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

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

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


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])

  • ¡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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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