# \includestandalone cannot compile \section or \subsection commands

Main.tex

\documentclass{scrartcl}

\usepackage{standalone}

\begin{document}
\section{A}

\includestandalone{Subfile}
\end{document}


Subfile.tex

\documentclass[crop=false,float=true,class=scrartcl]{standalone}

\usepackage{standalone}

\begin{document}
\textbf{b}
\subsection{B}
\end{document}


Results

• Subfile.tex runs fine.
• Main.tex can find Subfile.tex
• Main.tex errors at first use of \section or \subsection.
• If \input is instead used, Main.tex works fine.
• Tested with shell escape, to no avail.

Shell Escape

Used arara for shell escape attempts:

%  arara: lmkclean
%  arara: pdflatex: {   draft: yes, shell: yes }
%  arara: pdflatex: { synctex: yes, shell: yes }
%  arara: lmkclean
\documentclass[crop=false,float=true,class=scrartcl]{standalone}


(./Subfile.tex

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

l.11 \subsection{B}

• Thanks. Turns out, it's not so hard to make a MWE... – kando Jun 17 '15 at 19:36
• If tried a lot of options and combinations, at the moment I would say it's a bug, but perhaps there is a 'weird' trick unknown to me. – user31729 Jun 17 '15 at 20:43
• The error message is missing a right parenthesis " ) ". I wonder if that is related. Overall, I think that this is a package bug as well. – kando Jun 17 '15 at 21:01
• You should write a mail to Martin Scharrer, the package author (he is also one of our moderators). Perhaps he has some clue for this – user31729 Jun 17 '15 at 22:27
• Hi, I will have a look at it and will try to make it work, but note that standalone was not written with section in mind but for diagrams and similar boxed content, so I would call it a limitation not a bug ;-) – Martin Scharrer Jun 18 '15 at 16:57

The error happens because the subfile content is boxed and this causes issues with the sectioning commands. If you change \includestandalone{Subfile} with \mbox{\input{Subfile}} the same error occurs.
As \includestandalone is intended for stand-alone diagrams it boxes the content. Actually it adds an .tex-Driver to \includegraphics so that it can add TeX code as a 'graphic' as well. This adds the box.
There is not really a way around it. I recommend to use \input or \include instead. With the later you can use partial compiling using \includeonly{..} in the preamble.