Are there any tools that convert Mathematica code into LaTeX code?

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).


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]
Out[]//TeXForm=
\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.