mathematica 8.0 and psfrag
Asked Answered
T

3

11

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?

Telemann answered 17/6, 2011 at 11:10 Comment(0)
L
8

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

Lipfert answered 17/6, 2011 at 13:31 Comment(7)
What do you think on this question regarding incorrect encoding of non-ASCII characters in PostScript output from Mathematica? Is it possible to correct such output file (in EPS format) so that Cyrillic characters would be displayed correctly?Dactylic
@Alexey: I don't know. The nice thing about (E)PS is it's a plain text file, so you can see what's going on. That said, the EPS and PDF output works fine on my machine, although the font obtained using your cyrFix looks better.Lipfert
It looks like a very nice trick. But it doesn't seem to work with Mathematica 10 - the labels don't get replaced. Can you reproduce this behaviour?Burdette
@AlexeyBobrick I don't have Mma10 installed so I can't check to see if it works, sorry. Have you looked at the PS file to see what's happening?Lipfert
Yes, and I didn't find any fragments containing "({Q})", where, {Q} stands for a label letter.Burdette
@AlexeyBobrick I looked at the generated eps (using Wolfram Cloud) you can see that the fonts are now by default outlined and not represented as text. This is probably a bug and will hopefully be fixed. See this comment by SzabolcsLipfert
@Simon, still so in 10.0.1. The good thing about the new version export scheme, however, is that pdf export now works properly, embedding correct fonts etc.Burdette
P
4

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.

Procyon answered 17/6, 2011 at 14:5 Comment(0)
N
1

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.

Ninebark answered 17/6, 2011 at 12:13 Comment(3)
Thank you for your answer, rubenvb. The problem with Mathematica typesetting is that it is not publication quality, which is why I would prefer to use the much better looking LaTeX typesetting.Telemann
@pmt: Hmm, what do you mean by "not publication quality"? It's in vector format, and all the symbols are in their correct spots (I'd even dare say they just use LaTeX to typeset it internally).Ninebark
The main concern for publication is that the font styles will not match up in the LaTeX and Mathematica. Here's some discussion for psfrag and Octave, but the idea is the same.Lipfert

© 2022 - 2024 — McMap. All rights reserved.