当我尝试将我的文档编译成 pdf 时,我收到此错误。重要的是要知道我的项目一个月前确实编译过,没有错误:我今天打开它,它失败了,根本没有修改。我包含了一个 MWE。
\documentclass[a4paper, oneside, 10pt]{book}
\usepackage[english]{babel}
\usepackage[pdftex]{graphicx}
\usepackage{eso-pic}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage[breakable,listings]{tcolorbox}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{indentfirst}
\usepackage{epigraph}
\usepackage{hyperref}
\usepackage[toc]{glossaries}
\usepackage{fancyhdr}
\usepackage{varioref}
\definecolor{base03}{HTML}{002B36}
\definecolor{base02}{HTML}{073642}
\definecolor{base01}{HTML}{586E75}
\definecolor{base00}{HTML}{657B83}
\definecolor{base0}{HTML}{839496}
\definecolor{base1}{HTML}{93A1A1}
\definecolor{base2}{HTML}{EEE8D5}
\definecolor{base3}{HTML}{FDF6E3}
\definecolor{yellow}{HTML}{B58900}
\definecolor{orange}{HTML}{CB4B16}
\definecolor{red}{HTML}{DC322F}
\definecolor{magenta}{HTML}{D33682}
\definecolor{violet}{HTML}{6C71C4}
\definecolor{blue}{HTML}{268BD2}
\definecolor{cyan}{HTML}{2AA198}
\definecolor{green}{HTML}{859900}
\lstdefinelanguage{JavaScript}{
keywords={
typeof,new,true,false,catch,function,return,null,catch,switch,var,if,in,
while,do,else,case,break, try},
ndkeywords={class,export,boolean,throw,implements,import,this},
sensitive=false,
comment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]',
morestring=[b]"
}
\newtcblisting[auto counter,list inside=codeList,number within=section]{codeBox}[1]{
breakable,
bottomrule at break=0pt,
toprule at break=0pt,
title=Code~\thetcbcounter: #1,
colback=base2,
colframe=base02,
listing only,
listing options={
language=JavaScript,
commentstyle=\color{base0},
keywordstyle=\color{yellow},
stringstyle=\color{blue},
basicstyle=\ttfamily\footnotesize\color{base01},
identifierstyle=\color{base02},
ndkeywordstyle=\color{red}\bfseries,
breaklines=true,
breakautoindent=true,
breakindent=30pt,
escapeinside={~}{~},
showstringspaces=false,
captionpos=b
},
list entry=\thetcbcounter~~#1,
before=\bigskip\noindent,
fontupper=\singlespacing\vskip -1.5em
}
\begin{document}
\begin{codeBox}
code here
the end command will produce the error when compiling
\end{codeBox}
\end{document}
编译时,我得到:
! Missing \endcsname inserted.
<to be read again>
\tcb@lsttp@tcolorbox
l.85 \end{codeBox}
答案1
对我来说,同样的 MWE 无法与tcolorbox
3.00 一起编译(并显示相同的错误消息)。我不是这方面的专家,但我认为这可能是软件包中的一个错误tcolorbox
。如果我将此补丁应用于文件,它对我来说工作正常tcolorbox.sty
:
diff --git a/texmf/tex/latex/tcolorbox/tcolorbox.sty b/texmf/tex/latex/tcolorbox/tcolorbox.sty
index 4555182..c8ea54d 100644
--- a/texmf/tex/latex/tcolorbox/tcolorbox.sty
+++ b/texmf/tex/latex/tcolorbox/tcolorbox.sty
@@ -1186,7 +1186,7 @@
\else%
\csedef{tcb@lstof@#2}{\kvtcb@new@listof}%
\csedef{tcb@lsttp@#2}{\kvtcb@new@listtype}%
- \appto\tcb@new@colopt{,add to list={\csname tcb@lstof@\kvtcb@savedelimiter\endcsname}{\csname tcb@lsttp@\kvtcb@savedelimiter\endcsname}}%
+ \appto\tcb@new@colopt{,add to list={\csname tcb@lstof@#2\endcsname}{\csname tcb@lsttp@#2\endcsname}}%
\fi%
\kvtcb@init@hook%
}%
答案2
好的,我明白了。如果 codeBox 定义为:
\newtcblisting[auto counter,list inside=codeList,number within=section]{codeBox}[1]{ ... }
我的盒子编译正确。有一个缺点,即代码不会列在清单列表中。