3

I'm writing a report due to tomorrow night but I have a problem that I can not resolve. The code is the following, the problem is that in the list of listing appears also a fragment of the listing test.vhd. I have already used this code without any problem but I realise now that also in the old reports if I change something (for example I remove one of the listings) this problem can appear. I don't understand why. Thank you very much to anyone who will help me.

\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}
0

1 Answer 1

4

When tcolorbox parses a listing, it writes a temporary file \jobname.listing in which the current listing is stored for being read back in later on (under a changed catcode regime, I presume). Additionally, a file \jobname.\tcb@lstof@VHDLlisting is written, to which all the entries for the list of listings go.

In your document, as you specify list inside=listing in \newtcblisting, the file extension \tcb@lstof@VHDLlisting becomes listing, which clashes with the temporary output file for listings. The result is that different things go to the same file. On the next compilation run this file is included by \tcblistof and prints that random garbage left from one of the listings.

The fix is simply to choose another internal name for your list of listings, e.g. mylisting. The changes need to be applied to the \newtcblisting definition and the call of \tcblistof:

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .