# Thoughts, etc.Results of a non-deterministic process

10Nov/110

## Separating figures from a LaTeX document

Once again, I've run into something that shouldn't be an issue with a submission to PRA, but which nevertheless is. I generated some plots in Mathematica, but decided to label them with LaTeX. I thought this would be standard, given that it allows for a consistent font throughout the document, but the editors have said that using "commands in the manuscript source file to include axis labeling or other such content to your figures is a problem for us". Whatever the reasons for this, you can't argue with it if you want your manuscript published.

So, can you quickly extract each figure, complete with added labels, into a set of graphics files to be re-included in place of the original figures? Indeed you can! The first step is to use the preview package:
 \usepackage[active,tightpage]{preview} \PreviewEnvironment{tikzpicture} 

When you compile with this package active, every instance of the PreviewEnvironment will be rendered on its own page, and anything not in that environment will be suppressed. The tightpage option makes each page of the resulting file just big enough to contain the bounding box of its contents.

One warning: LaTeX labels get lost here, since they generally occur outside of the environment being extracted. This is important if you are, for example, placing a sub-figure label on the image. The first time you compile with preview active everything will look all right because the aux files will still remember the labels from the previous compile. If you start noticing ??' where you expect (a)', just deactivate the preview package, recompile until things look right, then reactivate it.

The next step is to split the resulting file into a sequence of files, one per page in the original. My first attempt was to split either the postscript or PDF file using a command like
 (Not the solution) pdf2ps allfigs.pdf fig%02d.ps 
to split allfigs.ps into fig01.ps, fig02.ps, .... Unfortunately, this rasterizes the text, without even antialiasing it, and the result just doesn't look quite right. I was hoping to simply switch to pdf2eps or pdf2pdf for better luck, but at least on my Mac OS X machine these don't exist.

Instead, I found a page detailing a quick solution using Automator that spits out each page of a PDF into its own new PDF. The final step was simply to replace all of my lovely TikZ code with simple \includegraphics commands.

UPDATE: It turns out that the Automator solution trims the images a little too closely, and parts of the output PDFs are missing around the edges. I tried several other scripts and online PDF splitters, but ran into one of two problems with each. Either (a) the "split" PDFs contained only the first page, regardless of the output range asked for, or (b) the resulting PDFs were ever so slightly cropped, as with the Automator script. Finally I downloaded a program, PDFsam (PDF split and merge) which did the trick.

Finally, it turns out that I had to convert each of the individual PDF files to EPS format for submission to PRA. I accomplished this quickly and easily with a nice little script that runs Ghostscript.

14Sep/100

## Passing multiple arguments from a List in Mathematica

In Mathematica a List, L, can be turned into a Sequence with the command Sequence@@L. This allows, for example, the logical-AND of the elements of L to be computed via

And[Evaluate[Sequence@@L]]

If L={x,y,z}, this results in the evaluation of And[x,y,z], instead of And[{x,y,z}], which is what And[L] produces.

27Aug/100

## Odd LaTeX error in Phys. Rev. A submission

So I'm in the process of getting an article published in PRA.  I first submitted it in mid-June, and got the referee's response the day before I left for a two-week holiday!  I thought my mad scramble to address the comments and resubmit before leaving for the airport was successful, but while waiting in the boarding area I received an email entitled "URGENT <reference id>" from the editors.  Apparently they were unable to compile my document from its LaTeX source code, and needed me to debug the problem and re-submit.  Unfortunately, it compiled without any errors on my system.  It did generate some warnings on their system when I uploaded it, but no actual errors.  I figured this might make it tricky to debug.  If you've seen TeX output you can imagine just how long the list of errors I had to deal with was, but the first relevant section turned out to be:

! Use of \caption@@settype doesn't match its definition.
\new@ifnextchar ...served@d = #1\def \reserved@a {
#2}\def \reserved@b {#3}\f...

For reasons I still don't understand, the problem was in using the \subref command within the \caption command of a figure. In each case, the caption was that of the figure containing the subfigure being referenced; I don't know if this caused the problem, or if it still wouldn't have worked referencing the subfigures from another figure's caption.

Whatever inner workings of TeX resulted in this combination's causing a problem, the solution was straightforward.  Thanks to a post on miscellaneous.debris, I found that simply adding \protect before each \subref made the problem go away.