0

This question already has an answer here:

I'm trying to run Beamer to get a listing in a presentation. I'm getting a mysterious error message that looks like:

! Missing number, treated as zero.
<to be read again> 
               \let 
l.221 \end{frame}

? H
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
 look up `weird error' in the index to The TeXbook.)

Part of my problem is that \let is not in my code, this must be the expansion of a macro. My immediate question is "How can I get TeX to give me information about what macros it was expanding when it encountered the error?" That might give me a clue about what to do next.

More context: I'm trying to use an algorithm listing of json objects in Beamer.

I have the following defined in my header:

\usepackage{algorithmicx}
\usepackage{algorithm}
\floatname{algorithm}{Example}
%--------------------------------------------
%JSON listing mode, from
% https://tex.stackexchange.com/questions/83085/how-to-improve-listings-display-of-json-files#83100

\usepackage{listings}
\usepackage{xcolor}

\colorlet{punct}{red!60!black}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{delim}{RGB}{20,105,176}
\colorlet{numb}{magenta!60!black}

\lstdefinelanguage{json}{
  basicstyle=\normalfont\ttfamily,
  numbers=left,
  numberstyle=\scriptsize,
  stepnumber=1,
  numbersep=8pt,
  showstringspaces=false,
  breaklines=true,
  frame=lines,
  backgroundcolor=\color{background},
  literate=
   *{0}{{{\color{numb}0}}}{1}
    {1}{{{\color{numb}1}}}{1}
    {2}{{{\color{numb}2}}}{1}
    {3}{{{\color{numb}3}}}{1}
    {4}{{{\color{numb}4}}}{1}
    {5}{{{\color{numb}5}}}{1}
    {6}{{{\color{numb}6}}}{1}
    {7}{{{\color{numb}7}}}{1}
    {8}{{{\color{numb}8}}}{1}
    {9}{{{\color{numb}9}}}{1}
    {:}{{{\color{punct}{:}}}}{1}
    {,}{{{\color{punct}{,}}}}{1}
    {\{}{{{\color{delim}{\{}}}}{1}
    {\}}{{{\color{delim}{\}}}}}{1}
    {[}{{{\color{delim}{[}}}}{1}
    {]}{{{\color{delim}{]}}}}{1},
}

The code for the frame in the Beamer file is:

\begin{frame}{Proc4 Messages}
  \begin{columns}
    \begin{column}{0.5\textwidth}
      \begin{algorithm}
    \begin{lstlisting}[language=json]
      {
        app:"ecd://coe.fsu.edu/EPLS/AssessmentName",
        uid:"Student/User ID",
        timestamp:"Time at which event occurred",
        verb:"Action Keyword",
        object:"Object Keyword",
        data:{
          field1:"Value",
          field2:["list","of","values"],
          field3:{part1:"complex",part2:"object"}
        }
      }
  \end{lstlisting}
      \end{algorithm}
    \end{column}
    \begin{column}{0.5\textwidth}
      \begin{itemize}
       \item Application header defines vocabulary used in other
          fields.
       \item ...
        \item Data field can hold any number/kind of object.
      \end{itemize}
    \end{column}
  \end{columns}
\end{frame}

The same listing runs fine in another document that uses article rather than beamer style, and the rest of the frame is pretty standard.

marked as duplicate by user36296 beamer Oct 24 '18 at 11:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • In general, an lstlisting should not be placed inside an algorithm if that algorithm is a float, since lstlisting provides its own floating behaviour. – Werner Oct 22 '18 at 23:33
  • 1
    Please provide us with a single document that produces the error. Otherwise there is a danger that additional issues arise from incorrectly patching together these fragments. – marmot Oct 22 '18 at 23:34
  • 1
    \begin{frame}[fragile]\frametitle{Proc4 Messages} is the right way. I can't see the need for the algorithm environment. – egreg Oct 22 '18 at 23:38
  • 1
    Off-topic: you don't need \usepackage{xcolor} with beamer and there is not enough room on a slide to fit in two columns of 0.5\textwidth because there is some space between the columns. Either make your columns a bit smaller or use \begin{columns}[onlytextwidth] – user36296 Oct 22 '18 at 23:40
  • as per your question itself, put \errorcontextlines5 on a line in the preamble. – user4686 Oct 23 '18 at 6:46
0

This turns out to be related to another issue found in https://stackoverflow.com/questions/2981008/latex-issue-with-beamer-and-listings

If I change \begin{frame}{title...} to \begin{frame}[containsverbatim]{title...} it works as expected.

  • 1
    Please don't use containsverbatim: it's only still there for compatibility. You want fragile – Joseph Wright Oct 23 '18 at 6:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.