This example shows how to set the options for automatic syntax highlighting for code in LaTeX with the
listings package (which provides the
lstlisting environment). The listings package supports many languages, including Java, C, C++, MATLAB/Octave and Python, and you can set the language option globally with
\lstset or for each listing, when you have listings in multiple languages.
Our searchable collection of LaTeX examples is a great place to look when you're using a LaTeX package for the first time (or the first time in a while!).
Show off your awesome LaTeX skills by contributing examples to the gallery. You can publish any Overleaf project with a couple of clicks.
New examples of LaTeX packages and techniques are added all the time. Follow us on twitter for the highlights!