I often want to copy formulas from Mathematica into a LaTeX document. Mathematica has a “copy as LaTeX” function, but it gives me not really the results that I want:


I rather would like to have the following:


I tried to use regular expressions in Python, which kind of work, but I cannot match matching brackets or parenteses. That would be very handy, since there could be anything in the cosine.

What would be a doable way to convert this?


2 Answers 2


Use TeXForm[].

In[1] := TeXForm[Cos[x] + Sin[x]]

         \sin (x)+\cos (x)
  • Okay, that solves the problem directly :-) Jun 24, 2012 at 12:24

And if you need to prevent evaluation of the expression you are trying to obtain the Latex form for, make sure to wrap the expression with HoldForm, as an example

enter image description here

otherwise you will obtain the TeXForm of the result of the integration:

enter image description here

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.