感谢 @u70550 Explorer 老师在 QQ 群的关注和关照,
问题的解决方案如下
- 删掉
\tcbuselibrary中的breakable
(该库与before={\begin{listing}[htbp!]}, after={\label{#3}\end{listing}},冲突, 原意是为了实现引用盒子, 由于没有仔细阅读tcolorbox盒子, 导致该错误. 引用可以使用宏包中的label可选项, 然后\ref即可, 在最后的完整示例中给出了一个例子) - 修改
abMATLAB环境的定义
- 删掉
- 基本功能已经实现 (更多的功能应当 仔细 阅读
tcolorbox宏包手册5.2 Lists of tcolorboxes,17 Libraries listings ,listingsutf8 , andminted部分)
(tcolorbox 手册的获取 在线: 浏览器搜素 ctan tcolorbox 等等; 本地发行版在终端运行命令 texdoc tcolorbox)
* 使用 `tcolorbox` 宏包以及 `minted` 库定义 `MATLAB` 的代码盒子
* 实现 `Lists of tcolorboxes`: `\tcblistof[\chapter*]{abMATLABlist}{MATLAB 代码}`
* 引用盒子: 上面已经提到- 完整的示例如下:


\documentclass[UTF8]{ctexbook}
\usepackage{geometry}
\geometry{
a4paper,
top=25.4mm,
bottom=25.4mm,
left=20mm, right=20mm,
headheight=2.17cm,
headsep=4mm,
footskip=12mm
}
%\usepackage{nameref}
%代码排版
\usepackage{tcolorbox}
\tcbuselibrary{minted}
\newtcblisting[auto counter,number within=chapter,list inside=abMATLABlist]{abMATLAB}[2][]{%
coltitle=black,
colbacktitle=white,
colupper=black,
colback=white,
boxrule=0pt,
toprule=0.08em,
titlerule=0.05em,
bottomrule=0.08em,
fonttitle=\bfseries,
title={\heiti 代码列表 \thetcbcounter: #2},
listing only,
sharp corners=all,
% nameref={\textcolor{blue}{代码列表}},
minted language=matlab,
list text=#2, %设置目录项的文本项
% list entry=\protect\numberline{\thetcbcounter} #2, %在这里等价于 list text=#2,; 可以进一步修改目录条目的样式如, 计数器等等
#1,
}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=blue}
\begin{document}
\tableofcontents
\tcblistof[\chapter*]{abMATLABlist}{MATLAB 代码}
\tcblistof[\section*]{abMATLABlist}{MATLAB 代码}
\begin{abMATLAB}{拉普拉斯展开计算行列式}
\end{abMATLAB}
\chapter{AAA}
%{abMATLABlist:DetLaplace}
\begin{abMATLAB}[label={abMATLABlist:DetLaplace}]{拉普拉斯展开计算行列式}
function d=DetLaplace(A)
% DETLAPLACE 使用 Lapace 展开计算行列式
% d = DetLaplace(A); 计算矩阵 A 的行列式 (determinant)
% 对第一行 (row) 使用 Laplace 展开 (expansion)
n = length(A);
if n==1
d=A(1,1);
else
d=0; v=1;
for j=1:n
M1j = [A(2:n,1:j-1) A(2:n,j+1:n)];
d = d + v*A(1,j)*DetLaplace(M1j);
v = -v;
end
end
\end{abMATLAB}
引用代码列表 \ref{abMATLABlist:DetLaplace}. 这也是引用代码列表 \nameref{abMATLABlist:DetLaplace} .
\chapter{BBB}
\begin{abMATLAB}{拉普拉斯展开计算行列式}
function d=DetLaplace(A)
% DETLAPLACE 使用 Lapace 展开计算行列式
% d = DetLaplace(A); 计算矩阵 A 的行列式 (determinant)
% 对第一行 (row) 使用 Laplace 展开 (expansion)
n = length(A);
if n==1
d=A(1,1);
else
d=0; v=1;
for j=1:n
M1j = [A(2:n,1:j-1) A(2:n,j+1:n)];
d = d + v*A(1,j)*DetLaplace(M1j);
v = -v;
end
end
\end{abMATLAB}
\chapter{CCC}
\begin{abMATLAB}{拉普拉斯展开计算行列式}
function d=DetLaplace(A)
% DETLAPLACE 使用 Lapace 展开计算行列式
% d = DetLaplace(A); 计算矩阵 A 的行列式 (determinant)
% 对第一行 (row) 使用 Laplace 展开 (expansion)
n = length(A);
if n==1
d=A(1,1);
else
d=0; v=1;
for j=1:n
M1j = [A(2:n,1:j-1) A(2:n,j+1:n)];
d = d + v*A(1,j)*DetLaplace(M1j);
v = -v;
end
end
\end{abMATLAB}
引用代码 \ref{abMATLABlist:DetLaplace}
\end{document}



问 tcolorbox 使用 minted 库排版代码, 实现目录报错 \tcblistof