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> 
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:

%JSON listing mode, from
% https://tex.stackexchange.com/questions/83085/how-to-improve-listings-display-of-json-files#83100




The code for the frame in the Beamer file is:

\begin{frame}{Proc4 Messages}
        uid:"Student/User ID",
        timestamp:"Time at which event occurred",
        verb:"Action Keyword",
        object:"Object Keyword",
       \item Application header defines vocabulary used in other
       \item ...
        \item Data field can hold any number/kind of object.

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. – user121799 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

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.