StartLaTeX faqLaTeX for Beginners F.A.Q.LaTeX topicsLaTeX courseSearch

In LaTeX, displaying LaTeX commands as plain text within a LaTeX document isn't straightforward because LaTeX interprets and executes these commands. However, there are ways to achieve this using the verb and verbatim environments.

verb Environment

Individual lines can be displayed using the \verb command. For example:

\verb+\documentclass{article}+

It's important to note that the character immediately following \verb should not appear within the code being displayed. For instance, \verb+$sin(x)+cos(x)=1$+ won't work! Similarly, \verb*\documentclass{article}* won't work either, as the * character is used to emphasize spaces between terms in the source code.

verb and Spaces

Input: \verb*|$sin(x) + cos(x) = 1$| Output:

Verbatim Environment

Everything within the verbatim environment is output as plain text.

\begin{verbatim}
This is a test
\end{verbatim}

verbatim*

Similar to the verbatim environment, but spaces are emphasized here as well.

\begin{verbatim*}
This is a test
\end{verbatim*}

In summary, the verb environment is used for displaying short code snippets within text, while the verbatim environment is employed for displaying longer blocks of code. The * variant of both environments emphasizes spaces within the displayed text.

Contact   Privacy Policy   disclosures

accept decline

This website uses cookies and pixel tags to ensure you get the best experience on our website. By using this website, you consent to the use of cookies.learn more about cookies see also our privacy policy