56

I am using Texmaker and MiKTeX on Windows 7. I have the following beamer code,

\documentclass{beamer}
\theme{AnnArbor}
\begin{document}
\begin{frame}
\begin{verbatim}

   \begin{frame}[<alignment>]
   \frametitle{Frame Title Goes Here}
   Frame body text and/or LATEX code
   \end{frame}

\end{verbatim}
\end{frame}
\end{document}

I was expecting the following output,

       \begin{frame}[<alignment>]
       \frametitle{Frame Title Goes Here}
       Frame body text and/or LATEX code
       \end{frame}

But instead I got the following Error Message,

File ended while scanning use of \@xverbatim.

Can any one please point out the error here. As far as I know verbatim can have anything inside it.

Also when I tried the following code,

\begin{verbatim}
 \ begin{frame}[<alignment>]
 \frametitle{Frame Title Goes Here}
 Frame body text and/or LATEX code
 \ end{frame}
\end{verbatim}

I got the following output,

    \ begin{frame}[<alignment>]
     \frametitle{Frame Title Goes Here}
     Frame body text and/or LATEX code
    \ end{frame}

But I don't want space between \ and begin and \ and end.

1

3 Answers 3

79

Your frame should be fragile. (One additional line commented for better effect).

\documentclass{beamer}
%\theme{AnnArbor}

\begin{document}
%\begin{frame}
\begin{frame}[fragile]
\begin{verbatim}

   \begin{frame}[<alignment>]
   \frametitle{Frame Title Goes Here}
   Frame body text and/or LATEX code
   \end{frame}

\end{verbatim}
\end{frame}
\end{document}

enter image description here

3
  • 6
    This worked for me. Can someone explain why this works?
    – cgogolin
    Commented Apr 5, 2016 at 16:52
  • For me too, Fragile worked!! Commented Apr 19, 2018 at 10:47
  • 2
    This does not work for me. Even after marking the fram fragile, I cannot put \end{verbatim} on a newline after \end{frame} in this example or it gives the same error. I am forced to put \end{verbatim} on the same line, which then messes up syntax highlighting for the remainder of my file.
    – user12413
    Commented Dec 7, 2018 at 20:42
4

Using fragile does not work for me when changing the mode as when generating slides and handouts from separate driver files calling the same content file so I came up with an ugly but effective work around. Let me give an example expanding on the one given above.

The driver file to create slides is called contentfile.beamer and has the following:

\documentclass{beamer}
\input{contentfile}

A driver file for the handouts is called contentfile.article and has the following:

\documentclass{article}
\usepackage{beamerarticle, pgfpages}
\setjobnamebeamerversion{contentfile.beamer}
\input{contentfile}

The file named contentfile has the actual content of the slides and the comments:

\begin{document}

As seen in Figure~\ref{fig:slideWithVerbatim}
the small slide image appears on the article version only and
is ignored when compiled as a beamer document.
That is what makes it a handout.
By contrast this text is ignored when the document is
build with the beamer class.

\begin{figure}
\framebox{\includeslide[width=0.9\textwidth]{frameVerb}}
\label{fig:slideWithVerbatim}
\end{figure}

\mode<beamer>{
\begin{frame}[fragile]
  \label{frameVerb} % this is the hook for the handout
  \begin{verbatim}

    \begin{frame}[<alignment>]
    \frametitle{Frame Title Goes Here}
    Frame body text and/or LATEX code
    \end{frame}

  \end{verbatim}
\end{frame}
}
\end{document}

The workflow is to run pdfLaTeX on the contentfile.beamer first to generate the slides and then run it on contentfile.article to generate the handout.

This had worked wonderfully for me until trying to use verbatim inside a frame environment. The only work around so far has been:

  1. Comment out the lines with \mode<beamer>{ and the final } around the frame environment with the problematic verbatim text in the contentfile file.

  2. Run pdfLaTeX on the contentfile.beamer file to generate the slides.

  3. Uncomment the lines from step 1, this will enable the directive that isolates this code from the article mode.

  4. Save the contentfile file and run pdfLaTeX on the contentfile.article file. This generates the handout version with the correct slides and avoids the collision with verbatim.

Awkward but it does work. I will be thankful to anyone sharing a more elegant and practical solution.

Output generated with above code and work flow

2

I am posting it too late. But one easy solution is "Don't use frame at all".. Latex will automatically assign a frame.

\begin{document}
\begin{verbatim}

   \begin{frame}[<alignment>]
   \frametitle{Frame Title Goes Here}
   Frame body text and/or LATEX code
   \end{frame}

\end{verbatim}
\end{document}

It will automatically assign a frame to the content and will not show any error.

1
  • 1
    Welcome to TeX.SX! I think that the point is that the OP was trying to show in a beamer talk how to use frames and so needed a frame displayed inside a frame, so your solution might compile but it doesn't help.
    – user30471
    Commented Jun 19, 2015 at 7:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .