6

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}?

7

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}
|improve this answer|||||
6

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}.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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