My roommate knows Mathematica. He draw 3-d graph for each term of (a+b)^3 = a^3 + 3a^2b + 3ab^2 + b^3. He doesn't know LaTeX. I want to write his thesis document in LaTeX. So, If there is a tool that converts Mathematica code into LaTeX, that would be easier for me than write the same things in LaTeX from scratch.


You can copy-and-paste LaTeX directly from a Mathematica notebook:

enter image description here

It is assumed the content is math-related, so non-math functions are set using \text (requires amsmath).

  • 1
    +1. You may also want to mention the possibility of using either \textsf or \texttt instead of just \text for the string Plot3D. That would make it clearer, visually speaking, what's Mathematica code. – Mico Nov 6 '17 at 6:10

What do you mean by "Mathematica code"? Can you give an example of the desired conversion?

Apart from the convenient copy-paste method described by @Werner, there's TeXForm, which converts a Mathematica expression into math-mode LaTeX.

In[]:= TeXForm[Sin[x]^2]
\sin ^2(x)

If you want to convert a notebook to LaTeX, use File -> Save As... -> LaTeX Document.

In the past, I have been asked by people who did not know LaTeX if it is a good workflow to write your document as a Mathematica notebook, then simply save as LaTeX and compile it to PDF (as a means of getting better typesetting). I do not think this is a good idea. The LaTeX produced by Mathematica often has multiple issues. The LaTeX knowledge needed to correct these problems is already sufficient to write the LaTeX from scratch, so why not just do that?

Furthermore, when writing formulas in LaTeX, we specify what they should look like. When writing formulas in Mathematica, we specify what they mean, but the ultimately it is up to the system to format them in a certain way. This means that LaTeX auto-generated from Mathematica expressions will often benefit from additional manual editing.

To sum up:

Tell your roommate to take an hour to learn the basics of LaTeX. If the desired output is LaTeX, starting with a Mathematica notebook does not usually provide any benefits. I think that those LaTeX features that Mathematica can handle can really be learned in an hour or so (bold, italic, headings, equations).

However, if your goal is to convert an already written Mathematica document to LaTeX, and continue editing in LaTeX only, then go ahead and use Save As ... -> LaTeX Document.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.