When I save the following notebook code as $\LaTeX$,

In[1]:= DSolve[y'[x] + x y'[x]^2 == 1, y, x]

Out[1]= {{y -> 
    C[1] + 1/2 (-2 Sqrt[1 + 4 x] - 2 Log[1 - Sqrt[1 + 4 x]])]}, {y -> 
    C[1] + 1/2 (2 Sqrt[1 + 4 x] - 2 Log[1 + Sqrt[1 + 4 x]])]}}

I get this $\LaTeX$ code:

%% AMS-LaTeX Created by Wolfram Mathematica 8.0 : www.wolfram.com

\usepackage{amsmath, amssymb, graphics, setspace}
    \noindent\(\pmb{\text{DSolve}[y'[x]+x y'[x]{}^{\wedge}2==1,y,x]}\)
    \noindent\(\left\{\left\{y\to \text{Function}\left[\{x\},C[1]+\frac{1}{2} \left(-2              
    \sqrt{1+4 x}-2 \text{Log}\left[1-\sqrt{1+4 x}\right]\right)\right]\right\},\left\{y\to
    \text{Function}\left[\{x\},C[1]+\frac{1}{2} \left(2 \sqrt{1+4 x}-2
    \text{Log}\left[1+\sqrt{1+4 x}\right]\right)\right]\right\}\right\}\)

I would like to have $$ instead of


i.e., as an ordinary $\TeX$ file.

  • $\begingroup$ Cross posted here and here $\endgroup$
    – Szabolcs
    Commented Mar 20, 2012 at 6:30
  • 1
    $\begingroup$ Is it such a big deal to take the LaTeX code saved as shown and then just do a global search-and-replace in a text editor (or, if you prefer, define a Mathematica function to do the same thing upon the saved file? $\endgroup$
    – murray
    Commented Mar 20, 2012 at 18:49
  • $\begingroup$ Your link, unfortunately, appears to have died :-( $\endgroup$ Commented Feb 18, 2015 at 11:40

2 Answers 2


The way you do this - by saving the whole notebook with un-formatted In/Out cells - will get you a file with non-traditional working Mathematica notation. For example you will get square brackets for functions instead of round ones and capitalized functions names. If your goal is just to get a nicely formatted formula in $\TeX$ form, you could use this (for your 1st equation):

In[1]:= f = First[y /. DSolve[y'[x] + x y'[x]^2 == 1, y, x]];

c_1+\frac{1}{2} \left(-2 \sqrt{4 x+1}-2 \log \left(1-\sqrt{4 x+1}\right)\right)

If you paste the output in the body of your $\TeX$ file between $$ you'll get a nice formula:

enter image description here

If you would like to save the whole document you need to apply some formatting to it, depending on what you exactly need. For example turning an output cell into text cell will result in wrapping the formulas in \( ... \) , which is an equivalent of $...$ in $\LaTeX$.


What I find convenient: in Mathematica

probi = Exp[Sum[-τ((Subscript[x,i,k] - Subscript[x,j,k])^2)/2,
        {i,j}∈Subscript[Edge,k]]] HoldForm[Sqrt[τ/(2Pi)]]^Subscript[N,i]

Export["formula1.tex", (HoldForm[logP[X,τ]] == Log[probi]//PowerExpand)//TeXForm, "text"]

and in $\LaTeX$:

$$ \input{formula1.tex} $$

This results with the formula: $$\text{logP}(X,\tau )=\sum _{\{i,j\}\in \text{Edge}_k} \frac{1}{2} (-\tau ) \left(x_{i,k}-x_{j,k}\right){}^2+N_i \log \left(\sqrt{\frac{\tau }{2 \pi }}\right)$$

If the formula is large use breqn.

  • 1
    $\begingroup$ Probably best to include in LaTeX preamble \DeclareMathOperator{\logP}{logP} and \DeclareMathOperator{\Edge}{Edge}, then change \text{logP} to \logP and change \text{Edge} to `\Edge'. $\endgroup$
    – murray
    Commented May 26, 2015 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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