[Tex/LaTex] LaTeX Source Code Listing

listings

I want a code listing, but the code I'm listing is LaTeX. When I simply use:

\usepackage{listings}
...
\begin{lstlisting}
...LaTeX document goes here...
\end{lstlisting}

The listing looks like this:

screenshot of listing generated by above code

I want it to look a little more professional than this. Can anyone help me out?

Best Answer

Use \lstset to customize your listings; select the specific language and a nice monospaced font; for example:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{bera}
\usepackage{listings}

\lstset{%
  basicstyle=\small\ttfamily,
  language=[LaTeX]{TeX}
}

\begin{document}

\begin{lstlisting}
\documentclass{article}
\usepackage{listings}

\begin{document}
Hello world!
\end{document}
\end{lstlisting}

\end{document}

enter image description here