リスト: 範囲区切りを白にして、ブロックコメントを非表示にする

リスト: 範囲区切りを白にして、ブロックコメントを非表示にする

簡単に言うと、範囲区切りを白にして、コード ブロックを表示するときに範囲区切りが表示されないようにしたいのです。また、特定のブロック コメントを完全に省略したいのです。マニュアルを読みましたlistingsが、なぜこれが機能しないのかわかりません。

私は morecomment=[s][\color{white}]{\#~}{~\#}、範囲のプレフィックス/サフィックスと同じマーカーを使用して、オプションを使用します。またmorecomment=[is]{"""~}{~"""}、前後にチルダを付けてブロックコメント (Python) を省略するオプションも使用したいと思います。チルダの前にブラックスラッシュを置くことも試しました。

何かお分かりですか? これは簡単に修正できると思います。

LaTeX コード

\documentclass[11pt,a4paper]{article}

\usepackage{xcolor}
\usepackage{textcomp}
\usepackage{listings}  % 

\lstset{
    language=Python,
    basicstyle=\ttfamily\small\color{blue},% just to show that colors are working
    breaklines=true,
    tabsize=4,
    escapeinside={\#`}{`},
    includerangemarker=false,
    rangeprefix={\#~},
    rangesuffix={~\#},
%   moredelim=[s][\color{white}]{\#~}{~\#},% I want to make the range delimters white, this is not working
    morecomment=[s][\color{white}]{\#~}{~\#},% I tried usign more delim, and more comment to no avail
    morecomment=[is]{"""~}{~"""},  % I want to omit block comments (invisible), this is not working
}


\begin{document}
\section{Some Sample code boxes} 
\subsection{Excerpt of Code}
\lstinputlisting[
language=Python,
linerange=beg:def-end:def,
]{Ex.py}
\subsection{Full Code, delimiters hidden}
\lstinputlisting[%
caption={Some Python code},%
language=Python%
]{Ex.py}
\end{document}

Ex.py Python コード

"""
Some block comment
"""
"""~
Some block comment I want omitted entirely
~"""

# I want the range delimiters below whited out so they do not appear on the full code block
#~beg:def~#
def y(x, a=1, b=1, c=1):
    return a*x**2 + b*x + c   #`\label{lin1}`
#~end:def~#

Some_other_code = 1

関連情報