I would like to highlight some words in a lstlisting
. The language is HTML.
However, \emph
seems not to be working with HTML.
Any suggestions how I could work around this problem?
Right now I have:
\lstdefinestyle{htmlCode} {
language=html,
basicstyle=\scriptsize\ttfamily,
keywordstyle=\bfseries\ttfamily,
commentstyle=\color{gray}\ttfamily,
emph={time},
emphstyle=\color{green}
}
\begin{lstlisting}[style=htmlCode,caption={Html code}]
<b>Time: $time$</b>
\end{lstlisting}
Best Answer
You could use the
escapechar=<char>
option forlistings
in the following way:The reason for this working may involve the fact that
listings
allows escaping to LaTeX when using themathescape=true
flag. This escapes around$...$
, which is exactly around yourtime
"keyword".