TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get green comments and blue javadocs.

But with this code I can't get blue javadocs, always I get all comments green:


\definecolor{red}{rgb}{0.6,0,0} % strings
\definecolor{green}{rgb}{0.25,0.5,0.35} % comments
\definecolor{purple}{rgb}{0.5,0,0.35} % keywords
\definecolor{blue}{rgb}{0.25,0.35,0.75} % doc

\lstset {
frame               =   Ltb,
framerule           =   0pt,
aboveskip           =   0.5cm,
framextopmargin     =   3pt,
framexbottommargin  =   3pt,
framexleftmargin    =   0.4cm,
framesep            =   0pt,
rulesep             =   .4pt,
backgroundcolor     =   \color{gray97},
rulesepcolor        =   \color{black},
stringstyle         =   \color{red},
showstringspaces    =   false,
basicstyle          =   \ttfamily\small,
commentstyle        =   \color{green},
morecomment         =   [s][\color{blue}]{/**}{*/},
keywordstyle        =   \color{purple}\bfseries,
numbers             =   left,
numbersep           =   15pt,
numberstyle         =   \tiny,
numberfirstline     =   false,
breaklines          =   true,

I use this code to print the code example:

    /* Includes */
    #include <stdio.h>

    int main(int argc, char* argv[]) {
        puts("Hola mundo!"); // Text console

In that can I be wrong? Thanx

share|improve this question

migrated from stackoverflow.com Jan 15 '13 at 21:35

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

This is because selecting language=C is overriding your morecomment setting. As the listings documentation says:

Please remember that both "extra" comments must be defined after the normal comment, since the delimiter /* is a substring of /*+ and /*-.

To fix it, either set the language in the \lstset before setting morecomment, set the morecomment value when you use the lstlisting environment, or define a style for your settings which you apply after setting the language (e.g. \begin{lstlisting}[language=C,style=mystyle])

share|improve this answer
¡Thank you very much! I'm new with LaTeX and that error was driving me crazy :D – Fjsermu Jan 16 '13 at 1:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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