# HoldForm: Display exactly as entered?

Sometimes, Mathematica's internal representation of expressions can give somewhat surprising results. Specifically, I noticed this when I tried to preserve products of fractions for display.

E.g. the following example as in "HoldForm does not Hold Form for fractions sometimes": i.e. it isn't easily possible to preserve the output fractions as they are written. This is actually surprising though, because Mathematica internally preserves the "product of two fractions" form:

In:=  HoldForm[1/x 1/y]  // InputForm
Out=  HoldForm[(1/x)*(1/y)]

In:=  HoldForm[1/x 1/y]  // FullForm
Out=  HoldForm[Times[Times[1,Power[x,-1]],Times[1,Power[y,-1]]]]


Is there some way to get Mathematica to display such forms as actual product of fractions in any of the formatted output forms, without manually adding holdform constructs?

• As to the final question, why not just convert input cell to the output once you are done with the input that should not be modified anyway? – Kuba Nov 15 '18 at 11:33
• Strongly related: (1), (2). – Alexey Popkov Nov 15 '18 at 11:35

MakeBoxes[Times[a_, b_], StandardForm] := RowBox[{MakeBoxes@a, MakeBoxes@b}]
1/x 1/y 1/z • Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output. – Kuba Nov 15 '18 at 11:17
• @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? ) – xzczd Nov 15 '18 at 11:28
• Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation. – kdb Nov 15 '18 at 15:06
• @kdb Yeah, if $1/x$ and $\frac{1}{x}$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong. – xzczd Nov 15 '18 at 15:37

IMO, the only way to be sure is to interfere as soon as possible:

\$PreRead = Function[boxes
,  boxes /.
RowBox[{"RawInput", "[", hf_, "]"}] :>
RowBox[{"RawBoxes", "[", ToBoxes[hf], "]"}]
]; Another possibility is to use InString:

1/x 1/y
ToExpression[InString[-1], StandardForm, RawBoxes] 