2
$\begingroup$

Context

I would like to use the Mathematica front end to pre-process expressions before exporting them to LateX, for the sake of readability.

Example

Say I have this expression

 (16*((-3 + r^2)*BesselI[0, r^2/8]^2 - ((-48 + 16*r^2 + r^4)*BesselI[0, r^2/8]* BesselI[1, r^2/8])/r^2 + 15*BesselI[1, r^2/8]^2)*Cos[2*\[Theta]])/(3*Sqrt[3]*E^(r^2/4)) 

which looks like this in Mathematica

Mathematica graphics

Once I edit it by hand within Mathematica, it might look like this: (notice that its more publishable in that form)

Mathematica graphics

(This is a great feature of the Front-End by the way!).

If I then select the expression and choose the export to latex menu, Mathematica exports the original (unedited) equation.

Question

How do I tell Mathematica to mind its own business and export to LaTeX the result of my edit, not its re-processing of it?

EDIT

Following the suggestion of @Nasser, I tried

Mathematica graphics

So it does not really preserve the original expression?

$\endgroup$
4
  • 1
    $\begingroup$ Try applying HoldForm[expr] when exporting. You might have to use HoldForm in more than one subpart of the expression if you want complete control. Hard to test it since your final expression is not posted in M code. $\endgroup$ Commented May 29, 2014 at 23:55
  • $\begingroup$ The expression you give as an example in markdown is not equivalent to the expression you show in the imbedded images. $\endgroup$ Commented May 30, 2014 at 0:21
  • $\begingroup$ @m_goldberg oops sorry. $\endgroup$ Commented May 30, 2014 at 2:39
  • $\begingroup$ @Nasser thanks. It does partially do the job, see my edit? $\endgroup$ Commented May 30, 2014 at 2:44

1 Answer 1

4
$\begingroup$

For the notebook interface, you can use HoldForm[] like this

expr2 = HoldForm[16 E^(-(r^2/4)) cos (2 \[Theta]) /(3 Sqrt[3])]; expr3 = HoldForm[((r^2 - 3) BesselI[0,r^2/8]^2 + 15 BesselI[1,r^2/8]^2 - ((r^4 + 16 r^2 - 48) BesselI[1,r^2/8] BesselI[0,r^2/8])/r^2)]; TraditionalForm[expr2 expr3] 

which gives

Mathematica graphics

Which is what you wanted. Now, for Latex export

TeXForm[expr2 expr3] 

which gives the tex expression. I copied this to my texlive box and run latex on it:

\documentclass[12pt,notitlepage]{article}% \begin{document} $\left(\left(r^2-3\right) I_0\left(\frac{r^2}{8}\right){}^2+15 I_1 \left(\frac{r^2}{8}\right){}^2-\frac{\left(r^4+16 r^2-48\right) I_1\left(\frac{r^2}{8}\right) I_0\left(\frac{r^2}{8}\right)} {r^2}\right) \frac{16 e^{-\frac{r^2}{4}} \cos (2 \theta )}{3 \sqrt{3}}$ \end{document} 

and here is the pdf file result

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Thanks again: inspired by your answer, it seems Map[HoldForm, exp]//TeXForm does more or less the trick. $\endgroup$ Commented May 30, 2014 at 3:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.