# Verbatim in beamer showing error: “File ended while scanning use of \@xverbatim.”

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.

-
– moose Aug 20 '14 at 17:14

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}


-
Thank you....... – Deepu Oct 29 '13 at 3:47

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.

-

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.

-
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. – Andrew Jun 19 at 7:55