TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I understand from this question that using psfrag to replace tags in eps-files works well with pdfLaTeX. I also think I understand from this question that there was no working mechanism to accomplish the same thing using Xe(La)TeX?

I have tried nonetheless to retag an image with psfrag and the pstool workaround, and was slightly surprised by the error message Undefined control sequence which reproduceably rendered the first (and reduced to only) \psfrag command undefined. Working without pstool, the Undefined control sequence turned out to be the \includegraphics command. Is there any workaround known for replacing eps-image tags in or around XeTeX? If possible, I would like to have the appropriate font inserted no earlier than compilation, so I can compile the document to two different pdfs with two different fonts.

May I present the following as a minimal non-working examples? They contain the only changes to the code of a working document which caused the above cited error:

Version 1: No pstool:

[... some document text]
\begin{figure}\psfrag{pfeildreiunten}{Dioxan/HCl konz}
\caption{arbitrary caption}

Version 2: with pstool:

[... some document text]
\begin{figure}\psfragfig{imagefilename}{ %
\psfrag{pfeildreiunten}{Dioxan/HCl konz}}
\caption{arbitrary caption}

One more pinch of information that might be useful: The eps was generated with ChemDraw. The label as I entered it was in one text box in the ChemDraw-drawing. I hope that was generaly the right usage for \psfrag.

Edit (16/07/2012)
After doing even more search engine research, I am pretty positive that I won't get psfrag or a direct workaround to work directly in XeLaTeX. Now I'm asking myself which of the following ideas would be feasible or are maybe already implemented (and I haven't found them because I'm not looking hard enough):

Idea 1:
I have no clue how text parts are handled in (E)PS or PDF files. All I know is that one can mark and search for text in PDFs, so it must be encoded in a somehow plaintext way. Is it possible to convert the EPS files I have to PDF, include them, and still tell Xe(La)TeX to look for tag xyz in the file and replace it with tag abc? If so, which packages can do that?

I have found this question which renders the answer to my idea 1 'no'.

Idea 2:
Many of the workarounds I have found are made to work with pdfLaTeX. Even some suggest creating the properly replaced text with LaTeX, creating a PDF file out of the EPS and inserting that later. Problem: I'm using one of the benefits of XeTeX, i.e. a non-TeX-standard font (Liberation family). Is it 'easy' to get this to work with LaTeX, create the correct labels, convert PDF, insert?

Before this is suggested, the following is not an immediate option:
I cannot (atm) create the images using the correct font directly. ChemDraw, which I use for generating images, is running on my Windows-based desktop, while XeLaTeX is used on my Lubuntu-based laptop (where Liberation is installed). If all else fails, I will probably resort to Arial text in graphics and leave it unfitting to the font used in the text.

share|improve this question
Have you tried the auto-pst-pdf package? – clemens Jul 14 '12 at 10:43
@cgnieder Thanks for the suggestion. I have now also tried a few varieties using auto-pst-pdf and also the psfragx and pst-pdf packages. None have worked as in all produce the same error Undefined control sequence at the first \psfrag tag as the runthrough with pstool did. – Jan Jul 14 '12 at 18:34
I vaguely remember that psfrag doesn't work with XeLaTeX but I can't recall any references (or reasons)… – clemens Jul 16 '12 at 7:57
I assume by the fact that I have gained an upvoted question but no answers, that they must be along the lines 'it might be possible, it's probably not easy, and I don't know'. Since I don't have forever due to a handing-in deadline, I think I'll have to go with the worst solution for now (using a non-matching font), and thereby render the discussion philosophical. If a solution can be found by (say) Monday, and I feel it's worth a try, I'll still include it into my work, though. Sorry for any unconvenience caused and for any bad manners I'm showing. – Jan Jul 18 '12 at 3:08
up vote 2 down vote accepted

I have found an equally good working mechanism for my problem: If I leave the original eps files blank, I can position text across them anywhere using the overpic package. Their minimalistic documentation, to be found via CTAN or other sources, tells you everything you need to know. Positioning might be tricky and trial and error, but on the other hand, graph data from gnuplot always follows the same proportions when exported via set term postscript eps (and a few other options), so I can recycle optimised coordinates.

The biggest advantage is the ability to use tags, so now my compounds are properly automatically labelled all through my schemes with the chemcompounds package.

share|improve this answer

As detailed in your answer, the overpic package is a solution but I do not think it is mandatory. What you can do is to use the picture environment together with the \put command offered by the graphicx (as far as I remember) package. An example is given below. The pic pdf image has no text. The latter is added using the \put command. The commented portion (which is a grid) is initially uncommented to help finding the coordinates in the \put command. I think it is somehow similar to the overpic package and to what is possible within Inkscape when you export your figures as pdf+tex. It is quite tedious but you get used to it I guess.

% \linethickness{0.05mm}
% \multiput(0,0)(1,0){61}{\line(0,1){45}}
% \multiput(0,0)(0,1){41}{\line(1,0){55}}
% \linethickness{0.15mm}
% \multiput(0,0)(5,0){12}{\line(0,1){45}}
% \multiput(0,0)(0,5){9}{\line(1,0){55}}
% \linethickness{0.5mm}
% \multiput(0,0)(10,0){7}{\line(0,1){45}}
% \multiput(0,0)(0,10){5}{\line(1,0){55}}

You first have to make sure that you are happy with the size of your image since scaling up or down the entire thing (image+tags) may be a bit tricky (you can achieve this through the \unitlengh length though).

The other option is to use the Tikz or pstricks packages when possible.

share|improve this answer
Thanks. Overpic has the grid option integrated, though, so instead of either copypasting or remembering and retyping the whole grid formula stuff, all you do is type \begin{overpic}[grid,tics=10]{filename}. Which seems shorter and easier to me ;) – Jan Jul 26 '12 at 10:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.