2

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?

  • 2
    Welkom bij TeX.SE! Could you please provide a minimal compilable document (with just one chapter, no content except for the environment) that shows the error? That makes it easier for the community to reproduce and possibly solve the problem. – Marijn Oct 04 '18 at 09:22
  • 1
    You should use \makeatletter before \newenvironment and \makeatother at the end of the definition, because it uses \@nameuse. – egreg Oct 04 '18 at 10:20
  • Thank you for taking the time to edit your question so that the example becomes usable. Even after the edit, however, egreg's comment and the duplicated question/answer is relevant and solves the problem, so I did not yet vote to reopen your question. Did egreg's comment and the linked question help or did you have problems applying the suggestions? – moewe Oct 04 '18 at 11:51
  • Yes it did. Although I really don't know how I should have found the answer where @egreg refered to. Anyway, your help is very appreciated :). – Achilleshiel Oct 04 '18 at 12:28
  • 1
    @Achilleshiel Long time users are acquainted with such kind of problems, so it was easy to recall the right duplicate. Don't worry: your question, after the edit, was a good one. – egreg Oct 04 '18 at 12:39
  • Exactly, even before the edit the question was OK and after the edit it was really good. There is no shame in having the question closed as a duplicate. It just saves having to re-type the same answer over and over again and makes sure that answers to the same thing can be found at one central place instead of many different questions. And of course it is much, much easier to find the duplicate if you know the answer to the problem and have a bit of experience navigating this site as egreg undoubtedly has. – moewe Oct 04 '18 at 15:50

0 Answers0