4

Using the listings package, one can define a format for some arbitrary set of delimiters and the characters enclosed within. However, when using double delimiters, the specified format doesn't apply to the closing delimiter.

Consider the following MWE.

\documentclass{article}
\usepackage{listings}
\usepackage{upquote}
\usepackage{xcolor}
\lstset{
    moredelim = [s][\color{blue}]{`}{'},
}
\begin{document}
\begin{lstlisting}
macros u i
`u`i''
\end{lstlisting}
\end{document}

This code yields the following output: enter image description here

Notice how the last closing delimiter ' is not formatted in blue. Is there a way to fix this?

Note: I used the upquote package to get the desired look of verbatim apostrophes, but if not used the problem persists.

4

Looks like a nesting issue. From the manual (page 24), you can add an asterisk to allow inner delimiters to be found:

\documentclass{article}
\usepackage{listings}
\usepackage{upquote}
\usepackage{xcolor}
\lstset{
    moredelim = *[s][\color{blue}]{`}{'},
}
\begin{document}
\begin{lstlisting}
macros u i
`u`i''
\end{lstlisting}
\end{document}

result

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.