5

lstlisting is not using the identifierstyle font inside of the moredelim that makes the identifier name red. In the example, the first varname is in tt font but the second is in roman. I want the second varname to also be in tt font but red. What am I doing wrong?

\documentclass{article}
\usepackage{listings}
\usepackage{color}

\lstset{
language=C++,
identifierstyle={\texttt},
moredelim=**[is][\color{red}]{@}{@},
}% lstset

\begin{document}
\begin{lstlisting}
varname
@varname@
\end{lstlisting}
\end{document}
2
  • use moredelim=**[is][\color{red}\tt]{@}{@}
    – Marijn
    May 12, 2016 at 16:07
  • 2
    @Marijn No, not \tt! Use \ttfamily. May 12, 2016 at 16:15

1 Answer 1

1

Add \ttfamily:

\documentclass{article}
\usepackage{listings}
\usepackage{color}

\lstset{
language=C++,
identifierstyle={\texttt},
moredelim=**[is][\color{red}\ttfamily]{@}{@},
}% lstset

\begin{document}
\begin{lstlisting}
varname
@varname@
\end{lstlisting}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.