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

14Aug/120

## Trouble with figure previews in TikZiT

I recently decided to give the open-source TikZiT a try for drawing TikZ-based figures. While the feature set TikZiT can handle is a relatively small subset of TikZ's capabilities, it seems to do what it does quite well. I'm running version 0.8.417 on Mac OS 10.6.8 (Snow Leopard), and have only encountered one significant issue so far. Out of the box, everything seemed to work as advertised except for the previewing function. When I asked for a PDF preview to be generated by pdflatex, I'd receive only the relatively unhelpful error message "AN ERROR HAS OCCURRED, PDFLATEX SAID:"

with no indication of what it may (or may not) have said. I have TeX Live 2011 installed (though I see 2012 was released last month), with pdflatex in my path. I did what I could to debug the problem, but a Google search for the error returned no results and the error itself didn't give much to go on. So, I contacted the developer of TikZiT, Aleks Kissinger, who got back to me with the solution within a few hours.

Apparently TikZiT doesn't necessarily use the actual path variable set in your operating environment, but rather searches the two files ~/.profile and ~/.bashrc to attempt to learn the location of pdflatex for itself. The very simple solution was to create or add to one of these files, with a line similar to

export PATH=/usr/texbin:\$PATH

in order to tell TikZiT to look in /usr/texbin for the pdflatex executable. Once I'd put that command into my newly created ~/.profile, I didn't even have to restart TikZiT to get a preview of my graph.

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.

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.