Agustin Martin Domingo committed Dec 15, 2010 1 2 3 4 ``````====================================================================== Using psfrag with pdflatex ====================================================================== `````` Agustin Martin Domingo committed Feb 17, 2011 5 ``````German (not up to date) version: README.de `````` Agustin Martin Domingo committed Dec 15, 2010 6 7 8 9 10 11 12 13 14 `````` psfrag is a LaTeX package which allows to replace text elements in included EPS graphics by arbitrary LaTeX output. E.g. you can make fonts in your graphics match your document fonts or even include mathematical formulae in your graphics. For example: \psfrag{x}{\$x\$} \psfrag{y}{\$y = x^2\$} \includegraphics{diagram} `````` Agustin Martin Domingo committed Feb 17, 2011 15 `````` `````` Agustin Martin Domingo committed Dec 15, 2010 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 ``````When using latex (not pdflatex) the file diagram.eps will be included. The extension is appended automatically. While doing this, every occurrence of "x" in the diagram is replaced by "x" using math font and every "y" is replaced by the LaTeX formula "y = x^2". Partial strings are not replaced, only completely matching strings. Because psfrag uses Postscript for making the replacements, in principle you can't use psfrag with pdflatex which doesn't have any interfaces to postscript. The basic idea around the problem is the following: Produce a new EPS from your original EPS which already contains all those psfrag replacements. This new EPS graphic actually can be converted to PDF including all replacements. The resulting "encapsulated" PDF then can be used with pdflatex. To make such an EPS which already contains the replacements, it is necessary to create a separate LaTeX document for every EPS file you use. To simplify that task, I wrote the included fragmaster.pl perl script. This script needs: perl, latex, dvips and the common EPS to PDF converter script epstopdf. To use the script you have to create two files per graphic: * _fm.eps: the EPS file itself, `````` Agustin Martin Domingo committed Feb 17, 2011 44 `````` * _fm: a fragmaster control file. `````` Agustin Martin Domingo committed Dec 15, 2010 45 46 47 48 `````` From these files the psfragged graphics will be created: * .eps, `````` Agustin Martin Domingo committed Feb 17, 2011 49 `````` * .pdf `````` Agustin Martin Domingo committed Dec 15, 2010 50 51 52 53 54 55 56 57 `````` The control file is basically a LaTeX file (with optionally special comments) and can look like this: % Just an ordinary comment % % A special comment: % fmopt: width=6cm `````` Agustin Martin Domingo committed Feb 17, 2011 58 ``````% `````` Agustin Martin Domingo committed Dec 15, 2010 59 60 61 62 63 64 65 66 ``````% Another special comment: % head: % \usepackage{amsmath} % end head % psfrag commands: \psfrag{x}{\$x\$} \psfrag{y}{\$y = x^2\$} `````` Agustin Martin Domingo committed Feb 17, 2011 67 `````` `````` Agustin Martin Domingo committed Dec 15, 2010 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 `````` The special comment fmopt: will be evaluated such that the following text will by passed as optional argument to \includegraphics. This way you can e.g. adjust the relation between graphics size and font size using something like width=6cm. The special comment construct "head:"/"end head" causes the lines in between to be included in the preamble of the LaTeX temporary document after having the leading comment characters "%" stripped off. This way, you can include LaTeX packages. fragmaster.pl will scan the current directory for files which end in _fm and their _fm.eps counterparts. Looking at the modification dates, the script checks if the output files have to be remade and does so if necessary (a little like "make" would do it). In your LaTeX document you can include the produced graphics using \includegraphics{} `````` Agustin Martin Domingo committed Feb 17, 2011 87 `````` `````` Agustin Martin Domingo committed Dec 15, 2010 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 `````` conveniently omitting the file extension. latex will choose the EPS, pdflatex will choose the PDF. ====================================================================== Example ====================================================================== The following example files are included: * parabel_fm.gp gnuplot file to create the following EPS graphics, * parabel_fm.eps raw EPS without psfrag replacements, * parabel_fm fragmaster file with the psfrag commands, * parabel.eps the produced EPS graphics, * parabel.pdf the produced PDF graphics, * document.tex LaTeX example including the graphics, * document.pdf example PDF, * document.ps example PS, * parabel_fm.pdf PDF version of the raw EPS graphics (only necessary for the `````` Agustin Martin Domingo committed Feb 17, 2011 115 `````` example!). `````` Agustin Martin Domingo committed Dec 15, 2010 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 `````` ====================================================================== Problems and solutions ====================================================================== In case the EPS will be produced as landscape graphics, i.e. gv shows "Landscape" instead of "Portrait" in the menu bar, and the graphic will end up turned around 90° in your document, then it is likely that your original EPS is wider than it is tall. In this case some (more recent) versions of dvips make the "smart" assumption that your graphic is landscape, even though the graphic's proportions don't tell anything about the orientation of its contents... Anyway, you can make dvips behave nicer by specifying the following line in /usr/share/texmf/dvips/config/config.pdf (or a local equivalent inside /usr/local/share/texmf): @ custom 0pt 0pt `````` Agustin Martin Domingo committed Feb 17, 2011 136 `````` `````` Agustin Martin Domingo committed Dec 15, 2010 137 138 139 140 141 142 143 144 `````` In the likely case that you're wondering why, I'd recommend the dvipsk sources warmly to you... Have fun with the script! Feedback is very much appreciated. Tilman Vogel (fill in: dot at dot) `````` Agustin Martin Domingo committed Feb 17, 2011 145 146 147 148 149 150 151 152 153 154 155 156 157 ``````====================================================================== Bugs and more info ====================================================================== For further details, please see "fragmaster -m" in UNIX systems (needs perldoc) or fragmaster man page if available. If directly downloaded from CTAN or used the one included in a win32 TeX distribution, please see fragmaster.pdf if available. Both are derived from fragmaster.pl pod section, located at the end of the script. Look there if the other formats are not available. Send bug reports to: `````` Agustin Martin Domingo committed May 25, 2018 158 `````` Agustin Martin (fill in: at dot) `````` Agustin Martin Domingo committed Feb 17, 2011 159 160 161 162 163 164 165 `````` In particular, the use of directory control files is a recent addition that still needs extensive checking. Your feedback is appreciated. Enjoy. `````` Agustin Martin Domingo committed Dec 15, 2010 166 167 168 169 170 171 `````` ====================================================================== Pointers to other solutions ====================================================================== * Pdfrack `````` Agustin Martin Domingo committed Feb 17, 2011 172 `````` * unpsfrag `````` Agustin Martin Domingo committed Dec 15, 2010 173 174 175 `````` Last modified: Thu Mar 19 20:52:45 CET 2009``````