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 preparing a presentation in which I want to display the following as it is

\begin{verbatim}
foo
\end{verbatim}

For this I used

\begin{verbatim}
\begin{verbatim}
foo
\end{verbatim}
\end{verbatim}

But the first \end{verbatim} ends the environment and the second induces error. Can anyone suggest how to do this?

I should appreciate the explanation of the trick and commands suggested.

share|improve this question
1  
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  cgnieder May 31 '12 at 10:50
    
Also see tex.stackexchange.com/questions/51031/… –  Will Robertson May 31 '12 at 14:07
add comment

3 Answers

up vote 5 down vote accepted

Try

\usepackage{verbatim}
\verb+\begin{verbatim} foo \end{verbatim}+

or, if you want it on separate lines

\verb+\begin{verbatim}+\\
\verb+foo+\\
\verb+\end{verbatim}+

or, if foo is long,

\verb+\begin{verbatim}+
\begin{verbatim}
foo
\end{verbatim}
\verb+\end{verbatim}+
share|improve this answer
add comment

I don't think that there is any really sensible trick which will work with verbatim directly. I would use another verbatim-like environment from the listings or the fancyvrb package.

share|improve this answer
add comment

You can create a new environment that ensembles the verbatim environment, like:

\documentclass{article}
\usepackage{verbatim}
\newenvironment{realverbatim}{\verbatim}{\endverbatim}

\begin{document}
Test of the new \verb~verbatim~ environment:

\begin{realverbatim}
\begin{verbatim}
foo
\end{verbatim}
\end{realverbatim}

\end{document}
share|improve this answer
add comment

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.