# ReVTeX 4.1 and standalone class

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

\documentclass[aps,prl,10pt]{revtex4-1}
\usepackage[subpreambles=true]{standalone}

\begin{document}

\includestandalone[mode=buildnew]{sketch}

\end{document}


And a file sketch.tex

\documentclass[class=revtex4-1,aps,prl,10pt]{standalone}

\begin{document}

Test

\end{document}


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/… – stephematician Sep 5 '16 at 12:14
• 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 Dec 4 '16 at 1:56
• I still get ! Bad number (18). \sa@buildgraphic #1->\ifeof 18 \PackageError {standalone}{Shell escape neede... – stephematician Jan 31 '17 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 Jan 31 '17 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. – stephematician Feb 1 '17 at 6:30

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