There seems to be some negative interaction between Koma Script (using version 3.11a) and the lstdoc package in my example document. The MWE works nicely when I comment out \usepackage{lstdoc} but when I include it the formatting of the table of contents is messed up. Here is the example document:

\documentclass[
a4paper,
titlepage
]{scrbook}

\usepackage{lstdoc}

\begin{document}
\tableofcontents

\section{test1}
test test
\end{document}


The output without lstdoc looks as follows

whereas with the package included this happens:

Is there any workaround to this problem? I want to the line because I am using the alternative to the glossaries package from this question which requires the lstdoc package. I noticed that hyperref is also pulled in if lstdoc is used but hyperref alone does not cause any problems.

-

The problem is that lstdoc.sty redefines some of the \l@... family of commands in charge of typesetting the entries for the sectional units in the ToC. For example, \l@section is defined in lstdoc.sty as

\newcommand*\l@section[2]{%
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup}


whereas the definition for \l@section in scrbook.cls is

\newcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{2.3em}}


In order to recover the original definitions you can redefine the \l@... commands in the preamble of your document to be the ones used for scrbook.cls. So for example:

\documentclass[a4paper,titlepage]{scrbook}
\usepackage{lstdoc}

\makeatletter
\renewcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{2.3em}}
\makeatother

\begin{document}
\tableofcontents

\section{test1}
test test
\end{document}


produces

which is (up to the colored hyperlink) the original formatting. Similar redefinitions will have to be made for some of the other \l@... commands corresponding to the other sectional units that will go to the ToC and which \l@... commamds are redefined by lstdoc.sty.

The following example code shows these redefinitions necessary to obtain the original formatting for ToC entries from \chapter down to \subparagraph:

\documentclass[a4paper,titlepage]{scrbook}
\usepackage{lstdoc}

% all sectional units will be numbered and will go to the ToC
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\makeatletter
\renewcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{2.3em}}
\renewcommand*\l@subsection{\bprot@dottedtocline{2}{3.8em}{3.2em}}
\renewcommand*\l@subsubsection{\bprot@dottedtocline{3}{7.0em}{4.1em}}
\makeatother

\begin{document}
\tableofcontents

\chapter{Test Chapter}
\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubsection}
\paragraph{Test Paragraph}
\subparagraph{Test Subparagraph}

\end{document}


-
Thank you! Now the table of contents is restored to it's old beauty. – Alexander Jul 19 '12 at 9:52