Saving in $\LaTeX$

10

5

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

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

Out[1]= {{y -> 
   Function[{x}, 
    C[1] + 1/2 (-2 Sqrt[1 + 4 x] - 2 Log[1 - Sqrt[1 + 4 x]])]}, {y -> 
   Function[{x}, 
    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

\documentclass{article}
\usepackage{amsmath, amssymb, graphics, setspace}
\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{{}}
\newcounter{mathematicapage}
\begin{document}
    \begin{doublespace}
    \noindent\(\pmb{\text{DSolve}[y'[x]+x y'[x]{}^{\wedge}2==1,y,x]}\)
    \end{doublespace}
    \begin{doublespace}
    \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\}\)
    \end{doublespace}
    \end{document}

I would like to have $$ instead of

\begin{doublespace}
\noindent

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

Zbigniew

Posted 2012-03-20T06:06:48.587

Reputation: 381

Your link, unfortunately, appears to have died :-( – Greenonline – 2015-02-18T11:40:27.833

Cross posted here and here

– Szabolcs – 2012-03-20T06:30:19.197

1Is 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? – murray – 2012-03-20T18:49:13.490

Answers

8

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]];
        TeXForm[f[x]]

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

Vitaliy Kaurov

Posted 2012-03-20T06:06:48.587

Reputation: 66 672

4

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.

\begin{dmath}
\scriptstyle
\input{formula1.tex}
\end{dmath}`

macieksk

Posted 2012-03-20T06:06:48.587

Reputation: 141

1Probably 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'. – murray – 2015-05-26T22:52:27.993