Archive for verbatim

a weird beamer feature…

Posted in Books, Kids, Linux, R, Statistics, University life with tags , , , , , , , , , , , , on September 24, 2014 by xi'an

As I was preparing my slides for my third year undergraduate stat course, I got a weird error that got a search on the Web to unravel:

! Extra }, or forgotten \endgroup.
\endframe ->\egroup
  \begingroup \def \@currenvir {frame}
l.23 \end{frame}

which was related with a fragile environment

\frametitle{simulation in practice}
\item For a given distribution $F$, call the corresponding 
pseudo-random generator in an arbitrary computer language
> x=rnorm(10)
> x
 [1] -0.021573 -1.134735  1.359812 -0.887579
 [7] -0.749418  0.506298  0.835791  0.472144
\item use the sample as a statistician would
> mean(x)
[1] 0.004892123
> var(x)
[1] 0.8034657
to approximate quantities related with $F$

but not directly the verbatim part: the reason for the bug was that the \end{frame} command did not have a line by itself! Which is one rare occurrence where the carriage return has an impact in LaTeX, as far as I know… (The same bug appears when there is an indentation at the beginning of the line. Weird!) [Another annoying feature is wordpress turning > into > in the sourcecode environment...]

\verbatim [beamer package]

Posted in R, Statistics, University life with tags , , , , , , on June 12, 2012 by xi'an

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:

\slidetitle{A family meeting}
\begin{block}{Random switch of couples}
\item Pick two couples [among the 20 couples] at random with probabilities proportional
to the number of other couples they have not seen\\
\item switch their respective position during one of the 6 courses
\item accept the switch with Metropolis--Hsatings probability\\
for (t in 1:N){
  if (log(runif(1))<(penat-penatp)/gamma){

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.12 }

Using two frames in a row instead of the “only<2>” version  did not help…
Continue reading

what’s wrong with package comment?!

Posted in Books, R, Statistics, University life with tags , , , , on May 4, 2012 by xi'an

I spent most of the Sunday afternoon trying to understand why defining


did not have the same effect as writing the line


until I found there is a clash due to the comment package… The assuredly simple code


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


produces an error message:

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

This 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…)

LaTeX surprises

Posted in Books, University life with tags , , , , , on January 18, 2010 by xi'an

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

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

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

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

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


I get a compilation error

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

Strange, isn’t it?!

Verbatim code

Posted in Books, Linux with tags , , , , , on October 27, 2009 by xi'an

When rendering computer code and output in LateX, I usually resort to the basic verbatim environment, as in

> matrix(1:4,ncol=3)
[,1] [,2] [,3]
[1,]    1    3    1
[2,]    2    4    2
Warning message:
data length [4] is not a submultiple or multiple of the number of columns [3] in matrix in: matrix(1:4, ncol = 3)

However, I do not like the way tildes are represented in this environment, being considered as accents rather than standard characters, as in the R command


Asking Springer-Verlag TeXperts for help during my last round of corrections of Introducing Monte Carlo Methods with R before it left for the printer, I received a solution which is to use the alltt environment instead, which allows for LaTeX commands within the verbatim rendering, using \(\sim\) instead of ~. (I have been looking for this solution for ages and of course, provided with the solution of using alltt instead, I immediately found a lot of related posts!) There is a drag, though, which is that curly brackets {} vanish from the R code, unless replaced with the LaTeX versions \(\{\) and \(\}\).

When ~is used in the in-line rendering


alltt does not work but a simple


is sufficient.


Get every new post delivered to your Inbox.

Join 653 other followers