
간단히 말해서, 코드 블록을 표시할 때 범위 구분 기호가 표시되지 않도록 범위 구분 기호를 흰색으로 만들고 싶습니다. 또한 특정 블록 주석을 완전히 생략하고 싶습니다. 설명서를 읽었 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