# LaTeX and Mathematica plot with same font/style

I know there are a couple of questions with answers to this but none of them seems to work for me so I ask here. Some basic facts:

I have 1. Mac OSX 2. Very limited knowledge in Terminal (so things like --shell escape mean zero to me) 3. TeXShop 4. Mathematica 9

I would like to plot with Mathematica but use LaTeX on the plot with the same font as in the main TeX-file. I've heard some about PStools, PSfrag and so on but don't know how to install them or apply them. It would be nice with a simple line of code to do everything but with very little Terminal/command line.

EXAMPLE: As suggested in threads elsewhere I do this in Mathematica 9

plot = Plot[Sin[Exp[x]], {x, -Pi, Pi}, AxesLabel -> {"e", "s"}]
Export[NotebookDirectory[] <> "plot.eps", plot]


And then I make a new LaTeX document with the following code

\documentclass{standalone}
\usepackage{pstool}
\usepackage{graphicx}
\usepackage{epstopdf}
\begin{document}
\psfragfig{plot}{%
\psfrag{e}{$\epsilon$}
\psfrag{s}{$\Sigma$}}
\end{document}


The file plot.eps is the one I exported from Mathematica 9. The result is unfortunately not good because there's only "e" and "s" instead of $\epsilon$ and $\Sigma$ see figure!

• Can you export your data out of mathematica? – percusse Oct 13 '15 at 13:19
• @percusse Yes, the file plot.eps is from Mathematica – Your Majesty Oct 13 '15 at 13:20
• – Michael E2 Oct 13 '15 at 13:30
• No I mean the actual numbers to be plotted. Then you can plot it in pgfplots without any problems (and no terminal) – percusse Oct 13 '15 at 13:31
• Check out some examples tex.stackexchange.com/questions/84856/… ;) – percusse Oct 13 '15 at 13:38

Why don't you plot it directly with pgfplots?

\documentclass[border=1]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle,
xlabel=$\epsilon$,ylabel=$\Sigma$,
every axis y label/.style=
{at={(axis cs:0,1.3)},anchor=south},
every axis x label/.style={
at={(axis cs: 3.5,0)},anchor=west},
xmin=-3.5,xmax=3.5,ymin=-1.3,ymax=1.3]
\end{axis}
\end{tikzpicture}
\end{document}


• Awesome. Is there a simple way to a similar thing with plotting data from Mathematica 9? Suppose I plot a numerical integration in Mathematica 9 to which there is no analytical function, just data. How can one plot that with pgfplots? Thanks for your solution bro. – Your Majesty Oct 13 '15 at 14:20
• @ShutupandCalculate certainly there is. You have to provide a sample data though. There are lot of such examples in pgfplots manual. You can access the manual at www.texdoc.net or by running texdoc pgfplots in terminal of your computer. – user11232 Oct 13 '15 at 14:21
• So I should save something like a data = Table[] in M9? – Your Majesty Oct 13 '15 at 14:23
• @ShutupandCalculate Please consult the pgfplots manual for some examples of data formats. – user11232 Oct 13 '15 at 14:28

May I suggest that you use the same font in Mathematica and in your article? You would simply declare in the plot function of Mathematica that you want the labels to be in the same font and size of the article. Export the plot in pdf format and use LaTeX the command in your LaTeX file:

\begin{figure}
\ifpdf
\pdfximage width \columnwidth{plotname.pdf}
\pdfrefximage \pdflastximage
\else
\includegraphics{plotname.png}
\fi
\end{figure}

• With "font" I mean the exact way/font as in my LaTeX file. – Your Majesty Oct 13 '15 at 14:17
• @shutupandcalculate: have you tried? What difference do you see? If it is a size question, maybe you might want to increase (decrease) the font size in Mathematica. Mathematica is able to use all the available fonts on your system. – Xavier_B Oct 13 '15 at 14:27

I made a small package called MaTeX that makes it easy to generate figure labels for Mathematica graphics using LaTeX. A short introduction, including instructions on how to match up font styles, is available in this other StackExchange post: