I want to highlight the line numbers of the lines of the Listing to which I refer. See the question Highlight line numbers in Listings for details about how to highlight one line number.
Now I want to highlight multiple line numbers. The pasted code works, unless you uncomment the inclusion of the hyperref
package.
Does anybody know how to get this to work?
BTW: Hyperref conflicts also with the solution of 1.
BTW2: Without the highlighting hyperref
causes no problems.
\documentclass{article}
\usepackage{xcolor}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\usepackage{listings}
% define C++ style
\lstdefinestyle{cppStyle}
{
basicstyle=\footnotesize,
tabsize=2,
captionpos=b,
frame=lines,
breaklines=true,
% language related
language=C++,
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
% numbering
numbers=left,
numberstyle=\tiny
}
\makeatletter
\newcommand\labelline[1]{%
\def\@currentlabel{\thelstnumber}\label{#1}}
\newcommand\lineref[1]{
\@ifundefined{r@#1}{0}{\ref{#1}}
}
\makeatother
%\usepackage{hyperref}
\begin{document}
\begin{lstlisting}[style=cppStyle,escapeinside={(*@}{@*)},caption={Definition of a dictionary in \texttt{readPPProperties.H}},label=lst:createDictionaryIOobject, numberstyle={\ifnum\value{lstnumber}=\lineref{code:ioObjectReadFlag}\color{green}\else\ifnum\value{lstnumber}=\lineref{code:ioObjectWriteFlag}\color{green}\else\fi\fi}]
IOdictionary ppProperties
(
IOobject
(
"ppProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED, (*@\label{code:ioObjectReadFlag}@*)
IOobject::NO_WRITE (*@\label{code:ioObjectWriteFlag}@*)
)
);
\end{lstlisting}
\end{document}