Document ClassesCustom List of Listings (listings package) possible?

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
l0calh05t
Posts: 19
Joined: Fri Jul 04, 2008 2:57 pm

Custom List of Listings (listings package) possible?

Post by l0calh05t »

I have all my Listings in an Appendix, and I want to add a list of listings at the beginning of that appendix. Obviously this means it should not be section level (rather subsection or no title at all), nor should it appear in the toc. By default (or at least in combination with the other packages I use), it appears in the toc and is considered an unnumbered section. Is there any way to change this?

Here's the list of packages I use:

Code: Select all

\documentclass[fontsize=11pt,paper=a4,titlepage,liststotoc,bibtotoc,twoside,BCOR=10mm]{scrartcl}

\usepackage[utopia]{mathdesign}
\usepackage[no-math]{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{ngerman}
\usepackage{amsmath}
\usepackage{array}
\usepackage{color}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{pdfpages}
\usepackage{ragged2e}
\usepackage{hyperref} % must be last package, except for cite packages
\usepackage{cite}
\usepackage{bibgerm}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
Stefan Kottwitz
Site Admin
Posts: 10283
Joined: Mon Mar 10, 2008 9:44 pm

Custom List of Listings (listings package) possible?

Post by Stefan Kottwitz »

Hi,

here's a quick workaround, you could place this where you called \lstlistoflistings:

Code: Select all

\newcommand\stdsection{}
\newcommand\stdaddtocontents{}
\let\stdsection\section
\let\stdaddtocontents\addtocontents
\def\section*#1{}
\renewcommand\addtocontents[3]{}
\lstlistoflistings
\let\section\stdsection
\let\addtocontents\stdaddtocontents
I just disabled \section* and \addtocontents temporarily.

Stefan
LaTeX.org admin
l0calh05t
Posts: 19
Joined: Fri Jul 04, 2008 2:57 pm

Re: Custom List of Listings (listings package) possible?

Post by l0calh05t »

That almost worked, but it still gets added to the hyperref pdf bookmarks.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10283
Joined: Mon Mar 10, 2008 9:44 pm

Custom List of Listings (listings package) possible?

Post by Stefan Kottwitz »

If you want to avoid this bookmark you could disable \addcontentsline too. It should be enough to do this instead of disabling \addtocontents, the workaround changes to:

Code: Select all

\newcommand\stdsection{}
\newcommand\stdaddcontentsline{}
\let\stdsection\section
\let\stdaddcontentsline\addcontentsline
\def\section*#1{}
\renewcommand\addcontentsline[3]{}
\lstlistoflistings
\let\section\stdsection
\let\addcontentsline\stdaddcontentsline
Stefan
LaTeX.org admin
l0calh05t
Posts: 19
Joined: Fri Jul 04, 2008 2:57 pm

Custom List of Listings (listings package) possible?

Post by l0calh05t »

Many thanks, it works as desired now.

I changed it to

Code: Select all

\newcommand\stdsection{}
\newcommand\stdaddcontentsline{}
\let\stdsection\section
\let\stdaddcontentsline\addcontentsline
\let\section\subsection
\renewcommand\addcontentsline[3]{}
\lstlistoflistings
\let\section\stdsection
\let\addcontentsline\stdaddcontentsline
to get a subsection style heading though.
Post Reply