Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 17 down vote accepted

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

share|improve this answer
    
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.

Output generated with above code and work flow

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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