Skip to main content
3 of 3
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/

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}$

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