I am writing a manual and I want to include tips and tricks trough out the chapters. A last chapter will collect all the tips and tricks that I included in the book. So I found the package collect. It does give instruction for a custom environment, so I decided to make a box with that so tips and tricks are clearly seperated from the regular text (using tcolorbox).
I applied the example from the collect package documentation:
\documentclass{book}
\usepackage{collect}
\definecollection{gra}
\newenvironment{grammarpart}[1]{%
\@nameuse{collect*}{gra}{%
\emph{Start of grammar ‘#1’}\par%
}{%
\par\emph{End of grammar}\par%
}{%
\subsection{#1}%
}{%
\par See some section in the text.
}%
}{%
\@nameuse{endcollect*}%
}
\begin{document}
\chapter{Foo}
\begin{grammarpart}
bar
\end{grammarpart}
\end{document}
Typesetting this resulted in the following error, tried this with pdfLaTeX and XeLaTeX:
! You can't use `\spacefactor' in vertical mode.
\@->\spacefactor
\@m {}
l.10 b
ar
?
I also experimented with \grammarpart{test} instead of begin/end arguments. However, that did gave me the same error as well.
I searched on \spacefactor and the use of \@. But to be fair, at that point it became black magic for me. So how do I get this example to work? Or is there a package that allows me to collect environments for a later chapter?
\makeatletterbefore\newenvironmentand\makeatotherat the end of the definition, because it uses\@nameuse. – egreg Oct 04 '18 at 10:20