我正在用 Python 脚本排版文档,其中一些是内联脚本,一些来自文件夹 scripts 下的文件。我将 tcolorbox 与 minted 结合使用,为了进行测试,我尝试格式化内联脚本和来自一个文件 scripts/hello.py 的脚本。
要求:这两个脚本共享在 newtcblisting programBox 下定义的公共计数器。
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass{memoir}
\usepackage{xcolor}
\usepackage{graphicx}
\graphicspath{ {./pythonBookFiles/pythonBookImages/} }
\DeclareGraphicsExtensions{.png,.pdf.,jpg}
\usepackage{hyperref}
\hypersetup{ %
pdfborder = {0 0 0},
colorlinks=true,
}
\hypersetup{
colorlinks=true,
citecolor=maroon,%
filecolor=maroon,%
linkcolor=maroon,%
urlcolor=maroon,%
hidelinks,%
% pdftitle=\thetitle,
% pdfauthor=\theauthor,
linktoc=all
}
\usepackage[many,minted]{tcolorbox}% version 3.03 or better
\newcommand{\mynewminted}[3]{%
\newminted[#1]{#2}{#3}%
\tcbset{myminted/#1/.style={minted language=#2,minted options={#3}}}}
\mynewminted{mypython}{python}{tabsize=2,linenos=false, numbersep=4pt, fontsize=\footnotesize}
\newtcblisting[auto counter,number within=section,
list inside=mypyg]{programBox}[3][]{%
listing only,title={Program \thetcbcounter: #3},
list entry={\protect\numberline{\thetcbcounter}#3},
enhanced,colframe=orange!70!black,breakable, drop fuzzy shadow, myminted/#2,#1}
\newtcbinputlisting[use counter from=programBox]{\programFile}[2][]{%
listing file={#2},
title=Program. (\thetcbcounter) of \texttt{#2},
colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,
listing only,breakable,#1}
\pretocmd{\chapter}{\addtocontents{mypyg}{\addvspace{10pt}}}{}{}
\makeatletter
\renewcommand*\l@tcolorbox{\@dottedtocline{1}{1.5em}{3em}}
\makeatother
\begin{document}
\section{Structure of Python program}
A simple program is shown as \ref{prog:simple}
\begin{programBox}{mypython,label=prog:simple}{Python Program }
import os, django.contrib
#this is one line comment
"""
This is
Multi line
Comment
"""
int a
print(a)
\end{programBox}
\section{Python source from a file}
\programFile[before upper=\textit{This is the included file content:}]{scripts/hello.py}
\end{document}
直到 programBox 环境它都运行良好,但使用 \programFile 宏它无法编译。
我得到的错误是Package minted错误:缺少 Pygments 输出;\inputminted wasor 可能正在使用缺少文件的 freezecache。...包含的文件内容:}]{scripts/hello.py}但是 pygments 已经安装好了。请帮我输入文件。提前谢谢了。
以下测试文件位于文件夹脚本下,文件名为:hello.py
import os, django.contrib
print("hello World")