Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\text{Cos}[x]+\text{Sin}[x]

I rather would like to have the following:

\cos(x)+\sin(x)

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?

share|improve this question

migrated from stackoverflow.com Jun 24 '12 at 16:50

This question came from our site for professional and enthusiast programmers.

    
Mods -- this might be a better question for the Mathematica.SE. See related TeX questions –  Eli Lansey Jun 24 '12 at 23:06

2 Answers 2

up vote 18 down vote accepted

Use TeXForm[].

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

Out[1]//TeXForm=
         \sin (x)+\cos (x)
share|improve this answer
    
Okay, that solves the problem directly :-) –  queueoverflow Jun 24 '12 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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