4

While I was reading a thread on LaTeX workflows, I came across a comment in https://tex.stackexchange.com/a/22433/32782 which seemed to indicate that there are more than one person who can/could use the standalone package for book chapters. Usually people would use \includeonly rather than the standalone package for dividing a document into different tex files and activating just one tex file, but the idea of using standalone intrigued me and I thought I should give it a try, starting with an article with sections first, but my example doesn't seem to work. Here is my example:

The main tex file, flying-animals.tex:

\documentclass{article}
\usepackage{standalone}
\begin{document}
\input{dragons}
\input{birds}
\input{superman}
\end{document}

And a tex file for one section, dragons.tex:

\documentclass{standalone}
\begin{document}
\section{Theories of dragons}
Being dragons.
\subsection{Theory of angry dragons}
Being angry dragons.
\subsection{Theory of tiny dragons}
Being tiny dragons.
\end{document}

When I compile dragons.tex, I get the following error.

LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3 \section
            {Theories of dragons}

Is it possible to make standalone work with sections?

2
  • 3
    this is not going to work with standalone.cls. if you want to use \section in your input, you need to have a document class or .sty file that defines it, and standalone doesn't. Commented Dec 26, 2013 at 20:55
  • as in the comments to your linked question, I'd use include and includeonly
    – cmhughes
    Commented Dec 27, 2013 at 9:17

1 Answer 1

5

Add varwidth as an option to the class in dragons.tex and this works fine. Note that if you compile dragons.tex you will get a single, long page, so this is far from ideal. standalone is mainly intended for graphics created by e.g. TikZ or PSTricks.

\documentclass[12pt]{article}
\usepackage{standalone}
\usepackage{lipsum}

\usepackage{filecontents}
% writes the following to dragons.tex
\begin{filecontents*}{dragons.tex} 
    \documentclass[varwidth]{standalone}
    \usepackage{lipsum}
    \begin{document}
    \section{Theories of dragons}
    Being dragons.
    \lipsum
    \subsection{Theory of angry dragons}
    Being angry dragons.
    \lipsum
    \subsection{Theory of tiny dragons}
    Being tiny dragons.
    \lipsum
    \end{document}
\end{filecontents*}

\begin{document}
\input{dragons}
\end{document}
2
  • 1
    The googler may prefer to use crop=false instead of varwidth.
    – Carel
    Commented Oct 29, 2015 at 19:28
  • +1 for standalone is mainly intended for graphics created by e.g. TikZ or PSTricks. Commented Dec 14, 2019 at 8:54

You must log in to answer this question.

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