Consider the following:
\documentclass{standalone}
\usepackage{listings}
\lstset{
language=Python,
morecomment=[s]{<<}{>>},
}
\begin{document}
\begin{lstlisting}
def expand():
"""<<expand documentation>>"""
for hook in noweb:
<<expand noweb hook>>
\end{lstlisting}
\end{document}
How can I get both occurrences of the syntax to be styled as the latter?
Edit for the wonderful Jubobs: (a less minimal working example :)
\documentclass{standalone}
\usepackage{listings}
\lstset{
language=Python,
showstringspaces=true,
showspaces=false,
showtabs=false,
moredelim=*[s][\lst@stringstyle]{"""}{"""},
moredelim=[s][\lst@commentstyle]{<<}{>>},
}
\renewcommand*\lstlistlistingname{List of Listings}
\lstMakeShortInline[basicstyle=\small\ttfamily]"
\begin{document}
\begin{lstlisting}
def expand():
"""foo <<expand documentation>>"""
for hook in noweb:
<<expand noweb hook>>
def marked_alone(node, neighbors):
"""\forall n \in N(n), "marked"(n) = 0
There are no marked nodes in this node's neighborhood."""
return not any(map(lambda n: n['marked'], neighbors))
\end{lstlisting}
\end{document}
with output
<<
and>>
, whether it be inside a docstring or elsewhere, to be typeset in comment style? Is that correct? What should be the style applied to docstrings (outside<< ... >>
)?showstringspaces
should definitely be disabled in docstrings (it would get super messy, as you can imagine), but I can't think of anything extra to add to that style.;)