2 回答

TA貢獻1772條經驗 獲得超8個贊
有一種方法可以通過一個名為listings的包向 python 添加代碼。這個包允許顯示代碼甚至完整的文件。
為了實現這一點,conf.py您可以添加:
latex_elements = {
"papersize": "letterpaper",
"pointsize": "10pt",
"figure_align": "htbp",
"preamble": r"""
\usepackage{listings}
\lstset{
language=Python, % the language of the code
title=\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title
}
""",
}
還有更多設置可以添加到lstset.
然后可以將代碼添加到.rst文件中:
.. raw:: latex
\section{Code}
\lstinputlisting{../../../path/to/my/file.py}

TA貢獻1828條經驗 獲得超4個贊
添加回答
舉報