help for writepsfragRyan E. Kessler (October 2012)

Automates the use of LaTeX's PSfrag package

writepsfrag
filename.eps using filename.tex, [replace append textsize(string) scale(#) body(string [,subopts]) substitute(stringlist)]

Description

writepsfrag writes to a LaTeX file the PSfrag commands necessary to
replace all occurences of text in a Stata Encapsulated PostScript (EPS) file with
properly-formatted LaTeX text.

Options

replace and append are file commands which specify whether the current output will overwrite or be to appended to filename.tex; see file for details.

textsize(string) specifies the LaTeX font size. The 10 acceptable values are as follows: \tiny, \scriptsize, \footnotesize, \small, \normalsize (default), \large, \Large, \LARGE, \huge, and \Huge.

scale(#) specifies the PSfrag scaling factor (default=1) which can be used in conjunction with textsize(string) to address scale/size issues.

substitute(stringlist) applies substitutions where `stringlist' is of the form `from to [from to...]'. Note that substitute($ \$ \dbs \\) is assumed, since neither \$ nor \\ can
be readily displayed in a plot. Accordingly, users should use \( ... \) --- not $ ... $ --- to enter LaTeX's math mode.

body(string [,subopts]) specifies the outmost LaTeX environment into which the resulting PSfrag code is to be placed. It accepts two values, figure and document, both of which allow the following suboptions:

placement(string) specifies the placement argument (default=htbp) of the LaTeX figure environment.

width(#) scales the \linewidth argument in the \includegraphics command (default=1).

caption(string) specifies the figure caption.

label(string) specifies the figure label (for cross-referencing).

packages(string) specifies LaTeX packages to be added to the preamble of
the LaTeX document (body(document) only).

Examples

A simple function:

. #delimit;

. twoway function y=normalden(x), range(-4 4)

> text(0.125 0 "\textbf{\color}")

> text(0.090 0 "\(y=\frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x-\mu)^2}{2\sigma^2}}\)")

> xlabel(-4 "\(-4\sigma\)" -2 "\(-2\sigma\)" 0 "\(\mu\)" 2 "\(2\sigma\)" 4 "\(4\sigma\)")

> xtitle("All text is set in {\LaTeX} font") ytitle("\(y\)");

. graph export normal.eps, as(eps);

. writepsfrag normal.eps using normal.tex;

. #delimit cr

The resulting PSfrag code can be called using LaTeX's \input command:

\begin[htbp]

\centering

\input

\resizebox{1\linewidth}{!}{\includegraphics}

\caption

\end

The same LaTeX code can be generated using the body(figure) option:

. writepsfrag normal.eps using normal.tex, replace body(figure, caption("Normal Probability Density Function"))

Author

Ryan E. Kessler

Research Department

Federal Reserve Bank of Boston

ryan.edmund.kessler@gmail.com

References

Cox, N. J. 2004. Stata tip 6: Inserting awkward characters in the plot. The Stata Journal 4(1): 95-96.

Cox, N. J. 2008. Stata tip 65: Beware the backstabbing backslash. The Stata Journal 8(3): 446-447.

Grant, M. C., and D. Carlisle. 1998. The PSfrag system, version 3. ftp://ctan.tug.org/tex-archive/macros/latex/contrib/psfrag/pfgguide.pdf

Jann, B. 2005. Making regression tables from stored estimates. The Stata Journal 5(3): 288–308.

Jann, B. 2007. Making regression tables simplified. The Stata Journal 7(2): 227–244.