考虑以下:
\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}
我怎样才能得到两个都出现的语法是否被设计为后者?
为精彩的 Jubobs 编辑:(a较少的最小工作示例:)
\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}
带输出
答案1
尝试以下方法。如果适合您,我会进一步充实我的答案。
\documentclass{article}
\usepackage{listings}
\makeatletter
\lstset{
language=Python,
moredelim=*[s][\lst@stringstyle]{"""}{"""},
moredelim=[s][\lst@commentstyle]{<<}{>>},
showstringspaces=false,
}
\makeatother
\begin{document}
\begin{lstlisting}
def expand():
"""foo <<expand documentation>>"""
for hook in noweb:
<<expand noweb hook>>
\end{lstlisting}
\end{document}