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 have a little problem in my settings. I cannot locate the error and need some additional eyes to tell me where I should look. I use listing to show my c++ code but when I try to add additional keywords they are not highlighted. Here's the setting:

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{dred}{rgb}{0.545,0,0}
\definecolor{dblue}{rgb}{0,0,0.545}
\definecolor{lgrey}{rgb}{0.9,0.9,0.9}
\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\lstset{ 
      backgroundcolor=\color{lgrey},  
      basicstyle=\footnotesize \ttfamily \color{black} \bfseries,   
      breakatwhitespace=false,       
      breaklines=true,               
      captionpos=b,                   
      commentstyle=\color{dkgreen},   
      deletekeywords={...},          
      escapeinside={\%*}{*)},                  
      frame=single,                  
      keywordstyle=\color{purple},  
      morekeywords={BRIEFDescriptorConfig,string,TiXmlNode,DetectorDescriptorConfigContainer,istringstream,cerr,exit}, 
      identifierstyle=\color{black},
      stringstyle=\color{blue},      
      language=C++,                
      numbers=right,                 
      numbersep=5pt,                  
      numberstyle=\tiny\color{black}, 
      rulecolor=\color{black},        
      showspaces=false,               
      showstringspaces=false,        
      showtabs=false,                
      stepnumber=1,                   
      tabsize=5,                     
      title=\lstname,                 
    }

So nothing special, I guess. Here is an minimal-example using listing:

\begin{lstlisting}[language={C++},caption={Caption}]
void XMLDetDecConfigReader::handleDescriptors(DetectorDescriptorConfigContainer* configContainer, TiXmlNode* descriptorsNode);
\end{lstlisting}

I don't want to use any other packages but to solve this highlighting-problem.

Thank you for your help.

share|improve this question
    
Welcome to TeX.sx! –  hpesoj626 Feb 22 '13 at 17:33
    
Thanks. I've defined my own dialect of c++. =) –  Mr.Mountain Feb 23 '13 at 10:49

2 Answers 2

up vote 0 down vote accepted

Output

enter image description here

I would heed Sašo Živanović's advice about defining your own C++ dialect if you are going to typeset other codes in other languages in your document apart from C++. If not, then write language=C++, before keywordstyle=\color{purple}, in your \lstset, then omit the language={C++} from your optional argument. You do this also for your own flavor of C++ highlighting via the \lstdefinelanguage command.

Here is a minimal working example (MWE) completed from your code snippets. (Please post MWEs next time.)

Code

%http://tex.stackexchange.com/questions/99455/keyword-highlighting-of-c-using-listing#99455
\documentclass[preview,border=5]{standalone}
%\documentclass{article}

\usepackage{listings}
\usepackage{xcolor}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{dred}{rgb}{0.545,0,0}
\definecolor{dblue}{rgb}{0,0,0.545}
\definecolor{lgrey}{rgb}{0.9,0.9,0.9}
\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\lstdefinelanguage{cpp}{
      backgroundcolor=\color{lgrey},  
      basicstyle=\footnotesize \ttfamily \color{black} \bfseries,   
      breakatwhitespace=false,       
      breaklines=true,               
      captionpos=b,                   
      commentstyle=\color{dkgreen},   
      deletekeywords={...},          
      escapeinside={\%*}{*)},                  
      frame=single,                  
      language=C++,                
      keywordstyle=\color{purple},  
      morekeywords={BRIEFDescriptorConfig,string,TiXmlNode,DetectorDescriptorConfigContainer,istringstream,cerr,exit}, 
      identifierstyle=\color{black},
      stringstyle=\color{blue},      
      numbers=right,                 
      numbersep=5pt,                  
      numberstyle=\tiny\color{black}, 
      rulecolor=\color{black},        
      showspaces=false,               
      showstringspaces=false,        
      showtabs=false,                
      stepnumber=1,                   
      tabsize=5,                     
      title=\lstname,                 
    }


\begin{document}
\begin{lstlisting}[language=cpp,caption={Caption}]
void XMLDetDecConfigReader::handleDescriptors(DetectorDescriptorConfigContainer* configContainer, TiXmlNode* descriptorsNode);
\end{lstlisting}
\end{document}
share|improve this answer

What you do is define what style you will use and then by specifying language={C++} in the environment effectively undo your specification. Either omit language=... from the optional argument or, probably even better, define your own dialect of C++.

share|improve this answer

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.