我正在使用 memoir 排版一些 python 源代码示例。我能够按照 minted 创建者的 github 建议为 memoir 声明 ftlisting 浮点数。这些浮点数的列表已成功打印在文档开头。
\begin{pyprog}{Title of Program}{prog-label}
import os, numpy
a = 25
print(a)
print("Hello World")
\end{pyprog}
我被困在创建一个新的环境 pyprog 上,如上所示,它接受两个参数 Title 和 Label 并将 minted 包装在 ftlisting 浮点环境中,请帮助我。
% !TeX document-id = {e0f3a9c2-ac76-43b6-9d06-b802f7bc550a}
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass{memoir}
\usepackage{lipsum}
\newlistof{listofprograms}{lol}{List of Programs}
\newfloat[chapter]{ftlisting}{lol}{Program}
\newlistentry{ftlisting}{lol}{0}
\usepackage[all]{tcolorbox}
\usepackage{hyperref}
% Hyperref settings
\hypersetup{
unicode=true,
bookmarks=true,
bookmarksopen=true,
pdfstartview=FitH,
pdfpagelayout=OneColumn,
pdfpagemode=UseOutlines,
colorlinks=true,
linkcolor=colLink,
urlcolor=colLink,
citecolor=colLink,
bookmarksnumbered
}
\usepackage[nameinlink]{cleveref}
\crefname{ftlisting}{Program}{Programs}
\newenvironment{pyprog}[pyprog=fr,2]{
\begin{ftlisting}[H]
\def\tempcaption{#1}
\def\templabel{#2}
\begin{minted}
}{
\end{minted}
\caption{\tempcaption}
\label{\templabel}
\end{ftlisting}
}
\begin{document}
\listofprograms
\section{This is working}
The float environment is working fine for \Cref{prog-intro} with minted listing and is printed in the listofprograms also.
\begin{ftlisting}[H]
\begin{minted}[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize
]{python}
import os, numpy as np
#initialise a with 25
a=25
print("Hello World from ftlisting float")
\end{minted}
\caption{Listing First one }
\label{prog-intro}
\end{ftlisting}
\section{Environment defined for pyprog is not working}
\begin{pyprog}{hello world}{prog-env}
import os, django.contrib
# This code is included using pyprog environment
print("Hello World from pyprog environment)
\end{pyprog}
\end{document}
第 84 行:缺少插入的 \endcsname。第 84 行:额外的 \endcsname。第 85 行:FancyVerb 错误:。import os, django.contrib 第 91 行:缺少插入的 \endcsname。\end{pyprog} 第 91 行:软件包 minted 错误:缺少 Pygments 输出;\inputminted wasor 可能正在使用缺少文件的 freezecache。\end{pyprog} 第 26 行:选项 `bookmarks' 已被使用,(hyperref) 设置该选项无效
我针对上述代码参考了以下答案。