# Adding C++ code snippets in LaTeX using “listings”

We will always have to use code snippets in LaTeX.  The method I use to implement this is using the package listings.

\usepackage{listings}

and later

\lstset{language=C++,basicstyle=\footnotesize}
\begin{lstlisting}{caption=Test}
{
// and data formats.   As you may have other user-defined setup
// in your rootlogon.C, the CMS setup is executed only if the CMS
// environment is set up.
//
TString cmsswbase = getenv("CMSSW_BASE");
if (cmsswbase.Length() > 0) {
//
// The CMSSW environment is defined (this is true even for FW Lite)
// so set up the rest.
//
\end{lstlisting}