I'm facing a strange behavior of HoldForm
.
I need to display 1/2*3/4
in LaTeX like this : $$ \frac{1}{2} \times \frac{3}{4} $$
So I use Mathematica : 1/2* 3/4 // HoldForm // TeXForm
BUT I get $$ \frac{3}{2\ 4} $$
First the writing 2 space 4
is ambigous and second it does not hold form at all :(
Can you help me ? Thank you ! (happy Holidays)
EDIT : I would need an automatic transformation of any input to correct TeX or an automatic correction of any output to correct TeX.
Answer
Use HoldForm
applied to each fraction to keep the fractions from combining.
HoldForm[1/2] HoldForm[3/4]
to produce $$ \frac{1}{2} \frac{3}{4} $$
or
HoldForm[(1/2) (3/4)]
to produce $$ \frac{3}{2 \times 4} $$
Using TeXForm
produces the desired LaTex code.
(HoldForm[1/2] HoldForm[3/4]) // TeXForm
(* \frac{1}{2} \frac{3}{4} *)
Addendum
Simpler is
Infix[f[1/2, 3/4], "\[Times]"] // TeXForm
(* \frac{1}{2}\times \frac{3}{4} *)
which also provides the times sign. $$\frac{1}{2}\times \frac{3}{4}$$
Second Addendum
z1 z2 /. Times -> Cross /. {z1 -> 1/2, z2 -> 3/4} // TeXForm
also produces the desired output. (This is based on the third Answer to 39061.)
Comments
Post a Comment