Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Listings package not correctly showing PHP strings

I'm using listings to include C code, but I've a problem: when I insert in the listing a printf like the following

  printf("inc_count(): thread \%ld, count = \%d  Threshold reached.\n", a,b);

The text inside the " .. " is not shown. I haven't found a way to fix this, I think it should be trivial and maybe I'm just using the wrong keywords... Can you help me?

EDIT: Usage example:

\begin{lstlisting}[language=C, label=cond-var, caption="Condition variables usage example"]
printf("inc_count(): thread \%ld, count = \%d  Threshold reached.\n", 
             my_id, count);
\end{lstlisting}

This is what is shown enter image description here

share|improve this question

marked as duplicate by Caramdir, Martin Scharrer Nov 16 '11 at 7:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
Please add a minimal working example (MWE) that illustrates your problem. Also, you don't need to escape % inside a listing. –  Andrey Vihrov Nov 15 '11 at 10:01
1  
Your example works fine here, the quoted text is printed and everything looks as I would expect it to. Can you add a complete example, also showing the packages you load etc? –  Roelof Spijker Nov 15 '11 at 11:21
1  
Until the MWE arrives, I'm going to guess that '\stringstyle' is set to a white color. –  Mike Renfro Nov 15 '11 at 11:43
    
@MikeRenfro yes, that was the problem, I thought it was something I didn't knew about listings, instead there was a \stringstyle set to white in the preamble of my code. You can add your post as a reply, I will mark it as accepted answer. –  Raffo Nov 15 '11 at 13:43
    
This is the same issue as in Listings package not correctly showing PHP strings –  Caramdir Nov 16 '11 at 1:15
add comment

1 Answer 1

Given that your code worked fine for @wh1t3 earlier, that indicated a problem with something else in your document. I guessed that your listings options set the string style to white text on a white background, which you confirmed was true. Examples for future reference (also correcting the extraneous quotes around the caption, and the backslashes in the strings):

enter image description here

\documentclass{article}

\usepackage{xcolor,listings}
\lstset{basicstyle=\scriptsize,stringstyle=\color{white},language=C}

\begin{document}
\begin{lstlisting}[label=cond-var-white, caption={Condition variables usage example}]
printf("inc_count(): thread %ld, count = %d  Threshold reached.\n", 
             my_id, count);
\end{lstlisting}

\lstset{backgroundcolor=\color{gray!50}}
\begin{lstlisting}[label=cond-var-gray, caption={Condition variables usage example}]
printf("inc_count(): thread %ld, count = %d  Threshold reached.\n", 
             my_id, count);
\end{lstlisting}

\lstset{backgroundcolor=\color{white},stringstyle=\color{black}}

\begin{lstlisting}[label=cond-var-black, caption={Condition variables usage example}]
printf("inc_count(): thread %ld, count = %d  Threshold reached.\n", 
             my_id, count);
\end{lstlisting}

\end{document}
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.