.png)
파일의 코드를 내 문서에 포함하고 싶습니다. 그러나 여러 개의 개별 라인 범위가 동일한 목록에 나타나야 합니다. 그리고 고블링도 사용하고 싶은데, 빈줄도 좀 넣어주면 좋을 것 같아요.
패키지 를 사용하는 경우 동일한 파일의 여러 줄 범위를 포함하는 listings
옵션을 사용할 수 있습니다 . linerange
그러나 파일 입력에는 고블링이 지원되지 않으며 출력에서 빈 줄 하나가 어떻게든 건너뛰는 것 같습니다(아래 예의 5번째 줄).
을 사용하면 minted
빈 줄을 포함할 수 있습니다. 그러나 명령당 하나의 줄 범위만 사용할 수 있습니다 \inputminted
. 그것은 괜찮을 것입니다(다른 라인 범위에 대해 다른 gobble 거리를 사용하기 때문입니다). 그러나 다른 범위 사이에는 이렇게 불쾌한 간격이 있습니다. 그것을 사라지게 하는 데 사용할 수 있지만 vspace
항상 작동하는 것은 아닙니다(예: 어떤 이유로 페이지가 늘어나는 경우). 이러한 파일 부분이 연속적으로 표시되어야 함을 인식하는 다음과 같은 것이 있으면 좋을 것입니다.
\begin{minted}
\pythonfile[firstline=5,lastline=7]{mymodule.py}
\pythonfile[firstline=16,lastline=17,firstnumber=last]{mymodule.py}
\pythonfile[gobble=4,firstline=22,lastline=23,firstnumber=last]{mymodule.py}
\end{minted}
다음은 최소한의 작업 예입니다.
\documentclass{article}
\usepackage{filecontents}
\usepackage{listings}
\usepackage{minted}
\begin{filecontents}{mymodule.py}
import numpy as np
def mymean(x, axis=0) :
''' Here I explain why I need my own mean function.
Suppose for instance that I want to use axis=0 as a default.
Keyword arguments:
axis -- the axis over which to compute the mean.
Return:
The mean.
'''
return np.mean(x, axis=axis)
def mystd(x) :
return np.std(x)
if __name__ == '__main__' :
x = np.random.randint(0,100,150)
print mymean(x)
print mystd(x)
\end{filecontents}
\newmintedfile{python}{frame=leftline,linenos}
\begin{document}
\section{Listings}
\lstinputlisting[frame=left,numbers=left,language=Python,linerange={5- 7,16-17,22-23}]{mymodule.py}
\section{Minted}
\pythonfile[firstline=5,lastline=7]{mymodule.py}
\pythonfile[firstline=16,lastline=17,firstnumber=last]{mymodule.py}
\pythonfile[gobble=4,firstline=22,lastline=23,firstnumber=last]{mymodule.py}
\end{document}