4

I created an image in Mathematica with some labels that, for some reason, refuse to be substituted when using PSFrag.

Specifically, the Mathematica code

image = Plot[Sin[x], {x, 0, 2 π}, PlotLabel-> "label"]
Export[NotebookDirectory<>"image.eps",image]

will create the image

enter image description here

The following PSFrag code should, in principle, substitute the label label with a nicely formatted $\sin(x)$:

\documentclass{article}
\usepackage{graphicx}
\usepackage{psfrag}

\begin{document}

  \psfrag{label}{$\sin(x)$}
  \includegraphics[width=\textwidth]{image.eps}

\end{document}

Indeed, a very similar version will work on the example.eps image provided by the PSFrag package in its documentation. However, the label is not replaced by my dvips driver. What is going wrong?

6
  • this looks kind of interesting, but for truly beautiful graphics you might look at pgfplots or PSTricks
    – cmhughes
    Mar 5, 2014 at 21:19
  • @cmhughes Those are nice, but they cannot do the heavy numerical integrations required by my thesis work. Every tool has its place.
    – E.P.
    Mar 5, 2014 at 21:22
  • but you can still export the heavy numerical integration results to a text file that you can then read with pgfplots or pstricks.
    – pluton
    Mar 6, 2014 at 2:55
  • Following your example directly within Mathematica 8.0, I receive as output the entire label (label).
    – Werner
    Mar 6, 2014 at 5:04
  • @Werner I'm running Mathematica 9.0.1 over Ubuntu 12.04. I'm not sure at all what different versions or OSs will do.
    – E.P.
    Mar 6, 2014 at 10:26

2 Answers 2

5

This turns out to be the fault of Mathematica's export protocol to EPS. If you inspect such a file directly in a text editor, the code corresponding to the label has been split up into single letters:

(l) N
P
p
3 10.5 m
(a) N
P
p
7.797 10.5 m
(b) N
P
p
13.203 10.5 m
(e) N
P
p
18 10.5 m
(l) N

That is, the string (label), which is what PSFrag hunts for, has been split into the five different single-character strings (l), (a), (b), (e) and (l).

To fix this, simply change the quoted code above with the proper (label), or change your labels to single characters.

3

You may also like to try MathPSFrag, which I've had lots of success with in the past.

It automatically creates (customisable) psfrag labels for every string in the image.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .