5

How can I use \lstlistoflistings to create a list of listings, but not have this list as an entry in the table of content?

Normally, a star helps to hide things like that and I use memoir as document class which supports and helps hiding lists like \tableofcontents*, \listoffigures*, \listoftables*, ... But adding the star like that: \lstlistoflistings* does not help.

I don't want to patch any of the class file or other packages if not really needed. (I use tex seldom enough to get annoyed if I want to have the listings list in the toc and then can't remember anymore what I changed).

At the moment I use latexmk to typeset my files. And so I currently have a .latexmkrc file with a hook that delete this entry from the content before it gets added to the toc, like this:

add_cus_dep("toc", "toc", 0, "removelistingfromtoc");
sub removelistingfromtoc {
  $origin = "$_[0].toc";
  $dest = "$_[0].toc.unpatched";
  system("mv '$origin' '$dest' && grep -v '\\contentsline.*{List of Listings}' ".
         "'$dest' > '$origin'");
  return 0;
}

This removes for example the following line from the toc file:

\contentsline {chapter}{List of Listings}{}{section*.3}

(I changed the name "Listing" to "List of Listings". Btw: Any author with english as their native language might help me to critic if this "List of Listings" is a proper and common term)

1
  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Aug 26, 2012 at 20:09

1 Answer 1

6

In the memoir class, the lists seem to be defined in terms of \newlistof, and since the listings package implements \lstlistoflistings by retrofitting \tableofcontents, it should be possible to redefine it the memoir way:

\newlistof{lstlistoflistings}{lol}{\lstlistlistingname}

And then simply add the * as you said. Note that I haven't tried this myself.

3
  • 1
    Thanks a lot! Your tip did the job. The Listing is not anymore included in the TOC and I can latexmkrc hack. Here a snippet of what's left now: : \renewcommand*{\lstlistlistingname}{List of Listings} \newlistof{lstlistoflistings}{lol}{\lstlistlistingname} : \begin{document} \lstlistoflistings* :
    – Kreisquadratur
    Aug 8, 2010 at 15:13
  • Welcome to TeX.sx! Your answer was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or edit your answer.
    – Werner
    Aug 26, 2012 at 20:10
  • @grddev BTW, very good answer! Wouldn't you consider becoming more active here on TeX.SX?
    – yo'
    Aug 26, 2012 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy