Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mathematica 8.0 and psfrag

I recently updated from mathematica 7.0 to 8.0, and have now encountered problem with replacing my plot labels with LaTeX code using the psfrag package. Everything worked perfectly with the earlier version and the exact same plots, but now psfrag leaves all the labels unchanged. I use Kile on Ubuntu 11.04 for LaTeX editing.

For example, in Mathematica:

plot = Plot[x, {x, -0.1, 0.1}, 
            AxesLabel -> {eps, SUM}, BaseStyle -> {FontSize -> 10}]  
Export["plot.eps", plot]

and then in LaTeX:

\begin{figure}   
\psfrag{eps}{$\epsilon$}  
\psfrag{SUM}{$\Sigma$}  
\includegraphics{plot.eps}  
\end{figure}  

This should now replace labels with LaTeX typesetting, but nothing happens. Any suggestions how to solve this? Does anyone know if there is a difference in how Mathematica 8 encodes text in eps files compared to earlier versions?

like image 961
pmt Avatar asked Jun 17 '11 11:06

pmt


3 Answers

There's no difference in how the EPS is encoded. The problem is that the PS code that makes the text in the v7 output (note that Mma uses bind def to create shortcuts for a lot of PS code, see the top of the generated EPS files for details):

%%IncludeResource: font Times-Roman-MISO
%%IncludeFont: Times-Roman-MISO
10 /Times-Roman-MISO Msf
0 8 m
(SUM) N

has been replaced in v8 with

%%IncludeResource: font Times-Roman-MISO
%%IncludeFont: Times-Roman-MISO
10 /Times-Roman-MISO Msf
p
0.75 9 m
(S) N
P
p
6 9 m
(U) N
P
p
14.25 9 m
(M) N

This means that psfrag can not grab hold of the tags. I can't find how to fix this in the Mma export options.

At the moment, the only work-around I can think of (and I've tested that works) is to use single letter tags for the axes labels, e.g.

plot = Plot[x, {x, -0.1, 0.1}, AxesLabel -> {"e", "s"}, 
  BaseStyle -> {FontSize -> 10}]
Export["plot8.eps", plot]

\begin{figure}[h]
\psfrag{e}{$\epsilon$}
\psfrag{s}{$\Sigma$}
\includegraphics{plot8.eps}
\end{figure}

Note:

The reasons for maybe wanting to use psfrag are well stated in http://www.reimeika.ca/marco/prettyplots/

Now, those tags don’t look too good (and make little sense to boot). However the idea is to ultimately include the plot in a paper or report made with LaTeX, and so the real point to the tags is to use them as markers for the psfrag package which allows to replace text within EPS graphs. This way of labeling has three big advantages over hardcoding the tags into the figure. First is consistency, as the fonts will be the same as those in the article. Second is the fact that LaTeX's mathematical engine can be used to the fullest extent within the plot. Last but not least, it allows changing notation easily within the .tex file, as opposed to having to recreate the plot from scratch.


Addendum:

The package psfrag only works with EPS graphics and thus only with latex. If you want to use psfrag and pdflatex, then see the tex.SE question Using psfrag with pdflatex

like image 143
Simon Avatar answered Nov 06 '22 14:11

Simon


Tried both 7.0.1 and 8.0.1 and worked well for me. Hence, I cannot reproduce your error. (Maybe just a typo, case sensitivity etc.). Anyway, I agree that LateX modification is almost obligatory for publications. First I also used PSFrag, but very often I also don't like the positioning of the labels, especially if you place more complex expressions. Therefore I suggest an intermediate step via PSTricks. This looks something like this:

\documentclass[floatfig,isolatin,amsthm,amsmath,amsfont,amstext,12pt,fullpage,pslatex,amsref]{scrartcl}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{float}
\usepackage{epic}
\usepackage{eepic}
\usepackage{color}
\pagestyle{empty}
\usepackage{pstricks}

\begin{document}

\begin{pspicture}(0,0)(13.0,7.8)

    %\psgrid(0,0)(0,0)(13,7.8)
% need the grid only in the beginning for positioning

    \rput[c](10.7,3.8){\includegraphics{plot.eps}}

% put labels. 

    \rput[c]{90}(9.5,4){\Large{$\frac{E^2_\text{tot}}{V M_\mathrm{S}}$}}
    \rput[c]{0}(6,6.0){$x/h$}

% also to put extra lines, arrows, comments, etc. in LaTeX style, e.g.:

%   \psline[linecolor=green,linewidth=2pt,linestyle=dashed]{->}(3.5,3.05)(9.1,3.05)
\end{pspicture}
\end{document}

So there is some work you have to do by hand, but usually it is worth the time as the result really looks better, especially if it is for publication. However, keep in mind that in standard settings LaTeX uses the Computer Modern Font for formulae. This is not identical with e.g. Times New Roman, the typical choice for text. You can change this with the mathptmx package.

like image 24
mikuszefski Avatar answered Nov 06 '22 15:11

mikuszefski


You can write the "typeset" form in Mathematica directly, then it'll be already in the .eps file and you can just include the .eps as is.

plot = Plot[x, {x, -0.1, 0.1}, AxesLabel -> {"[\eps], [\Sigma]}, BaseStyle -> {FontSize -> 10}]

Just do [esc]+"eps"+[esc] and you'll get an epsilon, or insert it from the toolbox. Same for the sigma.

like image 21
rubenvb Avatar answered Nov 06 '22 15:11

rubenvb