# Is there a way to use todonotes in standalone

Considering the MWE

\documentclass[12pt,crop=false,a4paper,class=book]{standalone}
\usepackage{todonotes}

\begin{document}
\section{test}
\todo{Bug}
\end{document}


During the compilation process the compiler prints:

You can't use \end' in internal vertical mode. \enddocument ... \endgroup \deadcycles \z@ \@@end l.8 \end{document}

Is there a way to make the todonotes save to use in the standalone class?

I would like to have single compilable chapters that I can compile together without changing the preamble everytime. Yet I don't want to loose my handy todonotes.

Well, the problem here is that package todonotes needs some definition made in class article, but theese definitions are not available in class standalone.

An workaround can be the following MWE, that just loads class article, but uses environment standalone inside. Please see that this is documentated in example 3, page 29 in the documentation of package standalone (use texdoc standalone on your terminal/console).

MWE:

\documentclass{article}
\newenvironment{standalone}{\begin{preview}}{\end{preview}}
%\input{standalone.cfg}
% \PassOptionsToPackage{active,tightpage}{preview}
\usepackage{preview}
\usepackage{todonotes}
\begin{document}
\begin{standalone}
\section{test}
text\todo{Bug} text
\end{standalone}
\end{document}


and the result:

• Assuming you meant the \input line to be uncommented, as in the standalone documentation, this doesn't work for me. Compiling gives an Undefined control sequence error on line 12 of standalone.cfg. May 25 '17 at 8:54

It works without further modification if you use the marginnote package:

\documentclass[12pt,crop=false,a4paper,class=book]{standalone}
\usepackage{todonotes}

\usepackage{marginnote}
\let\marginpar\marginnote

\begin{document}
\section{test}
\todo{Bug}
\end{document}
`

Result: