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.

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:

\usepackage{color}
\definecolor{gray97}{gray}{.97}
\definecolor{gray75}{gray}{.75}
\definecolor{gray45}{gray}{.45}

\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

\usepackage{listings}
\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:

\begin{lstlisting}[language=C]
    /* Includes */
    #include <stdio.h>

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

In that can I be wrong? Thanx

share|improve this question
add comment

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

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

1 Answer

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
add comment

Your Answer

 
discard

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.