Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

The behavior you observe is due to the formatting rules associated with Times. Please start by reading my answer here: Returning an unevaluated expression with values substituted inReturning an unevaluated expression with values substituted in. We can apply a similar technique here though the result is not quite as desired if we merely block Times during Box creation. We get:

$\left(1*\frac{1}{2}\right)*\left(3*\frac{1}{4}\right)$

This form is due to the internal format of 1/2 and 3/4:

Hold[1/2, 3/4] // FullForm
Hold[Times[1, Power[2, -1]], Times[3, Power[4, -1]]]

One way to handle this is to post-process the Box form yield the format we desire:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := 
 Block[{Times}, MakeBoxes[HoldForm[args], fmt]] /. 
  RowBox[{"(", RowBox[{n_, "*", FractionBox["1", d_]}], ")"}] :> FractionBox[n, d]

Now using hf in place of HoldForm:

hf[1/2*3/4] // TeXForm
\frac{1}{2}*\frac{3}{4}

Formatted:

$\frac{1}{2}*\frac{3}{4}$

The behavior you observe is due to the formatting rules associated with Times. Please start by reading my answer here: Returning an unevaluated expression with values substituted in. We can apply a similar technique here though the result is not quite as desired if we merely block Times during Box creation. We get:

$\left(1*\frac{1}{2}\right)*\left(3*\frac{1}{4}\right)$

This form is due to the internal format of 1/2 and 3/4:

Hold[1/2, 3/4] // FullForm
Hold[Times[1, Power[2, -1]], Times[3, Power[4, -1]]]

One way to handle this is to post-process the Box form yield the format we desire:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := 
 Block[{Times}, MakeBoxes[HoldForm[args], fmt]] /. 
  RowBox[{"(", RowBox[{n_, "*", FractionBox["1", d_]}], ")"}] :> FractionBox[n, d]

Now using hf in place of HoldForm:

hf[1/2*3/4] // TeXForm
\frac{1}{2}*\frac{3}{4}

Formatted:

$\frac{1}{2}*\frac{3}{4}$

The behavior you observe is due to the formatting rules associated with Times. Please start by reading my answer here: Returning an unevaluated expression with values substituted in. We can apply a similar technique here though the result is not quite as desired if we merely block Times during Box creation. We get:

$\left(1*\frac{1}{2}\right)*\left(3*\frac{1}{4}\right)$

This form is due to the internal format of 1/2 and 3/4:

Hold[1/2, 3/4] // FullForm
Hold[Times[1, Power[2, -1]], Times[3, Power[4, -1]]]

One way to handle this is to post-process the Box form yield the format we desire:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := 
 Block[{Times}, MakeBoxes[HoldForm[args], fmt]] /. 
  RowBox[{"(", RowBox[{n_, "*", FractionBox["1", d_]}], ")"}] :> FractionBox[n, d]

Now using hf in place of HoldForm:

hf[1/2*3/4] // TeXForm
\frac{1}{2}*\frac{3}{4}

Formatted:

$\frac{1}{2}*\frac{3}{4}$

added 230 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

The behavior you observe is due to the formatting rules associated with Times. Please start by reading my answer here: Returning an unevaluated expression with values substituted in. We can apply a similar technique here though the result is not quite as desired if we merely block Times during Box creation. We get:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := Block[{Times}, MakeBoxes[HoldForm[args], fmt]]

hf[1/2 * 3/4] // TeXForm

$\left(1*\frac{1}{2}\right)*\left(3*\frac{1}{4}\right)$

This form is due to the internal format of 1/2 and 3/4:

Hold[1/2, 3/4] // FullForm
Hold[Times[1, Power[2, -1]], Times[3, Power[4, -1]]]

I believeOne way to handle this can be handled as you wish with a newis to post-process the Box form yield the format we desire:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := 
 Block[{Times}, MakeBoxes[HoldForm[args], fmt]] /. 
  RowBox[{"(", RowBox[{n_, "*", FractionBox["1", d_]}], ")"}] :> FractionBox[n, d]

Now using MakeBoxeshf rule but it's Christmas and I've got other things to do.in place of HoldForm:-)

hf[1/2*3/4] // TeXForm
\frac{1}{2}*\frac{3}{4}

Formatted:

$\frac{1}{2}*\frac{3}{4}$

The behavior you observe is due to the formatting rules associated with Times. Please start by reading my answer here: Returning an unevaluated expression with values substituted in. We can apply a similar technique here though the result is not quite as desired:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := Block[{Times}, MakeBoxes[HoldForm[args], fmt]]

hf[1/2 * 3/4] // TeXForm

$\left(1*\frac{1}{2}\right)*\left(3*\frac{1}{4}\right)$

This form is due to the internal format of 1/2 and 3/4:

Hold[1/2, 3/4] // FullForm
Hold[Times[1, Power[2, -1]], Times[3, Power[4, -1]]]

I believe this can be handled as you wish with a new MakeBoxes rule but it's Christmas and I've got other things to do. :-)

The behavior you observe is due to the formatting rules associated with Times. Please start by reading my answer here: Returning an unevaluated expression with values substituted in. We can apply a similar technique here though the result is not quite as desired if we merely block Times during Box creation. We get:

$\left(1*\frac{1}{2}\right)*\left(3*\frac{1}{4}\right)$

This form is due to the internal format of 1/2 and 3/4:

Hold[1/2, 3/4] // FullForm
Hold[Times[1, Power[2, -1]], Times[3, Power[4, -1]]]

One way to handle this is to post-process the Box form yield the format we desire:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := 
 Block[{Times}, MakeBoxes[HoldForm[args], fmt]] /. 
  RowBox[{"(", RowBox[{n_, "*", FractionBox["1", d_]}], ")"}] :> FractionBox[n, d]

Now using hf in place of HoldForm:

hf[1/2*3/4] // TeXForm
\frac{1}{2}*\frac{3}{4}

Formatted:

$\frac{1}{2}*\frac{3}{4}$

Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

The behavior you observe is due to the formatting rules associated with Times. Please start by reading my answer here: Returning an unevaluated expression with values substituted in. We can apply a similar technique here though the result is not quite as desired:

SetAttributes[hf, HoldAll]

MakeBoxes[hf[args__], fmt_] := Block[{Times}, MakeBoxes[HoldForm[args], fmt]]

hf[1/2 * 3/4] // TeXForm

$\left(1*\frac{1}{2}\right)*\left(3*\frac{1}{4}\right)$

This form is due to the internal format of 1/2 and 3/4:

Hold[1/2, 3/4] // FullForm
Hold[Times[1, Power[2, -1]], Times[3, Power[4, -1]]]

I believe this can be handled as you wish with a new MakeBoxes rule but it's Christmas and I've got other things to do. :-)