Manual

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 36

DownloadManual
Open PDF In BrowserView PDF
MathPSfrag 2.0 Manual

Johannes Groÿe
Institute of Physics, Jagellonian University,
Reymonta 4, 30-059 Cracow, Poland.

Abstract
This is the complete manual of

PSfrag,

Math-

3

a package for the creation of

AT X labels for Mathematica plots.
L
E
The manual is not meant as an intro-

2
3 JCosA2

duction but rather as a documentation
of all available commands. An overview

1

!!!! 2 13
xE N

article may be found in [1]; for a rst impression have a look at the presentation

MathPSfrag-2.0/latex/beamerexample-eurobachotex-2007/ direc-

in the

C

tory. In case you have taken a look at

0

Sin@xD
local maximum

-1
Π
€€€€€€
2

0

either already, you might want to skip
the introduction.

3Π
€€€€€€€€€€€
2

Π

2Π

Fig. 1a) Mathematica

3
2
p
√
3 3 cos2 (2 x)
1
0

sin(x)
local maximum

−1

0

π
2
Fig. 1b)

Email: grosse@th.if.uj.edu.pl
http://wwwth.mppmu.mpg.de/members/jgrosse/mathpsfrag

π

MathPSfrag

3π
2

2π

Contents
1 Introduction

3

2 Naming conventions/Typography

4

3 Setup

4

3.1

Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

3.2

Installation

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

3.3

Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

3.4

Why conguration is needed . . . . . . . . . . . . . . . . . . . . . . . . . .

6

4

PSfrag LATEX package

6

5

MathPSfrag interface commands

7

5.1

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

8

5.3

PSfragExport
PSfrag . . . .
UnPSfrag . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

5.4

Conguration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

5.5

In the manuscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

5.2

6 pdfLATEX
6.1
6.2
6.3
6.4
6.5

Standard

pst-pdf .
pst-pdf .
ps4pdf .
pdftricks

PSfrag

11
( PostScript only) . . . . . . . . . . . . . . . . . . . .

12

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

7 Command reference

17

8 General auxiliary functions

25

9

26

Mathematica 4.x5.0

10 Known Bugs and Limitations

27

11 Figure Source Code

28

11.1 Rotated Text

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

29

11.2 HoldForm plus CustomTicks . . . . . . . . . . . . . . . . . . . . . . . . . .

29

11.3 Three-dimensional Knot

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

30

11.4 Automatic vs. Manual Example . . . . . . . . . . . . . . . . . . . . . . . .

31

12 How to bug report

32

A Program Summary

33

Index

34

2

1

Introduction

Many programs producing

EPS graphics do not allow the inclusion of LATEX commands.

While there exist several solutions to work around these diculties, they all have various
drawbacks. (See [2] for a discussion of several methods and an alternative approach to
overcome these diculties.) In this article, we will focus on a particular existing solution,
the

PSfrag

AT X macros allowing to replace pieces of text
package [3], which provides L
E

(tags) in an

EPS le by an arbitrary LATEX construct.

However, for

PSfrag

to work, the application must write tags unaltered into the

EPS

le. For Mathematica [4, 5], this requirement amounts to using single words, strictly
consisting of alphanumeric characters only. As a consequence, the user has to work most
of the time with an inconveniently labeled graphic and is furthermore required to keep
track of the tags used in the substitution macros.
On the other hand, it is not always possible to use Mathematica's conventional
export function as it produces

EPS les requiring the inclusion of additional fonts into

the document. This means conguring the local TEX installation such that it nds the
fonts provided by Wolfram Inc. [6, 7, 8], a process often not being under the author's
control. A way out is to include the fonts into the

EPS le and set the font family to a

standard PostScript one.

Plot[..., TextStyle→{FontFamily→"Times"}]
Export[..., ConversionOptions→{"IncludeSpecialFonts"→True}]
However, automatic inclusion of Mathematica's special fonts, which irrespective of the
chosen

FontFamily are used for displaying important symbols like brackets, is only a last

resort. While the slight mismatch between a standard PostScript font's appearance,

AT X's standard font (Computer Modern)
(here Times Roman, cf. g. 1a), and that of L
E
may be acceptable in case of ordinary text labels, mathematical expressions like square

AT X's typesetting quality in this approach.
roots or fractions cannot compete with L
E
Font inclusion is also a feature thatlike the visually displeasing option to not use
special fonts at allhas become available only starting from Mathematica version 4.2.1.
Consequently, some authors simply restrict labeling of Mathematica plots to a bare
minimum.

MathPSfrag

[9] is a package that conveniently produces publication-quality labels in

EPS les generated by Mathematica.

MathPSfrag

automates many (often all) tedious

AT X package
details related to the use of the standard L
E

PSfrag,

while still allowing

manual ne tuning. As a demonstration of the degree of automation, compare g. 1a,
which has been generated by using the standard Mathematica command
g. 1b, generated by

MathPSfrag's

Export,

and

export instruction.

While the solution presented here, relies on the

PSfrag

package, it avoids many of

its shortcomings by providing a semi-automatic layer. In many cases it is sucient to

PSfragExport command.
MathPSfrag also allows the creation of stand-alone images that do not need any addiAT X and Ghostscript
tional preparations in the manuscript. This is achieved by calling L
E

simply use the new

AT X distribution on the
from within Mathematica requiring the user to have a full L
E
same machine where Mathematica resides.

3

2

Naming conventions/Typography

Thoughout this document, le names are denoted Unix-style (path/to/files) unless
they are system-specic.

Similarly, folders are called directories. The basis directory of the
is called

path\to\files.
MathPSfrag package

The corresponding Windows path would be

MathPSfrag-2.0/,

but the user may rename it as she pleases.

{TEXMF}/. The
/usr/share/texmf/, /usr/local/texmf/ or C:\

The basis directory of the TEX installation will generically be called
real location might be for example.

Clocaltexmf\texmf\

.

Command line quoting is performed with single quotes

'

where appropriate in the

Unix-context. For Windows these should always be double quotes

"

.

Line breaks that are not to be entered (but are rather a consequence of limited space
in the manuscript), are marked with

C

at the beginning of the next line. (As the reader

might have observed in one of the paragraphs above.) Should a hyphen

-

happen to be

the last character of the line, it nevertheless should be entered verbatim, when a

C

sign

is encountered.
Mandatory arguments are denoted

3

hmusthave i,

optional arguments

[maybe ].

Setup

3.1

Requirements

Strictly required
ˆ

Mathematica 4.0 or later

ˆ

AT X,
L
E

ˆ PSfrag

dvips, Ghostscript
AT X package [3]
L
E

Recommended
ˆ

Mathematica 5.1 or later

ˆ CustomTicks
ˆ pst-pdf

AT X package [11]
L
E

ˆ pdftricks
ˆ

[10]

AT X package [12]
L
E

beamer LATEX class [13]

ˆ pdfcrop
Note that the

[14] (which requires Perl)

ps4pdf

name

ps4pdf,

3.2

Installation

package is deprecated by

which may conict.

1. Check the requirements!
2. Unzip the
3. Read the

MathPSfrag

README.TEXT

package
le

4

pst-pdf.

Both provide a shell script of the

4. Download

CustomTicks [10] (strongly
MathPSfrag.

recommended) and put

CustomTicks.m

into

the main directory of

(Presumably this directory is named
5. Try to translate
the

psfrag

MathPSfrag-2.0.)

is-psfrag-installed.tex with LATEX.

If it does not work, install

AT X package.
L
E

6. Is Mathematica version 5.0 or earlier installed?
Install

ˆ MathPSfrag-2.0/latex/mma4tex/mma4tex.tex

and

ˆ MathPSfrag-2.0/latex/mma4tex/mma4tex.sty
into subdirectory

{TEXMF}/tex/latex/tex4mma

of your TEX distribution.

Need

more details? Read section 9.
7. Load MathPSfrag-Test.nb and execute line by line. Errors if any probably occur

MathPSfragConfigurationTest[] line. Make sure that LATEX, dvips
and Ghostscript are in the system's execution path  that's the clean solution 
or nd the exact location of the executables and provide them via the UnPSfrag
options marked by (* EDIT THIS *) in the test notebook. Need more details?
after the

Read section 5.4.
Congratulations.

3.3

Testing

AT X examples are set up in such a way that they translate even without the user
The L
E
having to generate her own set of graphics. However for testing, it is useful to

ensure

that only the user generated content is included, which requires some editing.
1. Check
2. Edit

xmpl-psfrag-orig.pdf

to get an impression of what we want to create.

MathPSfrag-2.0/latex/common/inc-preamble.tex:

Comment the line

\graphicspath{{../myfigs/}{../origfigs/}}
and uncomment the line

\graphicspath{{../myfigs/}}
This will ensure that only the
with

MathPSfrag.

user's graphics are loaded and not the ones delivered

If you have changed the default location of where the graphics

are exported to, you have to change above line accordingly.

AT X the example in
3. L
E
execute

Makefile.sh

MathPSfrag-2.0/latex/xmpl-psfrag/. Hint: You
Makefile.bat (for Windows).

4. Have a look at the output and compare with
look good?

might

(Linux or Mac) or

xmpl-psfrag-orig.pdf.

Does it

Minor dierences might be due to dierent Mathematica versions.

Consider to bug report in case of errors, but have a look at section 12 before.

5

tag
⊗

TE
X
⊗

1.0

0.8

-3

-2

0.8

0.6

0.6

0.6

0.4

0.4

0.4

0.2

0.2

1

2

3

-3

-2

b)

Figure 2: Action of

1.0

0.8

-1

a)

TEX

⊗

1.0

0.2

1

-1

2

3

-3

-2

c)

1

-1

2

3

d)

\psfrag{tag}[bc][bc]{\TeX}.

The rst coordinate pair

[bc] picks

the reference point (red crossed circle) in the TEX expression (g. a), the second one in

tag that is part of the original EPS le (g. b).

the

Positioning is achieved by overlaying

both boxes such that both reference points coincide (g. c). The nal result is shown in
g. d. Scales are exaggerated for better illustration.

3.4

Why conguration is needed

MathPSfrag

is divided into two layers: A part that produces

correspondingly tagged
and

Ghostscript

commands and

EPS les, and a part that merges these two les by feeding them

AT X. For the latter part,
into L
E

dvips

\psfrag

MathPSfrag needs to know the exact location of the LATEX,

executables. Under Unix-like systems or if you have a properly

congured system path under Windows (unlikely), chances are that you do not have to
congure

MathPSfrag

AT X distribution on
at all. If for some reason there, there is no L
E

your Mathematica system, you may want to use the
of the

UnPSfrag command.

unpsfrag bash-shellscript instead

It might also work in a Cygwin [15] environment, but hasn't

been tested yet.

4

PSfrag

LATEX package

AT X package
This is intended to be a short introduction to the L
E

PSfrag

explaining only

the essential features necessary to understand the corresponding Mathematica package's internals and to take advantage of its manual options if automatic placement does
not yield the desired result. The full documentation can be found in [3].

PSfrag

provides the macro

\psfrag{htag i}[[texposition ]][[psposition ]][[scale ]][[rot ]]{hLATEX i}
which replaces any occurrence of

htag i

in the output of an

process has been illustrated in g. 2. According to [3], all

\includegraphics

EPS le by hLATEX i.

This

\psfrag calls that precede an

(or equivalent) in the same or surrounding environments will aect

the output of the included graphics; i.e.,

\psfrag commands can be dened either locally,

to act on strictly one graphic, or globally, thus acting on all graphics in a document.

[texposition ]

and

[psposition ]

are optional arguments that allow to set (rst) the

vertical (top, bottom, Baseline, or center) and (second) the horizontal (left, right, center)
alignment of the replacement text by specifying the respective rst character of the
choices given in parentheses. The arguments refer to the position of the reference point

AT X construct is placed such that its reference
in the respective bounding boxes. The L
E
point is at the position of the corresponding PostScript (tag) box' reference point,
cf. g. 3 and 2.

6

—
30]
[
]
.5
][1
l
c
[
bl]
—[ (center line)

(center line)

—
[tc
][c
c]
[0
.7
5]
[4
5]
—

—[cl][tc]—

—[tl][tr][1][180]—

—[Bl][tl]—

(baseline)

—[tr][Bl]—

—[cc][cr]—

—[bc][Bc]—

—[Bc][Br]—

—[Br][bc][2]—

—[br][br]—

—[cr][bl]—

Figure 3: Illustration of the various optional arguments of the
from [3] with minor changes.

\psfrag command,

taken

AT X
The rst option determines the alignment of the L
E

AT X macro
description, while the second one is responsible for the point to which the L
E
is attached.

[scale ] and [rot ] permit scaling and rotation of the inserted box, where the rotation
(in degree) is relative to the slope of the PostScript bounding box such that a value of

AT X scaling
0 preserves the orientation, see g. 6. Scaling is best achieved by using L
E
commands, like

\Large,

instead of the

[scale ]

AT X fonts
option, since the standard L
E

consists of bitmaps rendered specically for the chosen size and do not rescale well.
Since

PSfrag

exchanges the labels of an

EPS

bounding box of the resulting image. Fortunately,

bb

and

trim,

EPS le.

image, these may protrude from the

\includegraphics

oers the options

which may be used to override or correct the obsoleted information in the

In particular, in conjunction with some of the

PDF production techniques de-

scribed in the section 6, correct(ed) bounding boxes can be important because protruding
material might be clipped.

5

MathPSfrag

interface commands

MathPSfrag's EPS generation: PSfrag
, which supersedes Mathematica's Export command, and PSfrag, which allows overriding of the defaults for particular expressions. In addition the UnPSfrag
AT X and Ghostscript to carry out the PSfrag replacecommand is provided which calls L
E

There are only three commands needed to control

CExport

ments and create an (ordinary)

\includegraphics
5.1

EPS and PDF image that can be included with the usual

command.

PSfragExport

PSfragExport[hbasename i, hgraphics i, [options ]] converts hgraphics i, the usual PSfragExport
Graphics construct returned by Mathematica commands like Plot, to an EPS le
AT X le containing \psfrag macros. PSfragExport returns the hbasename i
and a L
E
and the names of the generated les in a list, suitable for processing by UnPSfrag; i.e.
UnPSfrag[PSfragExport[...]].
The UnPSfrag command, if provided, will merge these two into a single EPS le and
will also produce a

[options ]

PDF version.

More about this in section 5.3.

can be any combination of the following options, listed with their paren-

thetic defaults.

7

ˆ TeXSuffix→"hstring i"

("-psfrag.tex")

ˆ EpsSuffix→"hstring i"

("-psfrag.eps")

ˆ RenumberTags→hboolean i

(False)

ˆ Format...→hpsfrag i

(PSfrag[#]&)

Any other options will be passed on to

Export

command, respectively.

AT X and
The respective le names of the L
E
to which the value of the options

TeXSuffix

or applied to the graphics using a

Show

EPS le are determined by hbasename i

and

EpsSuffix

is appended. Unless a base

name containing a path is given, the output is written to the current directory, which

SetDirectory.
RenumberTags→True will renumber

can be set using Mathematica's
The option

all tags and represent the number

as one of 52 (small and capital) Latin characters or a combination of letters when the
number is larger than 52.

This feature, which generates very short tags, sometimes

required to achieve a more precise positioning.
For completeness' sake, it shall be mentioned that there is a number of

Format...

options, which determine how the automatic processing of text generating graphics options is handled. The default is pretending the user having applied

PSfrag

without any

additional options to the text content of the respective option. For example the

Plot

PlotLabel→"foo" would be turned into PlotLabel→PSfrag["foo"] due to the
FormatPlotLabel option having the value PSfrag[#]&.
The Format... options provide a method for changing the default treatment of particular Plot options. Suppose one would want to display a dierent number of signicant
digits on the x- and y -axis. This could be achieved by using
option

FormatTicksX→(PSfrag[#,TeXCommand→MyDigitsX[#]]&)
FormatTicksY→(PSfrag[#,TeXCommand→MyDigitsY[#]]&)
with

MyDigitsX/Y suitable, user-dened functions that accept a number as argument and

return a string containing a well formatted number. However, the recommended method
of customizing axes labels is using the

CustomTicks

package [10]. A minimal example is

given in section 11.2.

5.2

PSfrag

PSfrag

Usually one will not use the

Format...

options for the purpose of manually controlling

the output, but wrap the

PSfrag[hexpr i, [options ]]
command directly around any Mathematica expression
graphic, such as the argument of a

Text

PlotLabel→...

graphics directive; e.g.,

p=Plot[...,PlotLabel→PSfrag["χ^2-test",...]];
PSfragExport["chisquare", p];

8

or

hexpr i appearing
AxesLabel→...

as text in a
option or a

PSfrag

processes the following options, whose defaults have been put in parentheses.

ˆ TeXCommand→"hstring i"

(Automatic)

ˆ PSfragTag→"hstring i"

(Automatic)

ˆ TeXPosition→"hyx i"

(Automatic)

ˆ PSPosition→"hyx i"

(CopyTeXPosition)

ˆ PSRotation→hnumber i

(0)

ˆ PSScaling→hnumber i

(1)

Actually,

PSfragExport's automatic mechanism simply wraps PSfrag around all Text

primitives using the default values above. However, manual wrapping has the advantage
of allowing dierent options to be applied to expressions where the automatic behavior
did not give satisfactory results.

TeXCommand→"hstring i"

uses

hstring i

AT X command to appear in the
as the L
E

nal EPS graphic as a replacement of the corresponding expression hexpr i. If set to
Automatic, the internal function GuessTeX is called, which is basically a wrapper around
TeXForm that adds $ signs around math expressions.1
The content of PSfragTag is a unique alphanumeric tag that is used as a placeholder
in the graphics. In most cases the user will not want to change the Automatic default,
which corresponds to generating a valid tag from a string representation of hexpr i.
The remaining options are in one-to-one correspondence with those of \psfrag ex-

AT X
plained in section 4, see there; i.e., they determine the alignment of the generated L
E

TeXPosition is to extract the alignment of the surroundText command is produced during
export.) The default value CopyTeXPosition of PSPosition does exactly what it says;
i.e., taking over the value of the TeXPosition option. The values of PSRotation and
PSScaling are relative to the Mathematica expressions, that is the default values will
labels. The default behavior of
ing

Text

command. (If there is none, it waits till the

preserve both orientation and size.

MathPSfrag uses the FullGraphics command to determine the alignment values for
TeXPosition and PSPosition. Unfortunately FullGraphics does not work for threedimensional graphics, such that PSfragExport falls back to PSfragManualExport, which
does not perform any alignment detection and can also be used for two-dimensional

PSfrag has to be applied
Text directive and text producing option like PlotLabel.
TeXPosition will have to be given by the user.

graphics if automatic processing is not desired. In these cases
by hand to the argument of any
Moreover at least the values of

5.3

UnPSfrag

With the commands described so far, standard

MathPSfrag

Mathematica. First, creation of pre-rendered

frag

PSfrag

EPS

pictures can be produced.

AT X run from within
provides two additional features that require a full L
E

EPS images, which do not require the PS-

package anymore. Such pre-rendered images will be called unpsfraged henceforth.

Second, conversion to

PDF

preview of the nal plot.

AT X or raster images providing a
images suitable for pdfL
E

For both features,

1

MathPSfrag

needs to know where to nd

To be more precise, GuessTeX has two options that allow the user to override or modify the code
generated by TeXForm. These options take care of adding the required $ signs and also take into account
part of the version dependence of TeXForm, cf. section 10
9

AT X,
the executables for L
E

dvips and Ghostscript.

Unless the binaries are in the system's

execution path (as will be the case for Unix-like operating systems), this requires the
user to set the location of the les explicitly. The notebook containing the code of all
example plots shown in this manual also contains a comprehensive step-by-step guide of
how to set up these paths permanently.

UnPSfrag

The syntax of

UnPSfrag

is

UnPSfrag[{hbasename i,hepsfile i,htexfile i},[options ]];
where

hbasename i

is used to create the names of output les by appending suitable

suces like  .pdf or  .eps.
the tagged

EPS

and

The other two mandatory parameters should point to

PSfrag-LATEX

les that are to be merged.

PSfragExport

returns

the three le names in exactly this format such that its output can be directly fed to

UnPSfrag.
UnPSfrag

has a number of additional options that control how images are created.

Again only the most important ones shall be given here, while a complete list is given in
the manual.
By default,

UnPSfrag

only produces an

EPS

and a

possible to generate other output formats by setting the

PDF

le, though it should be

UnPSfragOutputFormats option

accordingly.
Furthermore

UnPSfrag

shows a low resolution bitmap preview of the nal images.

While this is extremely useful for checking if

MathPSfrag has produced the desired results,

it will enlarge the notebook considerably, which can be inconvenient for email exchange.

PreviewDevice option to None will switch o this behavior.
AT X code, it might require
When using the PSfrag option TeXCommand to specify L
E
additional style les. These can be included by UnPSfrag when providing the appropriate
\usepackage command as a string via the TeXPreamble option.
IncludeGraphicsOptions is the most important option. The string it provides is
AT X le used to perform the
handed over to the \includegraphics command in the L
E
\psfrag replacements. The option can therefore be used to set the size of the rendered
graphics; e.g., by setting its value to "width=7cm". Note however that the nal bounding
Setting the

content instead of exactly matching the specied size. This
bounding box changing during PSfrag's replacement procedure.

box will correctly t the image
mismatch is due to the

When an exact size is required, it can be reapplied in the manuscript, though it is better
to adjust the size from within Mathematica, the reason for which is explained in the
next section.

5.4

Conguration

When no pre-rendered images are desired, conguration is not required. In order to use

UnPSfrag however MathPSfrag needs to know where to
dvips and Ghostscript. The respective paths may be set
SetOptions[UnPSfrag,
LaTeXExecutable→"hstring i",
DvipsExecutable→"hstring i",
GhostscriptExecutable→"hstring i"
];

10

AT X,
nd the executables for L
E
by invoking

where the default values are

"latex", "dvips",

and

pending on whether the system is Windows based.

MathPSfrag
path.

"gs"

or

"gswin32c",

the last de-

These values are chosen to make

run out of the box provided that the binaries are in the system's search

This will most likely be the case on Unix-like systems; whereas Windows users

might either have to adjust their path environment variable or use absolute le names in

2

the above options.
Additionally

MathPSfragConfigurationTest[]

frag is able to nd all components.

can be invoked to check if

MathPS-

Step-by-step instructions that guide the user through

the conguration are provided in the notebook

MathPSfrag-Test.nb,

which also gener-

ates all of the examples in section 11.

MathPSfrag evaluates the variable $PostMathPSfrag after being loaded, which allows
init.m le3 that contains the conguration settings. It can also be
used to make Mathematica nd MathPSfrag without explicit path; e.g.,
setting up a private

AppendTo[$Path, "C:\\my_path_to\\MathPSfrag"];
$PostMathPSfrag := SetOptions[UnPSfrag,...];
5.5

In the manuscript

UnPSfrag'ed images do not require any additional treatment or package beyond graphics
or graphicx. Since EPS and PDF versions are created anyway, it is recommended to not
provide any sux for the le name in the \includegraphics command, such that the
AT X and pdfLAT X. It is possible to issue the common
manuscript translates with both L
E
E

size options, but this will also change the labels, such that they will not have the xed TEX
sizes anymore. This can potentially reduce the fonts quality, in particular when TEX's
standard computer modern fonts are used, which are composed of bitmaps optimized for

UnPSfrag option DvipsOptions is by default set to "-Ppdf",
dvips replace bitmap fonts by outline fonts on most systems, thus reducing

a particular resolution. The
which makes

the problem to a mere mismatch between the label's size and that of the manuscript's
text.

In any case it is advisable to adjust the size from within Mathematica before

rendering by applying
It is also possible

IncludeGraphicsOptions
to follow a pure PSfrag

performed on the level of the manuscript.

to

UnPSfrag.

approach, where all replacements are

This is discussed in section 4.

Before, a

number of usage examples shall be given.

pdfLATEX

6

AT X documents, the author often not only has to provide the For publication of L
E
nal manuscript but also the sources to produce them subject to constraints set by the
publisher.

MathPSfrag essentially oers two levels of image production, a rather sophisticated  UnPSfrag approach, which aims at producing pre-rendered stand-alone images as has been described above, and a classical, PSfrag centric approach. In this
approach, MathPSfrag is used to produce a tagged EPS le plus a PSfrag translation
Therefore,

AT X run of the
le, which can convert the tags back into readable labels during the L
E
2
3

The backslash is an escape symbol and has to be doubled; e.g., "C:\\Programs\\GS\\gswin32c.exe".
This is a le that is automatically loaded upon start-up; see
's Help Browser.

Mathematica

11

manuscript. These two les are generated by

PSfragExport.

(Further use of

UnPSfrag

would join this pair into stand-alone graphics.)
The decision which approach to use has an impact on both the process of image
creation and on how to include the images and compile the manuscript. In particular,

PSfrag

the

centric approach is less convenient and not as compatible as the

approach, since it relies on PostScript.

UnPSfrag

However it has the advantage of producing

considerably smaller images of potentially better typesetting quality as the used fonts
are guaranteed to match the document's. Furthermore, the label's font size is xed in
this approach, which is of particular importance for the bitmapped Computer Modern,
though modern TEX distributions have outline fonts available which scale more gracefully.
Still visual consistency might suer from dierently scaled labels.
The following sections describe how to include

PSfrag

images into a manuscript and

PSfrag
MathPSfrag is accompanied by a set of example les each of which illustrates one of

some ways for circumventing the PostScript-only restriction of the standard
use.

the strategies outlined below.

6.1

Standard PSfrag (

The standard

PostScript only)

PSfrag way is to include the EPS and PSfrag le in a manner similar to the

following code.

\begin{psfrags}
\input{example-psfrag.tex}
\includegraphics{example-psfrag.eps}
\end{psfrags}
The {psfrags} starts an empty group provided by PSfrag, whose sole purpose is making
\psfrag denitions local to the following graphic.
The produced DVI le is then required to be converted to PostScript using dvips;
and

PDF can only be created by distilling from the PostScript version using for example

Acrobat or

Ghostscript (ps2pdf).

The disadvantage of the pure PostScript approach is that the advanced typesetting

AT X are not available.
features of pdfL
E
This restriction may be overcome by the either use of the
package.

6.2

4

ps4pdf, pst-pdf

or

pdftricks

pst-pdf

ps4pdf is deprecated by pst-pdf, which follows the same strategy of using LATEX to produce
a collective PDF container for images. pst-pdf is a bit more convenient as it does not
require (or allow) to mark PostScript related code. A drawback of this feature is that
the above mentioned quick x for a discrepancy between the two outputs of a combined

AT X/pdfLAT X version cannot be applied anymore since any invisible frame boxes would
L
E
E
not be included in the

PDF container le.

That means that the use of

pst-pdf

will restrict the manuscript to translations with

AT X at least in the sense that it is not possible to write a manuscript that will simulpdfL
E
AT X. A major advantage
taneously have perfect bounding boxes when translated with L
E
of

pst-pdf

4

is that it provides the additional package option

notightpage

I would like to thank Ross Moore for bringing these packages to my attention.
12

to support use

of

pdfcrop by providing
trim options.

extra space around the images without requiring the use of

individual

6.3

pst-pdf

pst-pdf extracts all images of a manuscript in an additional LATEX run with the help of
the preview package. These can then be turned into a PostScript le and distilled to
AT X run, PDF replacements for
a PDF that is called image container. During the pdfL
E
PostScript parts are read from the image container. Whenever content or order of the
images are changed in the manuscript, the image container must be regenerated.

pst-pdf. Unfortunately,
ps4pdf, which is still installed on many systems, has a similar
script sharing the same name, ps4pdf. It is important to ensure that the correct version
of the ps4pdf is used that refers to pst-pdf.
There is one additional catch due to the way \psfrag invalidates bounding boxes:
pst-pdf must be loaded with the notightpage option and the ps4pdf script must be
called with the crop option.
Assuming manuscript.tex to be the main document, either of the following instrucThe required steps are automated in a script accompanying

the predecessor package

tions produces the image container:

ps4pdf --crop manuscript.tex

or

latex manuscript.tex
dvips -Ppdf -o manuscript-crop.ps manuscript
ps2pdf -dAutoRotatePages=/None manuscript-crop.ps manuscript-crop.pdf
pdfcrop manuscript-crop.pdf manuscript-pics.pdf
Of course, a distiller dierent from

ps2pdf

may be used. Subsequently, the manuscript

AT X in the usual manner, which will be use the pre-generated
can be processed by pdfL
E
pictures stored in the

-pics.pdf

le.

The main advantage of this variant is that all images are collected in one single le,
which can be very convenient for distribution, since it is much smaller than individual

PDF versions of each image.

This observation suggests that the collective image le is

free of double copies of resources like fonts.
It is possible to arrange the preamble in an agnostic way, such that translation is

AT X and pdfLAT X. This requires the image container to be created with
possible with L
E
E

latex '\AtBeginDocument{\RequirePackage{pst-pdf}} \input{manuscript.tex}'.
pst-pdf during an ordinary LATEX run, but only for
A
pdfL TEX. One should still ensure that pst-pdf receives the notightpage option. Note
that the ps4pdf script already uses this line, so ps4pdf crop manuscript.tex will

Then it possible to simply not load

work as expected. The preamble should read:

\PassOptionsToPackage{notightpage}{pst-pdf}
\usepackage{ifpdf}
\ifpdf\usepackage{pst-pdf}\else\fi

13

6.4

ps4pdf

It is recommended to use the package
The predecessor of

pst-pdf

is

ps4pdf,

pst-pdf

instead.

which requires all PostScript related material

(including material in the preamble) to be wrapped in

\PSforPDF

instructions similarly

to

\PSforPDF{%
\begin{psfrags}
\input{example-psfrag.tex}
\includegraphics%
[width=8cm,trim=...]%
{example-psfrag.eps}
\end{psfrags}
}% end of PSforPDF
and to include a

\usepackageps4pdf

into the preamble.

The

trim

option will be dis-

cussed later.
Assuming the main document is
tions produces a

manuscript.tex

the following sequence of instruc-

PDF le containing all images (and only these) in PDF format.

latex manuscript.tex
dvips -Ppdf -o manuscript-pics.ps manuscript
ps2pdf manuscript-pics.ps manuscript-pics.pdf
Of course, a distiller dierent from

ps2pdf

may be used. Subsequently, the manuscript

AT X in the usual manner without a need to recreate the picture
can be processed by pdfL
E
AT X will use the pre-generated pictures stored in the -pics.pdf le
container. pdfL
E
provided it has (up to the sux) the same name as the main document. A change of the
order or of the content of the PostScript material in the manuscript requires repeating
above steps.
There is however the important catch, that material lying outside the bounding box of
the PostScript graphics will be clipped. Since
material in the

PSfrag eectively changes the graphical

EPS les, the bounding box will always be at least slightly, sometimes

dramatically, incorrect and has to be manually corrected; e.g., by using the
of

\includegraphics to provide some extra margin.
ps4pdf even allows to arrange the manuscript in

trim

option

such a way that naive translation

DVI or
PDF le, while the image container can be created by giving an additional switch:

AT X or pdfLAT X will produce the expected result, namely creation of a
with L
E
E

latex '\let\picsonly\relax\input{manuscript}'
This can be achieved by including in the preamble

\usepackage{ifpdf}
\ifx\picsonly\relax\usepackage{ps4pdf}\else%
\ifpdf\usepackage{ps4pdf}\else%
\usepackage[inactive]{ps4pdf}\fi\fi

14

\newcommand{\PSfraginclude}[2][]{
\mbox{\PSforPDF{\whitebox{%
\begin{psfrags}%
\input{#2}%
\includegraphics[#1]{#2}%
\end{psfrags}%
}}}%
}
...
\PSfraginclude[width=5cm]{example-psfrag}
Figure 4: A customized

\includegraphics

for

ps4pdf.

As an aside, the author observed a slight mismatch between the bounding boxes

AT X and pdfLAT X versions when following the additional switch strategy
in the L
E
E
outlined above.

Strange enough when investigating this phenomenon by surrounding

\includegraphics

the

command by a frame box, this mismatch did not show up any-

more. This suggests a possible workaround by surrounding the material with a white
i.e. invisibleframe box. For convenience the user might want to have a macro taking
care of such complications, cf. g. 4
The main advantage of this variant is that all images are collected in one single le,
which can be very convenient for distribution, since it is much smaller than individual

PDF versions of each image.

This observation suggests that the collective image le is

free of double copies of resources like fonts.
A disadvantage is the manual ne-tuning required to produce correct bounding boxes.

AT X the situation can be alleviated to some
When one is only interested in using pdfL
E
extent by setting the bounding box way too large using the

Cgraphics

such that no material is clipped. A program like

trim option of \include
pdfcrop can then be used

to automatically correct the bounding box for all images in the image container:

latex manuscript.tex
dvips -Ppdf -o manuscript-pre.ps manuscript.dvi
ps2pdf manuscript-pre.ps manuscript-pre.pdf
pdfcrop manuscript-pre.pdf manuscript-pics.pdf
6.5

pdftricks

pdftricks

diers from the packages discussed so far in that it produces individual

PDF

les for PostScript based images. Originally it was meant to be used in conjunction

pstricks package. pdftricks requires the the shell-escape capability (a.k.a.
\write18 capability) activated and the programs ps2eps and epstopdf to be installed
with the popular

and in the system's search path.
In that case a the manuscript can simply be translated by

pdflatex -shell-escape manuscript.tex

{pdfpic} environment. There is
because \psfrag denitions are already

provided that images are enclosed in an

{psfrags}

environment anymore,

15

no need for a
local.

preamble
\newbox\subfigbox
\makeatletter
\newenvironment{subfig}{%
\def\caption##1{%
\gdef\subcapsave{\relax##1}}%
\let\subcapsave\@empty
\setbox\subfigbox\hbox
\bgroup}
{\egroup
\subfigure[\subcapsave]{\box\subfigbox}}
\makeatother
document

\begin{subfigure}
\begin{pdfpic}
...
\end{pdfpic}
\end{subfigure}

Figure 5: How to include a

{pdfpic}

environment into a subgure.

\begin{pdfpic}
\input{example-psfrag.tex}
\includegraphics[width=...]{example-psfrag.eps}
\end{pdfpic}

{pdfpic} environment is a {verbatim}-like environment that writes its content to
manuscript-fig1.tex, though the number is incremented for each {pdfpic},
AT X, dvips, epstopdf sequence. Any additional packwhich in turn is processed by a L
E
A
ages required for this L TEX run can be included using the {psinputs} environment. In
The

a le; e.g.,

our case this will usually mean

\usepackage{pdftricks}
\begin{psinputs}
\usepackage{psfrag,amsmath,graphicx}
\end{psinputs}
and possibly

mma4tex,

see section 9.

A restriction arises from the
an argument to other macros.
the

subgure

{verbatim}

nature of

{pdfpic}:

it cannot be used as

This may be an issue when used in conjunction with

package, whose documentation recommends to set up a

\subfigure-like

environment as presented in g. 5.
When the

\write18 capability is not available, one may perform the same steps by
pst2pdf shell script that accompanies pdftricks. (The latter should

hand or using the

work for example in a CygWin environment [15].) These steps have are

16

latex example-fig1.tex
dvips -Ppdf -o example-fig1.ps example-fig1.dvi
ps2eps -l -f example-fig1.ps
epstopdf example-fig1.eps
and have to be repeated for each

*-fig?.tex le. Once the gures have been generated,
\NoProcess[1-100], where the maximum has to be

one may switch o processing with
suciently large.

7

Command reference

The following is a complete list of all public symbols provided by the
age.

MathPSfrag

pack-

The order is approximately alphabetic, though options are collected below the

corresponding function. For a truly alphabetic list, have a look at the index.

BoundingBoxFromRaster[hrastergraphics i,hextramargin i]
rectangle around the non empty region of rastergraphics.
by extramargin in all directions.
(see there) is not set to

returns the smallest

This rectangle is enlarged

This function is used when the

bbox.

BoundingBoxFrom

CRaster

BoundingBoxDevice

CreatePSfragRules[hexpr i] generates the TEX commands corresponding to any CreatePSfrag
PSfrag used in hexpr i. This is an auxiliary function for hPSfragExport i and may CRules
be directly used for debugging or educational purposes.

Graphics object whose labels contain PSfrag
CreatePSfragRules[FullGraphics[anyplot]].
a

1.

2.

You may want to apply it to

commands.

RenumberTags: Option for CreatePSfragRules
PSfragExport (see there).

The usual application is

that can also be passed through

PSfragPrologue: Option for CreatePSfragRules
PSfragExport (see there).

that can also be passed through

FetchGhostscriptDevices[htempfilename i] calls Ghostscript to nd out which of Fetch
$MathPSfragGlobal PredefGsDevices are supported by the partic- CGhostscript
CDevices
ular version of Ghostscript on the current system.
the devices listed in

Format...

HandleAutomaticPSfrag, that can Format
PSfragExport. This is an internal feature that is present to keep

A number of (internal) options for

also be passed to

the design exible and separate the general processing from the logic required for the
treatment of particular Plot options. When you want to override the default behavior
often it is easier to use PSfrag of PSfragTicks. All MathPSfrag Format* options can be

used to ne-tune the output of the current automatic handling of axes labels and the like.
Their respective default value is usually just PSfrag, which is wrapped around each

17

Text

element that is produced by
behavior of

PSfrag

is to call

Plot options like AxesLabel or Ticks. Since the default
GuessTeX, you obtain the TEX code that is generated by

this rather imperfect function.

You can include you own TEX generating function by

Format...→PSfrag[#,TeXCommand→mytexguesser[#]]&, where you obviously
would have to implement mytexguesser to convert an arbitrary expression that could
show up into a TEX command. For Tick marks these are usually just numbers, so you
might want to use the FormatTicksX and FormatTicksY options to apply a function that
sets exactly the number format you want. See also NumberToTeX, a function that could
setting

be used for this job.
The full list of these options is

ˆ FormatAxesLabelX, FormatAxesLabelY, FormatFrameLabelEast, FormatFrame
LabelEastRotated, FormatFrameLabelNorth, FormatFrameLabelSouth, Format
FrameLabelWest, FormatFrameLabelWestRotated, FormatFrameTicksEast,
FormatFrameTicksNorth, FormatFrameTicksSouth, FormatFrameTicksWest,
FormatPlotLabel, FormatTicksX, FormatTicksY.

C
C

The rotated variants are used when

Rotated→True

has been applied to the graph-

ics.

Generate

CTemporaryName
GuessTag

GenerateTemporaryName["hprepend i"] creates a string that can be used as a unique
"hprepend i".

le name and starts with a given string

GuessTag[hexpr i]

tries to create a unique string describing

hexpr i

and entirely con-

sisting of alpha-numerical characters. (This is called a tag.) It is used by

PSfragTag→Automatic

ˆ MaximumTagLength: Option
produced by GuessTag.
ˆ MinimumTagLength: Option
produced by GuessTag.

GuessTeX

ReplacementHook

CCooperative

PSfrag when

is set (default).
for

GuessTag.

This sets the maximum length of a tag

for

GuessTag.

This sets the minimum length of a tag

GuessTeX[hexpr i] creates a string containing
PSfrag (see there) when TeXCommand→Automatic

the TEX form of

expr.

It is used by

is set (default).

ReplacementHookCooperative Option for GuessTex which contains a list of shape
{{priority, test, applybefore, applyafter},...} that can be used to customize
the behavior of GuessTeX. Starting with the lowest value of priority, each test is called
AT X
with the Mathematica expression that GuessTeX is supposed to transform into a L
E
expression. Each test that returns True will cause the respective applybefore command
to be applied to the Mathematica expression. In addition after the default generation

AT X code that is preformed in any case, the associated
of L
E

AT X code.
applied to the string containing the L
E
18

applyafter

command is

ReplacementHookExclusive Option for GuessTeX which contains a list of shape ReplacementHook
{{priority, test, command},...} that can be used to customize the behavior of CExclusive
GuessTeX. Starting with the lowest value of priority, each test is called with the
Mathematica expression that is to be transformed to a LATEX expression. The rst
AT X code. Instead the
test returning True  if any  will stop the default generation of L
associated

command

E

is called and its return value is used as TEX code.

HandleAutomaticPSfrag[graphics,opts]

PSfrag commands around all tex- HandleAutomatic
tual elements generated by the graphics options AxesLabel, Ticks, PlotLabel, Frame CPSfrag
Label and FrameTicks. It accepts a number of options, all starting with Format,
that allow to ne-tune this behavior. For example FormatTicksX has the default value
PSfrag. Setting FormatTicksX→(PSfrag[#,TeXCommand→myFormatter[#]]&) would
wraps

C

allow to write a function that gives better TEX output for all entries on the x axis. See
also

NumberToTeX.

PSfrag commands
Text elements generated by the associated Plot option. Use OptionsTo
decide if this handler is called and the corresponding Format... options to

The following are default handlers that take care of auto-wrapping
around the

CHandle

to

ne-tune the formatting.

ˆ HandleAxesLabel
ˆ HandleFrameLabel
ˆ HandleFrameTicks
ˆ HandlePlotLabel
ˆ HandleTicks

MathPSfragConfigurationTest[[tempfile ],[opts ]] checks the conguration of MathPSfrag
UnPSfrag (see there). [tempfile ] is by default a (hopefully) unique name generated CConfiguration
CTest
from $SessionId. It is written to the current directory. By default the test is not carried out if [tempfile ] already exists, though you can set ForceOverwrite→True as an
option to change that. Be careful. It may be better to simply provide a dierent name
for

tempfile.

NextLaTeXError[[n ]] displays the n-th error in a LATEX run performed by UnPSfrag. NextLaTeXError
When omitting the argument it shows the rst error message.

OptionHandlers:
Plot options

signs to

Option for

HandleAutomaticPSfrag

and

PSfragExport

that as-

dierent default handlers that actually carry out the formatting.

Format... options
setting OptionsToHandle

Usually do not touch this option but instead use the corresponding
to change the behavior or switch automatic handling o by
accordingly.

19

OptionHandlers

OptionsToHandle

OptionsToHandle

Option for

HandleAutomaticPSfrag

and

PSfragExport

that con-

tains a list of all options that are taken care o by the automatics. Currently automatics
are implemented for
the default value of

AxesLabel, Ticks, PlotLabel, FrameLabel, FrameTicks, which is
OptionsToHandle. You can switch o the automatics entirely by

setting this option to . The formatting of a Plot's elements can be changed by setting
the corresponding

PSfrag

Format...

options.

PSfrag[hexpr i, [opts ]] can be used to achieve a higher level of control over the
output of PSfragExport by attaching individual typesetting information to hexpr i. Use
PSfrag[expr] where ever you want to display StandardForm[hexpr i] (or Traditional
Form) on the screen, while a corresponding TEX command will be prepared for use
AT X. A typical use is Plot[..., PlotLabel→PSfrag[expr,opts]]. The most
within L
E
important option to PSfrag is TeXCommand, which allows to dene how expr is typeset

C

when exported to an

EPS le.

PSfragExport[hfilename i, hgraphics i] to write an EPS le in the current
working directory (see SetDirectory).
PSfragExport will append a sux (default:
-psfrag.eps) to hfilename i. This le will contain a substitute alphanumeric tag for every PSfrag command which in turn is replaced by a TEX command (by default guessed by
a stupid algorithm) using the \psfrag command (see documentation of psfrag.sty). The
replacement TEX rules are by default written to filename-psfrag.tex. You may independently generate and display these \psfrag commands by CreatePSfragRules[graph
ics].
PSfrag is automatically threaded over a List when the argument of TeXCommand is
a List of same length.
The available options are TeXCommand, TeXPosition, PSPosition, PSRotation, PS
Scaling, PSfragTag. Each has a separate help text. You might also want to study the
documentation shipped with psfrag.sty.
Use

C

C

PSfragTag

PSfragTag

PSfrag that may be used to manually set the tag that
is used by the TEX command \psfrag to substitute for a TEX command. Usually the
default setting (PSfragTag→Automatic) gives good results an should be left unchanged.
If you have problems with too large tags, you might also try to use RenumberTags→True
as an option for PSfragExport, which yields shorter tags.

PSPosition

PSPosition is an option of PSfrag dening the alignment of the postscript text
output by Export. Its default CopyTeXPosition takes over value of the TeXPosition
option, while the value Automatic is replaced by the alignment of the rst surrounding
Text graphics directive. Explicit values can be the same as those of Position.

is an option of

CopyTeXPosition

CopyTeXPosition:

PSRotation

PSRotation

Default value of

is an option of

PSfrag.

PSfrag's

option

PSPosition.

Its range is 0 to 360 degree. It may be used to

20

turn the text counterclockwise in the nal PostScript output.

PSScaling

is an option of

PSfrag.

It is a positive number which is used to increase

the size of any TEX command's output in the nal
meaning no rescaling.

le.

The default value is 1,

It is recommended not to use this option but instead use TEX

\small. MathPSfrag inserts \PFGstyle commands in front of each TEX
\newcommand{\PFGstyle}{\small} in the preamble will therefore

commands like
expression.

EPS

PSScaling

Issuing

scale all labels in a manuscript.

TeXCommand is an option of PSfrag.

C→Automatic]

The default

PSfrag[hexpression i, TeXCommand TeXCommand

deduces the TEX command from the given expression. For complicated

expressions, this may not give satisfactory results and you may have to set them by
hand using

TeXCommand→"TeX command string".

(Note, that the

TeXForm

output of

Mathematica is version dependent.) If the argument is not a string, it is assumed to
be a function that returns a suitable TEX string when applied to the Mathematica
expression.

TeXPosition is an option of PSfrag dening the alignment of the TEX text replacing TeXPosition
the tag in the

EPS output.

Possible values are any two-character combination of ("B",

"t", "c", "b") and ("l", "c", "r"). The default is

Automatic.

For the x label in

AxesLabel

you should use "Bl".

TeXShift→{"hx i","hy i"}
box by the specied amount.

is an option of

hx i

a numeric value is given, the unit

and

pt

hy i

PSfrag

shifting the position of the TEX

are TEX dimensions; e.g.,

3cm

or

4pt.

TeXShift

When

is assumed.

TeXShiftX→hvalue i

is equivalent to

TeXShift→{hvalue i,0}.

TeXShiftX

TeXShiftY→hvalue i

is equivalent to

TeXShiftY→{0,hvalue i}.

TeXShiftY

PSfragExport[hfilename i, hgraphics i, [opts ]]

writes

an

Encapsulated

Post-

EPS) version of graphics into a le. Filename may contain a directory, otherwise
the EPS le is written into the current working directory. This EPS le is meant to be read
Script (

\includegraphics and processed by the PSfrag LATEX package. The TEX commands
required by PSfrag are also written into a le. Note that PSfragExport automatically
appends suces dened by EpsSuffix→... and TeXSuffix→... to create the actual
le names. PSfragExport rst generates automatic PSfrag commands for all textual elements of a graphic (including numbers and formulas) by calling HandleAutomaticPSfrag.
All options [opts ] are passed through. This means that in particular special formatting
by

21

PSfragExport

HandleAutomaticPSfrag can be given directly to PSfragExport. The
PSfragManualExport, which does the actual job of creating the
EPS and TEX le. A list containing hfilename i and the names of the generated les is
returned. This list is suitable as input for UnPSfrag, such that typical usage looks like
this: PSfragExport["mydemo",myplot]//UnPSfrag
instructions of

second step is to call

ˆ EpsSuffix
ˆ TeXSuffix

PSfragManual

CExport

PSfragManualExport[hfilename i,hgraphics i] converts all PSfrag entries in a
Graphics object into alphanumerical tags using CreatePSfragRules. The result is
exported into an ordinary EPS le, while the generated \psfrag TEX commands are
written into a TEX le.

The respective le names are determined from the param-

hfilename i and the sux given in the PSfragExport options EpsSuffix and
TeXSuffix. PSfragManualExport returns a list of the form {filename, epsfilename,
texfilename}, which is suitable as input to UnPSfrag. PSfragManualExport is internally
called by PSfragExport after constructing automatic PSfrag commands for all textual
elements in a graphic by calling HandleAutomaticPSfrag.
eter

PSfragTicks

PSfragTicks[htickspec i,[opts ]] maps PSfrag[#,hopts i]& at each label in a tick
mark specication (see the Ticks option of Plot). Note that tickspec is for one axis
only, so PSfragTicks has to be applied to each axis. Since PSfragExport applied to
two-dimensional graphics will automatically wrap PSfrag at the correct positions, this
is only needed, when you want to have additional control over the output or for threedimensional plots.
A typical usage example:

Needs["CustomTicks`"];
Plot3D[..., Ticks->{
PSfragTicks[LinTicks[xmin,xmax], TeXPosition->"Bc"],
PSfragTicks[LinTicks[ymin,ymax], TeXPosition->"Bl"],
PSfragTicks[LinTicks[zmin,zmax], TeXPosition->"Br"] }];

TextToPSfrag

TextToPSfrag[hgraphics i] simply wraps PSfrag around all Text directives conhgraphics i. It is used by HandleAutomaticPSfrag, which in turn is called
PSfragExport.

tained in
by

UnPSfrag

UnPSfrag[{houtputprefix i,hepsinfile i,htexinfile i},[opts ]]

transforms

an

EPS graphics le hepsinfile i relying on \psfrag commands (contained in htexinfile i)
into a standalone graphics.

.eps

or

.pdf

outputprefix should give a valid lename when a sux like

is appended.

Example:

22

UnPSfrag[PSfragExport["example",myplot]];
PSfragExport["example",myplot]//UnPSfrag;

BoundingBoxDevice

is an option for

or

UnPSfrag

that defaults to

Ghostscript's bbox BoundingBox

device. Do not change this option unless you have good reason to do so. The format
is a

device triplet

device like

png

or

as described for the

pnm

PreviewDevice

CDevice

option. You may choose a raster

here in which case Mathematica will determine the bounding box

from the bitmap graphic by counting non-empty rows and columns. This is not quite
as precise as the bounding box generated from
memory and time.

Ghostscript's bbox

device and takes more

It has the advantage of correctly dealing with invisible elements,

which are not cut o by

Ghostscript's bbox.

DvipsExecutable is an option for UnPSfrag that contains an absolute or relative DvipsExecutable
dvips command. On Unixes this will usually be in the system path, so no
change will be required in most cases. On Windows systems dvips neither has a standard
location nor is it necessarily in one of the folders given in the system's PATH environment
variable. In that case, you will have to manually search the dvips program and set the absolute path explicitly, e.g. DvipsExecutable→"C:\Programs\texmf\bin\dvips". Also
make sure to set the correct values of LaTeXExecutable and GhostscriptExecutable.
You can check your conguration with MathPSfragConfigurationTest. The MathPSfrag
-Test.nb notebook gives a step-by-step guide for the correct conguration of UnPSfrag.
name of the

C

DvipsOptions

EPS les.

UnPSfrag that is passed on to dvips when producing DvipsOptions
"-Ppdf" will ensure replace bitmap by outline fonts on most

is an option for

Its default value

modern systems.

ForceOverwrite→boolean Option for UnPSfrag and for MathPSfragConfiguration ForceOverwrite

CTest

(see there, respectively).

GhostscriptExecutable→"hstring i"

is an option for

absolute or relative name of the Ghostscript command.

gs

UnPSfrag

that contains an

On Unixes this defaults to

and will usually be in the system path, so no change will be required in most cases.

gs-gpl. On Windows systems, this option defaults
gswin32c, but the program neither has a standard location nor is it necessarily in one
of the folders given in the system's PATH environment variable. In that case, you will
have to manually search the gswin32c program and set the absolute path explicitly;
e.g. GhostscriptExecutable→"C:\Programs\texmf\bin\latex". Also make sure to
set the correct values of LaTeXExecutable and DvipsExecutable. You can check your
conguration with MathPSfragConfigurationTest. The MathPSfrag-Test.nb notebook
gives a step-by-step guide for the correct conguration of UnPSfrag. (Also have a look
Sometimes you have to change this to
to

23

Ghostscript

CExecutable

at

explained there.)

IncludeGraphicsOptions

IncludeGraphics

COptions

$PostMathPSfrag

UnPSfrag that can be used to change the
IncludeGraphicsOptions→"width=3in" will

is an option for

size of the generated image. For example

AT X does not
change the size of the plot. However the size is only approximate since L
E
include the size of the labels in the calculation.

LaTeXExecutable

LaTeXExecutable is an option for UnPSfrag that contains an absolute or relative
name of the latex command. On Unixes this will usually be in the system path, so no
change will be required in most cases. On Windows systems latex neither has a standard
location nor is it necessarily in one of the folders given in the system's PATH environment
variable. In that case, you will have to manually search the latex program and set the absolute path explicitly, e.g. LaTeXExecutable→"C:\Programs\texmf\bin\latex". Also
make sure to set the correct values of DvipsExecutable and GhostscriptExecutable.
You can check your conguration with MathPSfragConfigurationTest. The MathPSfrag
-Test.nb notebook gives a step-by-step guide for the correct conguration of UnPSfrag.
Also have a look at $PostMathPSfrag.

C
LaTeXOptions

LaTeXOptions

is an option for

AT X during the creation of
on to L
E

MasterTeXFile

MasterTeXFile

UnPSfrag

is an option for

EPS les.

that contains command line options passed

UnPSfrag

that contains the full TEX le that is used

to convert the psfrag-EPS into a nal PostScript version. Then Ghostscript is used to
convert this pure PostScript le into other formats.

PreviewDevice

PreviewDevice is an option for UnPSfrag.

Unless there are severe problems, the only

value you might choose instead of the default is
Allowed values are

None

None

to suppress generation of preview

{gsdevice, suffix,
options}, where gsdevice is the name of a Ghostscript device, suffix is a string that
is a suitable sux for the generated le, e.g. .eps for an EPS le, and options are
additional command line options to Ghostscript that can be used to change anti-aliasing
settings or the like. Typically a preview device should be a raster device, like pnm or png.
Further information can be found in the documentation of the Ghostscript program.
images.

or a device triplet; i.e. a list

Remove

RemoveTemporaries is an option for UnPSfrag that can be set to False for debugging.

SuppressOutput

SuppressOutput

CTemporaries

is an option for

UnPSfrag

put of external programs.

24

that contains instructions to discard out-

TemporaryDirectory is an option for UnPSfrag that gives the name of a subdirectory Temporary

AT X run in performed. All intermediate les are stored there. The temporary
where the L
E

CDirectory

directory is removed after successful execution unless RemoveTemporaries has been set
to False.

TeXPreamble
produced by

UnPSfrag that in particular can be used to change TeXPreamble
UnPSfrag needs a TEX le to convert a psfrag-EPS le, as

is an option for

the fonts used in the image.

PSfragExport,

to an

EPS le independent of any psfrag commands.

TeX-

Preamble is a string that is included in the TeXPreamble of that le and can be used to

AT X packages. For example:
include additional L
E

TeXPreamble→"\usepackage{euler}"

to change the math fonts.

UnPSfragOutputFormats is an option for UnPSfrag that contains a list of devices UnPSfragOutput
{{gsdev1, suffix1, opts1}, ..., {gsdevN, suffixN, optsN}}. gsdev CFormats
is a string containing the Ghostscript device like png, pdf and so forth. The suffix is for
the lename and should contain a leading dot; i.e. .png, .pdf. The options in opts are
passed to the respective Ghostscript call and allow to set additional options. In particular
triplets; i.e.

the resolution and the anti-aliasing settings.

8

General auxiliary functions

PatchType1FontIntoEps[hinfile i,houtfile i]

copies missing fonts into an

This is a hack that will result in possibly usable but not standard conformant
The upshot:
with

Do not use this.

MathPSfrag,

You will not need this when you replace all expressions

which is a clean solution.

NumberToTeX[hnumber i,[opts ]]
sents number.

EPS le. PatchType1Font
EPS les. CIntoEps

returns a string containing TEX code that repre-

NumberToTeX

There are several options that inuence the appearance of number:

IntegerPartDigits

determines the number of digits before the decimal point in a

FractionalPartDigits sets the number of digits after the decChopExponent is True, exponents of the form 100 are suppressed.
ChopImaginaryPart→True turns complex numbers with almost vanishing imaginary part
into real numbers. In a similar manner Integerize→True will turn oating point numbers like 1. into integers. ExponentSymbol→"\cdot 10
" will format oats in the form
1.23 \cdot 10^{4}. This is the default behavior. Example: NumberToTeX[Exp[10.]].
oating point number,

imal point.

When

ˆ ChopExponent, ChopFractionalPart, ChopImaginaryPart, ExponentSymbol, Frac
tionalPartDigits, Integerize, IntegerPartDigits, IntegerToReal, Ration
alToReal

C
C

NumToBase52[hinteger i]

converts a non-negative

string.

25

hinteger i

into an alphabetic

NumToBase52

LatinCharacterSet
LatinQ.

LatinCharacter

CSet

LatinNum

CCharacterSet

is a list containing all 52 letters from A to Z and a to z.

Used by

LatinNumCharacterSetis

CNumQ

LatinNumQ["hstring i"]

LatinNumQ

a list of all 52 Latin letters and 10 digits. Used by

returns

True

if

string

Latin

consists entirely of alphanumerical

characters (A-Z, a-z, 0-9).

LatinQ["hstring i"]

LatinQ

returns

True

if string consists entirely of letters A to Z and a

to z.

9

Mathematica 4.x5.0

MathPSfrag

AT X code that corresponds to a particular Mathematica
creates the L
E

expression by calling

TeXForm.

Starting from version 5.1 the

supporting code, that only requires a few standard packages.

TeXForm output is selfPre-5.1 TeXForm output

will require an additional style le providing Mathematica fonts that have to be congured accordingly [6, 7, 8]. In the new approach, since a large number of Mathematica

AT X packages, some symbols are created
symbols do not have counterparts in standard L
E
by gluing together existing symbols. When applied carefully, this method can achieve
acceptable results; though the current implementation is not optimal yet.
The problem with the pre-5.1 output in conjunction with the

PSfrag

method is that

AT X installation,
it requires the Mathematica fonts to be available in the publisher's L
E
while in general they willif at allonly be available to the author. (This should not be
a problem when the author decides to follow the

UnPSfrag

approach, where all required

fonts are embedded into the image les. It is then however necessary to include the style

UnPSfrag option: TeXPreamble→"\usepackage{...}".)
PSfrag approach requires a compatibility package
(mma4tex.tex) that is included in the MathPSfrag distribution. Basically it parses Mathles by setting the according

To avoid these problems in the

ematica 4.x5.0 LATEX code and replaces it by code similar to the output of version
5.1/5.2. When MathPSfrag detects Mathematica 5.0 or earlier, PSfragExport creates
automatically

PSfrag

mma4tex.tex and issue a warning when
mma4tex.sty that additionally loads
mma4tex.tex is only loaded once. It is rec-

les that attempt to load

unsuccessful. There is also a corresponding style le
the required font packages and ensures that

ommended to include it in the preamble. Therefore both les have to be installed where

AT X can nd them; e.g., in a directory
L
E

tex/latex/mma4tex/ relative to the texmf direc-

AT X distribution. Thereafter the le database ( ls-R) has to be updated.
tory of the L
E

Again the details depend on the distribution.

Typical names of the update command

mktexlsr or texhash. For MiKTeX there is the choice between the command line
program (initexmf -u) and a graphical conguration program (MiKTeX Options or
are

Settings; press the button General/File Name Database/Refresh Now).

26

10

Known Bugs and Limitations

MathPSfrag relies on three Mathematica commands: TeXForm, FullGraphics
AbsoluteOptions. All are potential sources of failure.

and

For the rst one, this is due to substantial changes concerning its output in its version
history, which do not seem to have been publicly documented. With the latest steps in

amsmath compatible LATEX though, TeXForm will probably stabilize
AT X packages. To make the TeXForm output
need for non-standard L
E

the transition towards
with respect to its

of Mathematica versions 4.x5.0 rely on standard packages only, a compatibility layer
has been written, cf. section 9. However it will not produce satisfactory output regarding

AT X. Since for most
those Mathematica symbols that have no direct counterpart in L
E

AT X are sucient, this is only a minor restriction,
purposes the symbols available in L
E
which also applies to the

TeXForm

output of Mathematica version 5 anyway. In any

case, single occurrences of malformed

TeXCommand

option of

PSfrag.

TeXForm output may easily be overridden using the

FullGraphics, which is not faithful in the sense
Show[FullGraphics[...]] do not yield exactly the same output.
The same is true for AbsoluteOptions and may be a potential source of errors. The code
has been written such that the FullGraphics plot is only used for alignment information
The automatic positioning relies on

that

Show[...]

and

but discarded afterward in order to isolate this discrepancy.
For

AbsoluteOptions

this has not been possible since its output is directly needed.

So far the only observed dierence is that

AbsoluteOptions

turns integers into oating

point numbers. Therefore a mechanism to override this behavior has been implemented in

GuessTeX, the function implementing automatic generation of LATEX code in MathPSfrag:
Floating point numbers very close to integers are converted back to integers. Clearly this
introduces another potential source of mysterious errors. Therefore this mechanism can
be completely congured.

GuessTeX

provides two options:

CHookExclusive

.

form

ReplacementHookCooperative

and

Replacement

The former contains of a set of rules, each of which is a list of the

{rank, test, trafoexpr, trafotex}.

The rank is simply used to determine the

order of the rules (low rank rst). For all rules,

test

is a function that evaluates the

Mathematica expression to be turned into LATEX and determines if the rule is activated.
For all activated rule, rst all trafoexpr functions are applied to the Mathematica
AT X string using TeXForm and nally the trafotex
expression, it is then turned into a L
E

transformations are applied to the string.
Currently there is only one rule (albeit in two dierent versions) for

CHookCooperative

Replacement

:

ReplacementHookCooperative-> {
If[$VersionNumber >= 5.1,
{10000, True &, Identity, StringJoin["$", #, "$"] &},
{10000, (Head[#] =!= String)&, Identity, StringJoin["$", #, "$"] &}]};
Mathematica 5.1

TeXForm

always returns expressions in math mode, so the default

rule is to always wrap dollar sign around the nal expression.

TeXForm

Mathematica pre-5.1

will return expressions that are strings in text mode, such that they don't need

to be wrapped in dollar signs. (This is checked by the test in the last line.)

ReplacementHookExclusive option contains a set of rules that have the form
{rank, test, trafo}. The main dierence is that the rst rule that is activated (test
The

27

Example 90

0
12
ple
am
x
E

Ex
am
ple
60
Ex

am

ple

0

30

am
p
l
e
150

210
ple
am
Ex
Ex Example 180
0

24

Example 270

E

xam
ple

30
ple
m
a
Ex Example 0
Ex
am
ple
330

Figure 6: Example for substituting rotated text. To demonstrate that the new export
function can preserve the orientation, only half of the labels have been substituted by

AT X.
L
E

GuessTeX: The expression is
unmodied into the PSfrag replacement

returns True) will immediately stop further evaluation by

trafo and its result is written
GuessTeX expects this result to be a string.

handed over to
le. Therefore

Only when none of these rules

were activated, the cooperative mechanism described rst will be employed.
The current content of the exclusive option is:

ReplacementHookExclusive->Join[{
{ 900, (NumberQ[#] && Chop[# - Round[#]] === 0 )&,
"$" <> ToString[Round[#]] <> "$" &},
{1000, (NumberQ[#] && (StringPosition[ToString[#], "\n"] === {})) &,
"$" <> ToString[#] <> "$" &},
{1100, NumberQ, "$" <> NumberToTeX[#] <> "$" &} },
If[$VersionNumber < 5.1, {
{5000, (Head[#] === PaddedForm) &, ToString[" " <> ToString[#], TeXForm] &}
}, {}] ];
The rst line undoes said

AbsoluteOptions

bug by rounding real numbers to integers

when they are very close to integers already (less then
The

TeXForm output of

representation into TEX.

10−10 ).

Mathematica up to 5.2 always turns a number's
The second line uses

ToString,

InputForm

which preserves the chosen

form of the number. However, this approach will not work when a oating point number
is processed that has a large exponent. (The test rejects multiple line output.) The third
line will process any remaining numbers by applying
function provided by

MathPSfrag.

NumberToTeX,

a simple formatting

TeXForm treats
PaddedForm as a mathematical function whose name is output verbatim. ToString shows
The last line intercepts another Mathematica 4.x5.0 peculiarity:

the correct behavior, that is merely a number. It should be noted that there is a number
of other

...Form commands that might not be treated correctly in Mathematica pre-5.1

and require similar work-arounds.

11

Figure Source Code

The source code of all example plots is listed and commented below. It can also be found
in the test notebook (MathPSfragTest.nb) that comes with
to congure and check the installation of

MathPSfrag.

28

MathPSfrag and can be used

In the example code below, it

sin(25x2 −6)
sin(5x)+2

1.0
0.5
0.0
−0.5
.0

0.5

1.0

x
1.5
2.5
2.0
3.0
HoldForm, Mathematica would

HoldForm example: Without
6−25x2
y axis to − sin
2+sin(5x) . The CustomTicks
typical stripped decimal 1. on the x axis.

Figure 7:

the label on the
the

normal order

package has been used to avoid

will be assumed that all necessary packages have already been loaded. In particular the
comparison of the automatic and manual examples should be educational.

11.1

Rotated Text

Text
Export and PSfragExport do the right thing, cf. g. 6.
demonstrated, that PSfragExport can apply the option PlotRange→

While in some environments Mathematica does not rotate the letters of a rotated
on screen, both the conventional
Furthermore, it is

All

to the graphics before carrying out the export.

Show[Graphics[{
Table[Text["Example " <> ToString[Round[phi*180/Pi]],
{Cos[phi], Sin[phi]}, {0, 0}, {Cos[phi], Sin[phi]}],
{phi, 0, 2Pi - 0.01, 2Pi/6}],
Table[Text[PSfrag["Example " <> ToString[Round[phi*180/Pi]]],
{Cos[phi], Sin[phi]}, {0, 0}, {Cos[phi], Sin[phi]}],
{phi, 2Pi/12, 2Pi - 0.01, 2Pi/6}],
Circle[{0, 0}, 1]
}]];
PSfragExport["ex_rot", %] // UnPSfrag;
11.2

HoldForm plus CustomTicks

HoldForm can be used to x the shape of an
CustomTicks [10] can be used to circumvent the usual

Fig. 7 is a plain example demonstrating that
expression while

LinTicks

from

stripped decimal 1. and print a much nicer 1.0 instead.

holdformexpr := HoldForm[Sin[25x^2 - 6]/(Sin[5x] + 2)];
holdformex = Plot[Evaluate[ReleaseHold[holdformexpr]], {x, 0, 3},
AxesLabel→{x, holdformexpr},
Ticks→{LinTicks[0, 3], LinTicks[-1, 1]},
PlotStyle→Hue[0.6],
PlotRange→{{0, 3}, {-1.2, 1.2}}, PlotPoints→100, AxesOrigin→{0, -1}]
PSfragExport["ex_hold", holdformex] // UnPSfrag

29

0.5
0.0
−0.5

−0.5

0.0
0.5

0.5

0.0
−0.5

.0

Figure 8: Three dimensional example: As there exists no
manual labeling was required and the

RenumberTags

FullGraphics3D command,
PSfragExport was used

option of

to produce smaller tags, increasing positioning precision.

11.3

Three-dimensional Knot

Here, the three-dimensional knot in g. 8 is generated.

knot3d[r_, phi_] =
Flatten[{(0.5 + 0.2*Cos[phi/5] + r*Sin[1.7phi]){Cos[phi], Sin[phi]},
phi/(5Pi) + r*Cos[1.7 phi]}];
ParametricPlot3D[Evaluate[knot3d[r, phi]], {phi, -3Pi, 4Pi}, {r, 0.05, 0.2},
Ticks → {
PSfragTicks[LinTicks[-1, 1], TeXPosition → "Bc"],
PSfragTicks[LinTicks[-1, 1], TeXPosition → "Bl"],
PSfragTicks[LinTicks[-1, 1], TeXPosition → "Br"]},
PlotPoints → {200, 3}, ViewPoint → {-1.1, 2.6, 2.2}]
PSfragExport["ex_3d"] // UnPSfrag;

30

3

3

2

2

p
√
3 3 cos2 (2 x)

1

3 cos

1

0

2π

3π
2

4x

2
3

0

sin(x)

local maximum
−1
π
π
0
2

√

−1

sin(x)
local maximum
0

π

π
2

a) automatic

3π
2

2π

b) manual

PSfragExport vs. b) Plot without resorting
PSfragManualExport. Additionally, the typesetting of

Figure 9: Comparison: a) Plot exported with
to automatics; i.e., exported with

the  cos . . .  label has been manually improved.

11.4

Automatic vs. Manual Example

Fig. 9a has been created using strictly the automatics provided through

PSfragExport,

while g. 9b achieves the same result by not relying on automatics at all but instead
marking each textual element with a

CExport

PSfrag command and exporting with PSfragManual

. Both examples share the rst lines of code that stretch over the full width.

f1[x_] := Sin[x];
f2[x_] := 3*((Cos[2 Sqrt[x]])^2)^(1/3);
SimpleLabel[tip : {_, _}, txt_, txtpos : {_, _}, align : {_, _}] := Sequence[
Arrow[txtpos, tip, HeadScaling→Absolute, HeadLength→8, HeadCenter→{}0.6],
Text[txt, txtpos, align]];
mygrid = Map[{#, {AbsoluteDashing[{0.1, 1}], GrayLevel[0.5]}} &, {Pi*{1/2, 1, 3/2}, {1, 2}}, {2}];
(* Automatic *)

tickmarks = {
Pi/2*{0, 1, 2, 3, 4},
Automatic,
None,
None};

(* Manual *)

mantickmarks = {
{N[#], PSfrag[#, TeXPosition→"tc"]} &
/@ (Pi/2*{0, 1, 2, 3, 4}),
{N[#], PSfrag[#, TeXPosition→"cr"]} &
/@ {-1, 0, 1, 2, 3},
None, None};
mantexstr = "$3\left|\cos \sqrt{4x}\right|^\frac{2}{3}$";

textlabels = Graphics[{
SimpleLabel[{Pi/2, f1[Pi/2]},
"local maximum",
{1, -0.5}, {0, 1}],
SimpleLabel[{7/6Pi, f1[7/6Pi]},
f1[x], {4.2, -0.3}, {-1, 0}],
SimpleLabel[{4.2, f2[4.2]},
f2[x],
{3.5, 1.5}, {1, 0}]
}];

mantextlabels= Graphics[{
SimpleLabel[{Pi/2, f1[Pi/2]},
PSfrag["local maximum", TeXPosition→"tc"],
{1, -0.5}, {0, 1}],
SimpleLabel[{7/6Pi, f1[7/6Pi]},
PSfrag[f1[x], TeXPosition→"cl"], {4.2, -0.3}, {-1, 0}],
SimpleLabel[{4.2, f2[4.2]},
PSfrag[f2[x], TeXPosition→"cr", TeXCommand→mantexstr],
{3.5, 1.5}, {1, 0}]
}];

rawplot = Plot[
{f1[x], f2[x]}, {x, 0, 2 Pi},
PlotStyle→{Hue[1.0], Hue[0.6]},
Frame→True, FrameTicks→tickmarks,
TextStyle→{FontFamily→"Times"}];

manrawplot = Plot[
{f1[x], f2[x]}, {x, 0, 2 Pi},
PlotStyle→{Hue[1.0], Hue[0.6]},
Frame→True, FrameTicks→mantickmarks
];

exampleplot = Show[rawplot, textlabels,
GridLines→mygrid];

Show[manrawplot, mantextlabels,
GridLines→mangrid];

PSfragExport["ex_auto", exampleplot];

PSfragManualExport["ex_manual", %];

Export["ex_nopsfrag.eps", exampleplot];

31

12

How to bug report

There is a number of things you can do/tell me to speed up the process of nding the
error:
1. What is your operating system (Windows, Linux, Mac OS)?
2. What is your Mathematica version (4.x, 5.x, 6.x)?
3. What are the steps that lead to the error? Please create a
copy all lines needed (and

only

minimal

example. Just

those) to reproduce the error into a fresh notebook.

Then think about if there are lines that can still be removed. Then quit your kernel
and evaluate the notebook in one rush.
4. Send me an email (see rst page of this manual).

5

5. Send me your credit card number.

5

Just kidding, of course I only accept cash.
32

A

Program Summary

Manuscript Title:

MathPSfrag: Creating Publication-quality Labels in Mathematica®

Plots

Authors:

Johannes Groÿe

Program Title:

MathPSfrag

Journal Reference:
Catalogue identier:
Program available from:

http://wwwth.mppmu.mpg.de/members/jgrosse/mathpsfrag

Licensing provisions:

CPC non-prot use license

Programming language:

Mathematica 6.0, 5.2, 5.0, 4.1

Computer:

Tested on x86 architecture

Operating systems:

Tested on Linux, Windows XP

RAM used during test run:

11 Mb

Keywords:

Encapsulated PostScript,

PACS:

01.30.Rr

Classication:

14 Graphics

External routines:

Standard

Nature of problem:

Insucient typesetting quality of labels in graphics exported from

Solution method:

An automatic export function is provided that generates LATEX substitution labels.

Requirements:

LATEX, Ghostscript, PSfrag; recommended: ps2eps, pdfcrop, Perl

Restrictions:

The described method requires to some extent the use of Encapsulated PostScript (EPS) graphics though conversion to PDF is supported. Special
characters that do not have a direct
counterpart in LATEX will not show satisfactory typesetting quality.
For
versions earlier than 5.1, the automatically created
LATEX code requires a compatibility LATEX package, which is included
in the package. In
4.1, one of the examples does not
work in its current form due to a bug in
's Export
command. However, the same eect can be achieved using exclusively
MathPSfrag's rotation mechanism.

Mathematica, PSfrag, L TEX

Mathematica packages

Mathematica

Mathematica
Mathematica
Mathematica

Running time:

A

Mathematica

41s for all examples in this article

References
[1] J. Groÿe, MathPSfrag: Publication quality labels with Mathematica. 1
[2] W. McKay, R. Moore, Convenient Labelling of Graphics, the WARMreader Way,
TUGboat 20(3).
URL

http://www.tug.org/TUGboat/Articles/tb20-3/tb64ross.pdf

3

[3] M. C. Grant, D. Carlisle, The PSfrag system, version 3.
URL http:
//www.ctan.org/tex-archive/macros/latex/contrib/psfrag/pfgguide.ps
4, 6, 7

33

3,

[4] S. Wolfram, The Mathematica book (4th edition), Cambridge University Press,
New York, NY, USA, 1999. 3
[5] Wolfram Research, Inc., Mathematica 5.2 (2005).
URL

http://www.wolfram.com/

3

[6] WRI Support, tetex 1.0 with mathematica?

http:
//support.wolfram.com/mathematica/interface/export/tetexconfig.html
URL

3,

26
[7] WRI Support, Mathematica fonts and ghostscript.

http:
//support.wolfram.com/mathematica/graphics/export/ghostscript.html
URL

3,

26
[8] WRI Support, Mathematica fonts in eps les.
URL http:
//support.wolfram.com/mathematica/graphics/export/includefonts.html

3,

26
[9] J. Groÿe, MathPSfrag.
URL

http://wwwth.mppmu.mpg.de/members/jgrosse/mathpsfrag/

3

[10] M. Caprio, Custom tick marks for linear, logarithmic, and general nonlinear axes
(2005).
URL

http://library.wolfram.com/infocenter/MathSource/5599/

4, 5, 8, 29

pst-pdf package.
http://www.ctan.org/tex-archive/graphics/pstricks/contrib/
pst-pdf/pst-pdf.pdf 4

[11] R. Niepraschk, H. Gäÿlein, The
URL

pdftricks.
http://www.ctan.org/tex-archive/macros/latex/contrib/pdftricks/

[12] A. Chambert-Loir, R. CV, R. CV,
URL

[13] T. Tantau, The beamer
URL

class.

http://latex-beamer.sourceforge.net/

4

pdfcrop.
http://www.ctan.org/tex-archive/support/pdfcrop/

[14] H. Obeberdiek,
URL

[15] Red Hat, Inc., Homepage of the
URL

http://www.cygwin.com

GPL'ed cygwin version.

6, 16

34

4

4

Index
BoundingBoxDevice, 23

Integerize, 25

BoundingBoxFromRaster, 17

IntegerPartDigits, 25
IntegerToReal, 25

ChopExponent, 25
ChopFractionalPart, 25

LaTeXExecutable, 24

ChopImaginaryPart, 25

LaTeXOptions, 24

CopyTeXPosition, 20

LatinCharacterSet, 26

CreatePSfragRules, 17

LatinNumCharacterSet, 26
LatinNumQ, 26

DvipsExecutable, 23

LatinQ, 26

DvipsOptions, 23
MasterTeXFile, 24
EpsSux, 22

MathPSfragCongurationTest, 19

ExponentSymbol, 25

MaximumTagLength, 18

FetchGhostscriptDevices, 17

MinimumTagLength, 18

ForceOverwrite, 23

NextLaTeXError, 19

Format, 17

NumberToTeX, 25

FormatAxesLabelX, 18

NumToBase52, 25

FormatAxesLabelY, 18
FormatFrameLabelEast, 18

OptionHandlers, 19

FormatFrameLabelEastRotated, 18

OptionsToHandle, 20

FormatFrameLabelNorth, 18
FormatFrameLabelSouth, 18

PatchType1FontIntoEps, 25

FormatFrameLabelWest, 18

PostMathPSfrag, 11

FormatFrameLabelWestRotated, 18

PreviewDevice, 24

FormatFrameTicksEast, 18

PSfrag, 8, 20

FormatFrameTicksNorth, 18

PSfragExport, 7, 21

FormatFrameTicksSouth, 18

PSfragManualExport, 22

FormatFrameTicksWest, 18

PSfragPrologue, 17

FormatPlotLabel, 18

PSfragTag, 20

FormatTicksX, 18

PSfragTicks, 22

FormatTicksY, 18

PSPosition, 20

FractionalPartDigits, 25

PSRotation, 20
PSScaling, 21

GenerateTemporaryName, 18
GhostscriptExecutable, 23

RationalToReal, 25

GuessTag, 18

RemoveTemporaries, 24

GuessTeX, 18

RenumberTags, 17
ReplacementHookCooperative, 18

HandleAutomaticPSfrag, 19

ReplacementHookExclusive, 19

HandleAxesLabel, 19
HandleFrameLabel, 19
HandleFrameTicks, 19
HandlePlotLabel, 19
HandleTicks, 19
IncludeGraphicsOptions, 24

SuppressOutput, 24
TemporaryDirectory, 25
TeXCommand, 21
TeXPosition, 21
TeXPreamble, 25

35

TeXShift, 21
TeXShiftX, 21
TeXShiftY, 21
TeXSux, 22
TextToPSfrag, 22
UnPSfrag, 10, 22
UnPSfragOutputFormats, 25

36



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.4
Linearized                      : No
Page Count                      : 36
Page Mode                       : UseOutlines
Author                          : 
Title                           : 
Subject                         : 
Creator                         : LaTeX with hyperref package
Producer                        : pdfTeX-1.40.3
Create Date                     : 2007:11:20 18:14:45+01:00
Modify Date                     : 2007:11:20 18:14:45+01:00
Trapped                         : False
PTEX Fullbanner                 : This is pdfTeX using libpoppler, Version 3.141592-1.40.3-2.2 (Web2C 7.5.6) kpathsea version 3.5.6
EXIF Metadata provided by EXIF.tools

Navigation menu