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.

Say I want to make a file which has as text \documentclass{article} I found out I can do it like this:

\documentclass{article}
\begin{document}
  \begin{verbatim}
    \documentclass{article}
  \end{verbatim}
\end{document}

That's fine. But what if I want to have as text \begin{verbatim} and \end{verbatim}?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

You can use the fancyvrb package. This adds some nice features to the verbatim environment. Among other things it defines an environment Verbatim in which you can write \end{verbatim} since it won't match the \begin{Verbatim}.

\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
  \begin{Verbatim}
      \begin{verbatim}      
        text        
      \end{verbatim}
  \end{Verbatim}
\end{document}
share|improve this answer
add comment

Define a new verbatim environment with different delimitation strings:

\documentclass{article}

\usepackage{verbatim}
\newenvironment{xverbatim}{\verbatim}{\endverbatim}

\begin{document}

\begin{verbatim}
\documentclass{article}
\end{verbatim}

\begin{xverbatim}
\begin{verbatim}
\documentclass{article}
\end{verbatim}
\end{xverbatim}

\end{document}

Remember also that verbatim environments respect code indentation, so your code

  \begin{verbatim}
    \documentclass{article}
  \end{verbatim}

will result in four spaces in front of \documentclass{article}.

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.