tcolorbox 将列表片段添加到列表列表

tcolorbox 将列表片段添加到列表列表

我正在写一份明晚就要交的报告,但我遇到了一个无法解决的问题。代码如下,问题是清单中还出现了清单的片段test.vhd。我已经使用过此代码,没有任何问题,但现在我意识到,如果我更改某些内容(例如,删除其中一个清单),旧报告中也会出现此问题。我不明白为什么。非常感谢任何能帮助我的人。

\documentclass[11pt]{report}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{listings}
\usepackage[most]{tcolorbox}
\usepackage{inconsolata}
\usepackage{graphicx}
\tcbuselibrary{breakable} 

\lstdefinelanguage{VHDL}{
   morekeywords={
     library, use, all, entity, is, port, variable, map, in, out, end, architecture, of, begin, and, generic, signal, if, then, else, generate, for, component, constant, process, to, downto, std_logic, std_logic_vector, ieee, std_logic_1164, std_logic_unsigned, numeric_std, rising_edge, type, case, when, others, natural, integer, unsigned, signed, array, to_integer
   },
   morecomment=[l]--
}
\lstdefinelanguage{ASM}{
   morekeywords={
    addui, jal, j, seqi, bnez, sw, lw, mult, jr
   },
   morecomment=[l]\;
}
\newtcblisting[auto counter, number within=chapter, list inside=listing]{VHDLlisting}[2][]{sharp corners, breakable, fonttitle=\bfseries, colframe=gray, listing only, listing options={basicstyle=\ttfamily\tiny, commentstyle =\color{gray} \textit, language= VHDL, breaklines=true, showstringspaces=false, breakatwhitespace=false, tabsize=4, postbreak={\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}}}}, title=Listing \thetcbcounter: #2, #1, list entry={\protect\numberline{\thetcbcounter}#2}}
\newtcblisting[use counter from=VHDLlisting, number within=chapter, list inside=listing]{ASMlisting}[2][]{sharp corners, breakable, fonttitle=\bfseries, colframe=gray, listing only, listing options={basicstyle=\ttfamily\tiny, commentstyle =\color{gray} \textit, language=ASM, breaklines=true, showstringspaces=false, breakatwhitespace=false, tabsize=4, postbreak={\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}}}}, title=Listing \thetcbcounter: #2, #1, list entry={\protect\numberline{\thetcbcounter}#2}}

\begin{document}

\tcblistof[\chapter*]{listing}{List of Listings}

\chapter{a chapter}
\begin{VHDLlisting}{test.vhd}
this is a listing
this is a listing
this is a listing
this is a listing
this is a listing
\end{VHDLlisting}
\end{document}

答案1

tcolorbox解析列表时,它会写入一个临时文件\jobname.listing,其中存储当前列表,以便稍后读回(我猜是在更改的 catcode 机制下)。此外,\jobname.\tcb@lstof@VHDLlisting还会写入一个文件,其中存储列表的所有条目。

在您的文档中,正如您list inside=listing在 中指定的那样\newtcblisting,文件扩展名\tcb@lstof@VHDLlisting变为listing,这与列表的临时输出文件发生冲突。结果是不同的东西进入同一个文件。在下一次编译运行中,该文件被包含\tcblistof并打印出其中一个列表留下的随机垃圾。

解决方法很简单,为列表选择另一个内部名称,例如mylisting。更改需要应用于 的\newtcblisting定义和调用\tcblistof

\newtcblisting[..., list inside=mylisting]{VHDLlisting}[2][]{ ... }

\tcblistof[\chapter*]{mylisting}{List of Listings}

相关内容