# MathPSfrag: Creating Publication-Quality Labels in Mathematica Plots

This article introduces a Mathematica package providing a graphics export function that automatically replaces Mathematica expressions in a graphic by the corresponding LaTeX constructs and positions them correctly. It thus facilitates the creation of publication-quality Enscapulated PostScript (EPS) graphics.

## Authors

• 1 publication
• ### MathPSfrag 2: Convenient LaTeX Labels in Mathematica

This article introduces the next version of MathPSfrag. MathPSfrag is a ...
01/15/2008 ∙ by Johannes Große, et al. ∙ 0

• ### Carnot Efficiency of Publication

This paper analyzes publication efficiency in terms of Hirsch-index or h...
08/27/2017 ∙ by Abhisek Ukil, et al. ∙ 0

• ### Mislabel Detection of Finnish Publication Ranks

The paper proposes to analyze a data set of Finnish ranks of academic pu...
12/19/2019 ∙ by Anton Akusok, et al. ∙ 0

• ### Predicting publication productivity for researchers: A latent variable model

This study provided a model for the publication dynamics of researchers,...
10/06/2019 ∙ by Zheng Xie, et al. ∙ 0

• ### A Robust Bayesian Copas Selection Model for Quantifying and Correcting Publication Bias

The validity of conclusions from meta-analysis is potentially threatened...
05/06/2020 ∙ by Ray Bai, et al. ∙ 0

• ### Stylised Choropleth Maps for New Zealand Regions and District Health Boards

New Zealand has two top-level sets of administrative divisions: the Dist...
12/10/2019 ∙ by Thomas Lumley, et al. ∙ 0

• ### Calendar-based graphics for visualizing people's daily schedules

Calendars are broadly used in society to display temporal information, a...
10/23/2018 ∙ by Earo Wang, et al. ∙ 0

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## Introduction

Many programs producing EPS graphics do not allow the inclusion of LaTeX commands. While there exist several solutions (see for example McKay and Moore (1999)) to work around these difficulties, they all have various drawbacks. In this article, we will focus on a particular existing solution, the PSfrag package Grant and Carlisle , which provides LaTeX macros allowing to replace pieces of text (“tags”) in an EPS file by an arbitrary LaTeX construct.

However, for PSfrag to work, the application must write tags unaltered into the EPS file. For Mathematica Wolfram (1999); Wolfram Research, Inc. (2005), 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 unconveniently labelled 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 files requiring the inclusion of additional fonts into the document, a process often not being under the author’s control. A way out is to include the font into the EPS file, or set the font family to a standard PostScript one:

Plot[…, TextStyle$$\to$${FontFamily$$\to$$"Times"}] and
Export[…, ConversionOptions$$\to$$
{"IncludeSpecialFonts"$$\to$$True}].


While the slight mismatch between the PostScript font’s appearance, cf. fig. 1(a), and that of LaTeX’s standard font (Computer Modern) may be acceptable in case of ordinary text labels, mathematical expressions like square roots or fractions cannot compete with LaTeX’s typesetting quality in this approach. Consequently, some authors simply restrict labelling of Mathematica plots to a bare minimum.

MathPSfrag Große is a package that conveniently produces publication-quality labels in EPS files generated by Mathematica. MathPSfrag automates many (often all) tedious details related to the use of the standard LaTeX package PSfrag, while still allowing manual fine tuning. As a demonstration of the degree of automation, compare fig. 1(a), which has been generated by using the standard Mathematica command Export, and fig. 1(b), generated by MathPSfrag’s 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 particular,

• in most cases, it is sufficient to simply use the new PSfragExport command,

• including the graphic into the document requires only one additional command.

This article is organized as follows. A short review of PSfrag and a somewhat longer explanation of the semi-automatic features provided by MathPSfrag, are given in the first and second section, respectively. The third part contains several examples whose code as well as that of figures 1(a) and 1(b) is contained in the appendix. Finally, some of MathPSfrag’s internals are discussed.

## I Review of PSfrag

This is intended to be a short introduction into 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 Grant and Carlisle .

PSfrag provides the macro

\psfrag$$\langle$$tag$$\rangle$$[$$[$$posn$$]$$][$$[$$psposn$$]$$][$$[$$scale$$]$$][$$[$$rot$$]$$]$$\langle$$LaTeX$$\rangle$$,

which replaces any occurence of tag in the output of an EPS file by LaTeX. According to Grant and Carlisle , “all \psfrag calls that precede an \includegraphics (or equivalent) in the same or surrounding environments” will affect the output of the included graphics, i.e. \psfrag commands can be defined either locally, to act on stricly one graphic, or globally, thus acting on all graphics in a document.

posn and psposn are optional arguments which allow to set (first) the vertical (top, bottom, Baseline, or center) and (second) the horizontal (left, right, center) alignment of the replacement text by specifying the respective first character of the choices given in parentheses. The arguments refer to the position of the reference point in the respective bounding boxes. The LaTeX construct is placed such that its reference point is at the position of the corresponding PostScript (tag) box’ reference point, cf. fig. 2.

scale and rot permit scaling and rotation of the inserted box, where the rotation is relative to the slope of the PostScript bounding box such that a value of “0” preserves the orientation, see fig. 3. Scaling is best achieved by using LaTeX scaling commands, like \Large, instead of the scale option, since the standard LaTeX fonts consists of bitmaps rendered specifically for the chosen size and do not rescale well. As will be demonstrated in the example section, MathPSfrag provides macro hooks that allow to scale labels retroactively from within the document.

## Ii How to use MathPSfrag

There are only two commands needed to control MathPSfrag’s EPS generation: PSfragExport, which supersedes Mathematica’s Export command, and PSfrag, which allows overriding of the automatics for particular expressions.

The export function

PSfragExport[$$\langle$$basename$$\rangle$$, $$\langle$$graphics$$\rangle$$, $$[$$options$$]$$]

converts graphics, the usual Graphics construct returned by Mathematica commands like Plot, to an EPS file and a LaTeX file containing \psfrag macros.

options can be any combination of the following options, listed with their parenthetic defaults.

• TeXSuffix"string" ("-psfrag.tex")

• EpsSuffix"string" ("-psfrag.eps")

• RenumberTagsboolean (False)

• AutoConvertTextboolean (True)

• AutoPositionboolean (True)

The respective file names of the LaTeX and EPS file are determined by basename to which the value of the options TeXSuffix and EpsSuffix is appended.

The option RenumberTagsTrue will renumber 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, has been used in fig. 4 to achieve a preciser positioning.

Setting AutoConvertTextFalse will restrict conversion of Text directives in graphics into LaTeX commands to those directives having been marked manually. The default behaviour is to wrap the PSfrag command discussed below around all expressions found in graphics.

AutoPositionFalse switches off the mechanism for determining the \psfrag alignment from Mathematica’s internal representation of the graphics. Note that this also implies AutoConvertTextFalse.

Any other options will be passed on to Export or applied to the graphics using a Show commmand, respectively.

For the purpose of manually controlling the output, that means circumventing the automatics, the

PSfrag[$$\langle$$expr$$\rangle$$, $$[$$options$$]$$]

command is available. It can be wrapped around each Mathematica expression expr appearing as text in a graphic, such as the argument of a PlotLabel or AxesLabel option.

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

• TeXCommand"string" (Automatic)

• PSfragTag"string" (Automatic)

• Position"yx" (Automatic)

• PSPosition"yx" (CopyPosition)

• Rotation"number" (0)

• Scaling"number" (Automatic)

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 to apply different options to expressions where the automatic behaviour did not give satisfactory results.

];
PSfragExport["ex_manual", %, AutoConvertText$$\to$$False, AutoPosition$$\to$$False]


### .5 HoldForm plus CustomTicks

Fig. 7 is a plain example demonstrating that HoldForm can be used to fix the shape of an expression while LinTicks from CustomTicks Caprio (2005) can be used to circumvent the usual stripped decimal “1.” and print a much nicer “1.0” instead.

Plot[(3x - 1)^3, {x, -0.5, 2.5}, PlotStyle$$\to$$Hue[0.6],
AxesLabel$$\to$${x, HoldForm[(3x - 1)^3]},
Ticks$$\to$${LinTicks[-0.5, 2.5], LinTicks[-15, 18]}];
PSfragExport["ex_hold", %]