I am attempting to put together a paper to submit to APS, for which I am using ReVTeX 4.1. I would like to include figures as separate files via the standalone package, and have the option to build them as pdfs with the same size as seen in the final document.

To do this I tried to use the standalone class with the class option class=revtex4-1 and within the main document use the \includestandalone[mode=buildnew] macro. This fails as pdflatex seems to get stuck in an infinite loop building a larger and larger pdf document of the standalone file.

Here's a MWE. Consider a file main.tex





And a file sketch.tex





And compile via the command

pdflatex --shell-escape main.tex

edit: I upgraded to TeXlive 2016 and now I cannot compile standalone documents with lualatex, it gives the following error in the log file.

! Bad number (18).
\sa@buildgraphic #1->\ifeof 18 
                                \PackageError {standalone}{Shell escape neede...
l.6     \includestandalone[mode=buildnew]{sketch}

Since I expected to read a number between 0 and 15,
I changed this one to zero.

! Package standalone Error: Shell escape needed to create graphic! Use the '-sh
ell-escape' option..

See the standalone package documentation for explanation.
Type  H <return>  for immediate help.

l.6     \includestandalone[mode=buildnew]{sketch}

This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method
  • The lualatex issues seems to be related to tex.stackexchange.com/questions/313284/… Commented Sep 5, 2016 at 12:14
  • 1
    Add \RequirePackage{luatex85} prior to \documentclass to compile a standalone class file with LuaTeX from TL 2016. For portability, wrap it in a conditional check: \IfFileExists{luatex85.sty}{\RequirePackage....
    – cfr
    Commented Dec 4, 2016 at 1:56
  • I still get ! Bad number (18). \sa@buildgraphic #1->\ifeof 18 \PackageError {standalone}{Shell escape neede... Commented Jan 31, 2017 at 13:22
  • Maybe it doesn't like revtex. Can you not specify the class for standalone? Will it make any difference to the graphic?
    – cfr
    Commented Jan 31, 2017 at 17:05
  • I can lualatex a simple revtex document and a revtex document where the standalone documents don't have class=revtex4.1. It seems to be standalone documents with class=revtex4.1 that produces errors. The error will vary by compiler. lualatex gives me the above error (which is related to the changed in TL16), pdflatex and latex will fail to build the standalone components as described in the OP. Commented Feb 1, 2017 at 6:30

1 Answer 1


A workaround was identified by the maintainer of standalone, so I thought I'd copy it over here:

The reftex4-1 class changes the output routine of LaTeX and is not compatible with the default way standalone crops the pages. You can fix this by simply adding the 'preview' option to the \documentclass[..]{standalone} line in the subfiles. This way the cropping is done by the 'preview' package which is compatible with changed output routines.


  • ;-) Just closed that ticket yesterday evening and was surprised finding it here so quickly. Note that I also fixed the LuaTex problems in the developer version, so the next release will work again with it. Commented Dec 7, 2017 at 6:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .