# Why does Listings package not display anything in draft mode? [closed]

I'm writing a C++ course for secondary students and wanted to display some source code in a nice way (indenting, eventually coloration) and tried the Listings package. But I have a problem, the file compile with no problem and then, when I look at the place where my code is supposed to appear, it is empty. Neither code or spaces. Why? I am not really a LaTex expert, I just wrote my thesis with it (no source code in it), so maybe it is something very simple I missed... Working on a mac with texmaker in utf8.

The minimum (non-)working example is:

\documentclass[draft]{article}

\usepackage{listings}
\lstset{language=C++}

\begin{document}
\section{Inline listings are shown}
\lstinline!void main() {return 0}!

\section{Environment listings are blank}
\begin{lstlisting}
void main() { return 0; }
\end{lstlisting}

\section{Included file listings are blank}
\end{document}


This hides listings in lstlisting environments and files included with \lstinputlisting as can bee seen in this output:

## closed as unclear what you're asking by jub0bs, Martin Schröder, mafp, Speravir, ChrisSJan 16 '14 at 0:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Seems like listings package doesn't play well with draft option in the document class. The listings manual suggests passing the final option to the package in chapter 2.2 Package loading. This solution works for me:

\documentclass[11pt,a4paper,draft]{article}
...
\usepackage[final]{listings}
...


That way I've got both black marks on overfull lines and listings. The same trick works with graphicx package.

• Works very well :) – 7heViking Nov 25 '14 at 9:53

listings.sty can not handle utf8-characters. If this is your problem use listingsutf8 or alternetively package minted. If this is not an answer to your problem, then as usual: provide a small minimal example ...

• Thank you very much! That was the problem... I always get problems when I want to use utf8... I will stick to latin1 now :) – Lucas Jan 20 '11 at 15:28
• Oops. I answered too early... In fact it does work with the snippet, but not with the code section or inclusion... – Lucas Jan 20 '11 at 17:24
• \documentclass[11pt,a4paper,draft]{article} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{array} \usepackage{listings} \begin{document} \section{Snippet} \lstset{language=C++} \lstinline!void main() {return 0}! \section{section} \lstset{language=C++} \begin{lstlisting}[frame=single] void main() { return 0; } \end{lstlisting} \section{include} \lstinputlisting{ex_comments.cpp} \end{document} – Lucas Jan 20 '11 at 17:30
• @Lucas: do not use the option draft in the documentclass – user2478 Jan 20 '11 at 20:18
• Ohhh... This time it works perfectly! That happens when you try to use commands you don't know, supposing which is the effect... Anyway, thank you very much! Lucas – Lucas Jan 22 '11 at 8:03