I'm looking for a maintainable way of typesetting placeholders in code snippets. In my listings, I would like that anything contained between the two delimiters @<
and >@
be
- typeset in (typewriter) italics in some colour (RubineRed, say),
- preceded by an upright (not italics) opening chevron,
- appended by an upright (not italics) closing chevron.
For instance, @<some_value>@
should (in one of my listings) be typeset as
Unfortunately, I can't figure out a way of getting my delimiters (@<
and >@
) to be replaced by upright chevrons without having to hardcode the latter or without breaking what moredelim
does. I want to avoid hardcoding the chevrons because it's not maintainable; imagine if I changed my mind later on as to how my placeholders should be typeset...
Below is an example of what I have at the moment and what I would like to get. Any idea?
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{listings}
\lstset
{
moredelim = **[is][\color{RubineRed}\itshape]{@<}{>@},
basicstyle = \ttfamily,
}
\begin{document}
Current strategy: hard code the chevrons (which, sadly, get italicised), e.g.
\begin{lstlisting}
x=@<<some_value>>@
\end{lstlisting}
Desired output of \texttt{\detokenize{x=@<some_value>@}} within a listing:
{
\ttfamily
x=%
{%
\color{RubineRed}
\textless\textit{some\_value}\textgreater
}
}
\end{document}