listings package allows setting basicstyle, keywordstyle, identifierstyle,
commentstyle, stringstyle. Is it possible to set different style for comments that start from /**
not just /*
?
To make my question more clear. Assume I have set environment
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage[scaled=0.92]{beramono}
\usepackage[scaled=0.92]{berasans}
\usepackage[scaled=0.92]{beraserif}
\lstnewenvironment{MyCode}
{\lstset{
language=C++,
basicstyle=\fontfamily{fvm}\selectfont,
keywordstyle=\bfseries,
identifierstyle=\color{blue},
commentstyle=\fontfamily{fve}\selectfont\color{olive},
stringstyle=\fontfamily{fvs}\selectfont,
frame=single,showstringspaces=false,columns=flexible} }
{}
and I have the following code
\begin{document}
\begin{MyCode}
/*
Multi-line
non-Doxygen comments
*/
#include <iostream>
/** Single-line Doxygen comment */
class MyClass {
private:
int value; /**< After member Doxygen comment */
public:
/**
* Multi-line Doxygen comment
* @param int x new value
* @return bool operation success
*/
bool setValue(int x /**< [in] also Doxygen */) {
this->value = x; /* non-Doxygen comment */
std::cout << "I'm setting value " << x << std::endl;
/* Single line non-Doxygen comment */
return true;
}
};
\end{MyCode}
\end{document}
There are mixed:
- usual comments starting with
/*
- Doxygen (javadoc) comments starting with
/**
/**
itself starts with /*
so all comments are formatted according to
commentstyle=\fontfamily{fve}\selectfont\color{olive},
Is it possible to distinguish between those comments and set another style for /**
comments? For example color them red not olive.
Best Answer
The
listings
package allows for multiple comment delimiters, but only one comment style. However, you can get around this limitation by using themoredelim
key. In your particular example, you could write something likeand the style used for "comments" delimited by
\**
and*\
will be different to that used for comments delimited by/*
and*/
.