I'd like to colorize the names of header files included in angle brackets (<>) in my C examples formatted by the listings package. In the MWE I'd like <brackets.h>
to be orange too like "quotes.h"
. I don't want to do that manually with escapes in every listing but globally. I have tried various crude things including the use of keywordcommentsemicolon
(which did not work at all because it is an undefined key although it is mentioned in the documentation... does it need to be enabled?). The most promising results were achieved by using morecomment=[s]{<}{>}
. However, that would colorize everything following a <
... which is not that uncommon in C ;)
The solution should work independently from the documentclass, especially beamer should work, and preferably work with common listings options (i.e., not change the behavior of other formatting options such as identifierstyle
.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\definecolor{darkorange}{HTML}{C87B0F}
\usepackage{listings}
\lstset{language=C,captionpos=b}
\lstloadlanguages{C}
\lstset{%
stringstyle=\color{darkorange},
identifierstyle={\color{blue}}.
}
\begin{document}
\begin{lstlisting}[gobble=4]
#include <stdlib.h>
#include "quotes.h"
int main(int argc, char **argv) {
if (argc <= 3)
return 0 > **argv;
return EXIT_SUCCESS;
}
\end{lstlisting}
\end{document}