I have a snippet of code I'm putting into a paper written in LaTeX.
I don't want it to highlight any of the keywords that start with a # sign, such as #define, or #pragma. Here is a MWE of what I have right now:
\documentclass[10pt,journal,compsoc]{IEEEtran}
\newcommand{\us}{\char`_}
\usepackage{listings}
\usepackage{color}
\usepackage{float}
\lstdefinestyle{cpp_onecol}{
language=C++,
basicstyle=\small\ttfamily,
breaklines=true,
morekeywords={CHECK},
keywordstyle=\color{black}\bfseries\itshape,
commentstyle=\color{black}\bfseries,
alsoother={\#},
deletekeywords ={\#pragma}
}
\begin{document}
\begin{figure}
\begin{lstlisting}[style=cpp_onecol]
#pragma hello
#define I_DONT_LIKE_POUNDSIGN 1
int a;
int b;
volatile int c;
\end{lstlisting}
\begin{lstlisting}
\end{lstlisting}
\end{figure}
\end{document}
This generates:
I have tried searching for a solution, but I think the # is ruining my search results too. The only one I found suggested adding the alsoother={\#},
but that didn't really help at all.
Best Answer
I figured it out. I added a deletedelim with a pound sign.
Here is the MWE:
And the result: