## LaTeX surprises

When compiling the solution manual to “Introducing Monte Carlo Methods with R” into a version with only the odd-numbered exercises, I used a \relax{…} command to comment out the even-numbered solutions. This produced a strange bug when applied to a paragraph that included the lines

\begin{verbatim}
> system.time({for (t in 1:100) y=rmnorm(n=1,var=Sigma)})
user  system elapsed
0.028   0.000   0.028
\end{verbatim}

as somehow the curly bracket } in the group of commands was understood as the end of the \relax command. It took me a while to spot the reason for this bug as I implicitely assumed that anything within the verbatim environment was not understood as a LaTeX command. But the bug was also helpful in pointing out an extra curly bracket } in an R code provided as a solution (within the verbatim environment). While switching between the long and the short versions of the solution manual to “Introducing Monte Carlo Methods with R”, I also found a point I had been seeking for a while, namely that

\begin{comment}
\subsection{Exercise \ref{exo:helpme}}
Test the \verb+help+ command on the functions \verb+seq+,
\verb+sample+, and \verb+order+.
\end{comment}

works out nicely to comment out whole paragraphs once the verbatim package is included. However, if I try to shorten the syntax by defining

\newcommand\become{\begin{comment}}
\newcommand\begone{\end{comment}}

I get a compilation error

Runaway argument?!
File ended while scanning use of \next.
<inserted text>
\par

Strange, isn’t it?!

### One Response to “LaTeX surprises”

1. Notice: you need the verbatim package to use the comment environment.