Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to add code listings to LaTeX document using verbatim environment

📅 2012-Dec-15 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ latex, source code, verbatim ⬩ 📚 Archive

Code displayed using verbatim environment
Code displayed using verbatim environment

Source code listings can be displayed in a LaTeX document using the verbatim environment like this:

\begin{verbatim}
int main()
{
    return 0;
}
\end{verbatim}

The text inside the verbatim environment is typeset using typewriter font. Also, all the characters are printed, including whitespace.

Tried with: MikTeX 2.9 and Windows 8 Pro