4

I have a PDF file converted to EPS using Acrobat 11. While I've successfully used psfrag in the same LaTeX document to replace text (replace font, basically) in EPS files generated by Matlab R2013a, I can't get the same done in the EPS generated by Acrobat. What could be the reason? The text that I'm trying to replace is single word, and I can see it in the EPS file when opened in Notepad. Any hints and suggestions will be highly appreciated.

  • Is the word as a single string in the EPS surrendered by brackets as (hello) the usual reason fro psfrag failing is that the word has been typeset using ligatures or kerns so the full word does not appear as plain text in the internal EPS source. – David Carlisle Jan 23 '16 at 15:52
  • @David: Yes exactly. So what's the workaround? – Mohammad Imran Jan 23 '16 at 16:37
  • @MohammadImran There is no workaround. As long as the EPS file does not contain the string literally, there is nothing that can be done. My general recommendation is not to rely on psfrag and generate all figures using LaTeX itself, so that you have a full control on the result. – yo' Jan 23 '16 at 16:59
  • @Yo: You mean the literal string that I see in the EPS is not really there? I see these two lines in the EPS when opened in Notepad:(Classifiers) [9.36057 3.95929 6.24078 5.51782 5.51782 3.95929 4.68082 3.95929 6.12003 4.68085 0 ]xsh – Mohammad Imran Jan 23 '16 at 17:04
  • If the literal string is in the EPS file, then psfrag should work of course. I don't know why it does not. – yo' Jan 23 '16 at 19:12
4

In comments you added the relevant PostScript code:

(Classifiers)
[9.36057 3.95929 6.24078 5.51782 5.51782 3.95929 4.68082 3.95929 6.12003 4.68085 0 ]
xsh

xsh will be a defined alias in the file header for xshow the postscript command for letterspaced text, with the spacing being given by the numbers in the square brackets. xshow isn't supported by psfrag (I can't see why not, I think we just missed it at the time).

So you should be able to edit that command just to say

(Classifiers) 
show

and then psfrag will see it.

The following example includes an EPS file using each of these forms, and then includes it again after specifying a replacement for Classifiers note how just the non-letter spaced version is replaced.

enter image description here

\begin{filecontents}{\jobname.eps}
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 295 85 365

/Times-Roman findfont 10 scalefont setfont


10 350 moveto
(Classifiers) [9.36057 3.95929 6.24078 5.51782 5.51782 3.95929 4.68082 3.95929 6.12003 4.68085 0 ] xshow

10 300 moveto
(Classifiers) show

showpage
\end{filecontents}
\documentclass{article}

\usepackage{psfrag}

\begin{document}


1: \fbox{\includegraphics{\jobname.eps}}

\psfrag{Classifiers}{\rotatebox{5}{\textbf{C}\textit{lass}\textsf{ifiers}}}%
2: \fbox{\includegraphics{\jobname.eps}}

\end{document}
  • Thank you very much, but somehow I'm not able to use the edited EPS files in my document. I am in Windows environment and I edit the EPS in Notepad. The generated PDF document just stops short of the page where I am inserting the edited FPS. Could it have something to do with mismatched line endings resulting from use of Notepad? – Mohammad Imran Jan 25 '16 at 7:56
  • @MohammadImran line endings should should not make a difference, postscript considers all any combination of \r and \n as a line end. Note of it doesn't work for you you do not have to accept the answer! (leaving it not accepted makes it more likely that some provides a different answer). You could also email me the EPS file if you wish (if you google my name you'll see my email address) – David Carlisle Jan 25 '16 at 9:18
  • Thumbs up @David! Got it finally working using your suggested solution. And yes, it was the line ending issue, I got a confirmation from (forums.adobe.com/thread/674536?start=0&tstart=0). I edited the file in Microsoft Visual Studio 2010 editor (yes!) and it apparently didn't mess up the line endings. I really appreciate your help. – Mohammad Imran Jan 25 '16 at 9:25
  • @MohammadImran that's odd, but glad you got it working:-) – David Carlisle Jan 25 '16 at 9:27
  • 1
    @Ondrian if it's going to be useful I suppose we should update psfrag to support xshow, as I said originally it can't be hard (or at least it wouldn't have been hard 20 years ago when i could remember what it was doing:-) – David Carlisle Mar 31 '18 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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