Once again working on my slides for the AMSI Lecture 2012 tour, it took me a while to get the following LaTeX code (about the family reunion puzzle) to work:
\begin{frame}[fragile,label=notleM2]
\slidetitle{A family meeting}
\begin{block}{Random switch of couples}
\only<1>{
\begin{itemize}
\item Pick two couples [among the 20 couples] at random with probabilities proportional
to the number of other couples they have not seen\\
{\verb+prob=apply(meet(T)==0,1,sum)+}
\item switch their respective position during one of the 6 courses
\item accept the switch with Metropolis--Hsatings probability\\
{\verb#log(runif(1))<(penalty(old)-penalty(new))/gamma#}
\end{itemize}
}
\only<2>{
\begin{verbatim}
for (t in 1:N){
prop=sample(1:20,2,prob=apply(meet(T)==0,1,sum))
cour=sample(1:6,1)
Tp=T
Tp[prop[1],cour]=T[prop[2],cour]
Tp[prop[2],cour]=T[prop[1],cour]
penatp=penalty(meet(Tp))
if (log(runif(1))<(penat-penatp)/gamma){
T=Tp
penat=penatp}
}
\end{verbatim}
}
\end{block}
\end{frame}
since I was getting error messages of the form
[86] (./simulation.38.vrb) [87] (./simulation.39.vrb
!Illegal parameter number in definition of \beamer@doifinframe.
l
l.12 }
?
Using two frames in a row instead of the “only<2>” version did not help…
Read more »
what’s wrong with package comment?!
Posted in Books, R, Statistics, University life with tags comment package, Introducing Monte Carlo Methods with R, LaTeX, R, verbatim on May 4, 2012 by xi'anI spent most of the Sunday afternoon trying to understand why defining
\newcommand{\era}{\end{comment}}did not have the same effect as writing the line
\end{comment}until I found there is a clash due to the comment package… The assuredly simple code
\documentclass{book} \usepackage{comment} \begin{document} \begin{comment} prompt, you could embark on an on-line visit of the main features of {\tt R} by typing \verb+demo()+ after the prompt (make sure to test \verb+demo(image)+ and \verb+demo(graphics)+ to get an idea of the \era Self-explanatory. \end{document}produces an error message:
Runaway argument? ! File ended while scanning use of \next. <inserted text> \par <*> moretest.texThis is quite an inconvenience as I need to compile my solution manual for “Introducing Monte Carlo Methods with R” with the even-numbered exercises commented out or not depending on the version… (Leaving this package out and using the comment command within the verbatim package does not work either because era does not seem to be recognised as the end of a commented part…)
Share:
5 Comments »