# Standalone: class vs package

What is the difference between the standalone class vs the package? From what I understand, the usage is different by \documentclass{report} or \usepackage{standalone} respectively. Is the class for the sub files and the package is for the main file?

I have a subfile:

\documentclass{report}
\usepackage[numbers]{natbib}

\begin{document}

dummyref \cite{GSMAIntelligence2016}
\bibliographystyle{unsrtnat}
\bibliography{ref}

\end{document}


This compiles fine with the pdflatex + bibtex + pdflatex (x2) command however if I change it to documentclass{standalone} and run the same command I get the following errors:

! LaTeX Error: Something's wrong--perhaps a missing \item.
! LaTeX Error: Something's wrong--perhaps a missing \item.
! Missing \endgroup inserted.
! Missing } inserted.
! LaTeX Error: \begin{document} ended by \end{thebibliography}.
! Extra \endgroup.
! Too many }'s.

• When you use the class you need to pass options that allow multiple paragraphs and/or multiple pages. Since the crop option is enabled by default, and crop assumes you have only one paragraph, you must add the varwidth=true option to allow multiple paragraphs with crop. – Alan Munn Jan 13 '16 at 16:28
• Thank you! That seems to have fixed it. I am now able to compile both the subfile and the main file. I notice that after I change the document class from report to standalone, when the subfile is compiled individually, the text fills the whole page however when it is compiled as part of the main file (which has document class report), it looks fine (with margins, etc). Do you know how to fix this? – WWLK Jan 13 '16 at 16:37
• @WWLK The class is for typesetting content singularly. The canvas is not a fixed paper size (A4, A3, etc), rather it adapts to the content inside. That's why it "fills" the whole page. – Alenanno Jan 13 '16 at 16:44
• @Alenanno I see, thanks for the information. FYI, I have added [class=report, crop=false] which seems to have the desired effect. – WWLK Jan 13 '16 at 16:48

The standalone class is designed to create individual snippets of content whose size adapts to the content itself. This is implemented with the [crop=true] option, which is enabled by default. The [crop=true] option assumes that the content is a single paragraph. This is the source of the error you see when you compile your sample document with the standalone class.

There are two ways to solve this problem, with different effects:

1. Use option [varwidth=true] which will allow multiple paragraphs, but will still crop the image to the size of its content.

2. Use option [crop=false], which will not crop the document to the size of the content, and instead render it as a single page.

The class also allows you to specify an alternative class to compile the document in "within" the standalone compilation. The default us the article class. Changing this to the report class as you mentioned in the comments isn't actually doing any work here; it's only the crop=false option that is making the content fill a page.

### Difference between the class and the package

The standalone class is useful especially if you are generating images for inclusion into other documents, especially because it can also do automatic conversion to other image formats.

On the other hand, the usefulness of the package version of standalone is less clear to me. In its most basic use, the standalone package allows you to use \input in a main document to insert standalone class documents into a larger document. I don't have a concrete use case for this, and I can't see an obvious use for it. Perhaps others who use it in this mode can comment on how they actually use it.

• That makes sense, thank you. Are you able to give more information regarding when I should use the standalone class and when I should use the standalone package? – WWLK Jan 14 '16 at 11:03
• I have a perfect example, I think. I produce long A-level mathematics questions that often include graphics. I use the standalone class to create them and put them into a folder of questions (over 1000 so far). Producing a question this way means that I can make one and see the result immediately. After saving it I can make a worksheet later using the standalone package and so include a number of questions without bothering to change the original file. An added bonus is that I can distribute the cropped PDFs to my less enlightened colleagues to include in their Word documents (ugh!). – Nickolas Jun 5 '16 at 14:36
• @Nickolas Thanks for this comment. It's exactly the kind of real world experience that I was lacking on using the package version. – Alan Munn Jun 5 '16 at 14:48