# Converting Mathematica to $\LaTeX$

Is there a Mathematica-to-$\LaTeX$ converter, so that I can place Mathematica code, including things like A // MatrixForm, just as they are in the console straight into a $\LaTeX$ document?

• Check out TexForm in the documentation. May 29, 2013 at 22:37
• Also there is File > Save As > TeX May 29, 2013 at 22:56

TeXForm is indeed your friend. It even gives you nicely formatted code:

Table[RandomInteger[10], {3}, {4}] // TeXForm


gives

(*
\left(
\begin{array}{cccc}
9 & 5 & 10 & 9 \\
6 & 10 & 3 & 9 \\
9 & 5 & 9 & 7 \\
\end{array}
\right)
*)

• $\overset{\infty}{\smile}$ Ohhooooo... Thank you! May 30, 2013 at 0:08
• It doesn't work for me for {{-3, -6, -9}, {0, -3, -6}, {3, 0, -3}, {6, 3, 0}, {9, 6, 3}, {13, 10, 7}} // TeXForm May 3, 2017 at 14:16
• For me, in Mathematica 10.0, that produces the expected LaTeX output. Jun 5, 2017 at 18:45
• @SEngstrom how to install this in Ubuntu? Nov 5, 2017 at 17:10

This works great for transferring expressions in Traditional Form.

Select an expression, Right-Click, Copy As, LaTeX. Paste it where you want.

You can even highlight part of a traditional form output and grab the LaTex. This also works for MathML in Mathematica 8.

Too long for a comment. There are still problems with TeXForm, though. As much as I love it as I am writing a book on continued fractions, TeXForm has at least two problems:
1. For fractions it just uses \frac, and it doesn't know that for continued fractions \frac should be \cfrac. a/(a+a/(a+a/(a+a/(a+a/b))))//TeXForm produces output that is too squeezed. You still have to manually replace all \frac with \cfrac. TeXForm has no "continued fraction detector", it just treats the sub-set of continued fractions as fractions.
2. Due to the dependence on TraditionalForm there can undesirable re-sorting happening under the hood. a/(a+a/(a+a/(a+a/(a+a/b))))//TeXForm now displays the fractions on the left followed by the partial denominators. This is mathematically not wrong, but proper continued fraction notation has the partial denominators first, followed by the fractions. And unfortunately TeXForm has no options, helpful would be an option that allows the user to turn off the auto-sorting happening in TraditionalForm. Compare:
a/b+a

WRI apparently does not consider this a problem, for example the last example in the helpbrowser for TraditionalForm is Nest[Sqrt[1 + 1/#] &, x, 10] // TraditionalForm and look how that differs from the original Nest[Sqrt[1 + 1/#] &, x, 10]