3

I am using the following:

\usepackage{listings}
    \lstset{
      language=C,
      keywordstyle=\color{pantone309!90},
      morekeywords={
        omp,
        parallel,
        \#pragma
        }
    }

When i now write this

\begin{lstlisting}
#pragma
#define
    #pragma
    #define
\end{lstlisting}

It looks like this:Output of my example

How can i fix this, so that it all pragmas are highlighted as keyword ?

JHnet
  • 215
  • Welcome to TeX.SX! Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Nov 11 '13 at 22:19
  • AFAIK in Listings the C/C++ preprocessor directives such as #define etc. are formatted not with keywordstyle but with directivestyle. – marczellm Nov 11 '13 at 22:20
  • related: http://tex.stackexchange.com/questions/142582/how-can-i-get-identifier-style-to-apply-to-in-a-perl-listing – jub0bs Nov 11 '13 at 22:22

1 Answers1

2

You have to define \#key in otherkeywords (page 44 of the manual)

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
  language=C,
  keywordstyle=\color{green!70!blue},
  morekeywords={
    omp,
    parallel,
  }
  alsoother={\#},
  otherkeywords={\#pragma,\#define},
}

\begin{document}
\begin{lstlisting}
#pragma
#define
    #pragma
    #define
\end{lstlisting}
\end{document}

enter image description here

(Sorry for the change in the color; it was easier to define a new one than searching how to use Pantone colors.)

egreg
  • 1,121,712