[Tex/LaTex] End \verbatim command


The verbatim environment is used to display LaTeX commands instead of having them executed.

To display a single command in-line, the \verb|| command can be used.

To display a whole block, we can use \begin{verbatim} to open the environment and \end{verbatim} to close it.

But I've come across \verbatim as well. With that, we can also type \begin{verbatim} and \end{verbatim} having them shown on our document and not initiating and ending their environment. The problem is, I still haven't found how to terminate it.

I know there are better ways, and maybe \verbatim should be never used at all. But I just wanted to understand how it worked to learn more about LaTeX. After invoking it, how can I return to a normal environment where LaTeX code is compiled, a normal font is used and line breaks are automatic?

Best Answer

verbatim is a very special environment which looks for the exact string \end{verbatim} to end it. Unlike other latex environments you can't use \env ...\endenv instead of \begin{env} ...\end{env} with verbatim.

If you really want to start with \verbatim then you must do something like this to get around the errors due to the various latex settings for environments in general and verbatim specially:




enter image description here

Which shows that it is not a good idea to use \verbatim directly without the help of packages like verbatim.