Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I was trying to emulate the style of the long table of contents in the memoir manual. Specifically, the effect I want to achieve is to have all subsections names and page numbers in the same paragraph, eliminating the dots. Refer to the image below, which is a screenshot from the memoir manual. An example of the effect I want to achieve, paragraphing of subsections

Page 171 of the memoir manual includes code to achieve this effect. However, when I try to compile myself, there is always a mysterious error message, even though hitting enter every time this error occurs will still produce a correct document:

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

Here is a minimal example that illustrates this:

\documentclass{memoir}
\usepackage{kantlipsum}
\usepackage[bookmarks]{hyperref}

\makeatletter
\newcommand*{\setupparasubsecs}{%
  \let\oldnumberline\numberline
  \renewcommand{\l@subsection}[2]{%
      \def\numberline####1{\textit{####1}~}%
      \leftskip=\cftsubsectionindent
      \rightskip=\@tocrmarg
      \parfillskip=\fill
      \ifhmode ,\ \else\noindent\fi
      \ignorespaces
      {\cftsubsectionfont ##1}~{\cftsubsectionpagefont##2}%
       \let\numberline\oldnumberline\ignorespaces
  }
}
\AtEndDocument{\addtocontents{toc}{\par}}
\makeatother

\begin{document}
\maxtocdepth{subsection}
\setupparasubsecs
\tableofcontents
\chapter{Research}
\kant[1-3]
\section{Survey}
\kant[1-3]
\subsection{Methodology}
\kant[1-3]
\subsection{Hypothesis}
\kant[1-3]
\subsection{Results}
\kant[1-3]
\chapter{Discussions}
\section{Survey}
\subsection{Implications \& Consequences}
\kant[1-3]
\subsection{Flaws \& Limitations}
\kant[1-3]
\chapter{Conclusions}
\kant[1-3]
\end{document}

I suspect it could be a problem of not ending a paragraph when typesetting the next chapter heading. Meanwhile, there is also some spacing problems before the comma, which unfortunately isn't replicated in the above example.

I am using the latest TeXLive 2012 distribution and compiling with LuaLaTeX, but the problem is also reproducible in pdfLaTeX.

EDIT: I looked at memsty.sty and found the actual code contains:

\newcommand*{\setupparasubsecs}{%
  \let\oldnumberline\numberline
  \renewcommand{\l@subsection}[2]{
    \ifnum\c@tocdepth > 1\relax
      \def\numberline####1{\textit{####1}~}%

      [snip]

      {\cftsubsectionfont ##1}~{\cftsubsectionpagefont##2}%
       \let\numberline\oldnumberline\ignorespaces
    \fi}}

\AtEndDocument{\addtocontents{toc}{\par}}%%% OK

It differs from the code in memman.pdf by an additional \ifnum. Apparently in a later revision Peter Wilson decides to add this but it is not reflected in the manual itself. However the \ifnum does not seem to eliminate the error, or cause some visual changes to the document though.

EDIT 2: I tried to compile the memoir manual and it didn't have this error. I guess I probably left out something in my code.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

As you said, you need to end the paragraph. One way would be:

\newcommand*{\setupparasubsecs}{%
  \let\oldnumberline\numberline
  \renewcommand{\l@subsection}[2]{%
      \def\numberline####1{\textit{####1}~}%
      \leftskip=\cftsubsectionindent
      \rightskip=\@tocrmarg
      \parfillskip=\fill
      \ifhmode ,\ \else\noindent\fi
      \ignorespaces
      {\cftsubsectionfont ##1}~{\cftsubsectionpagefont##2}%
       \let\numberline\oldnumberline\ignorespaces
  }
\let\old@l@section\l@section
\def\l@section{\par\old@l@section}
\let\old@l@chapter\l@chapter
\def\l@chapter{\par\old@l@chapter}
}
share|improve this answer
    
Wow, that was fast and accurate. Helpful for people who don't understand LaTeX internals. Thank you. –  kccqzy Aug 4 '12 at 9:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.