# Memoir: skip section numbers, make subsection numbers continuous within chapter

Can the memoir class create a reference book whose table of contents would look like this:

Chapter 1. Animals

Mammals
Cows ................... 1.000
Bulls .................. 1.001
Calves ................. 1.002
Amphibians
Frogs .................. 1.003
Turtles ................ 1.004
Newts .................. 1.005

Chapter 2. Plants

Trees
Pines .................. 2.000
Oaks ................... 2.001
Maples ................. 2.002
Shrubs
Brambles ............... 2.003
Brooms ................. 2.004
Lilacs ................. 2.005


In particular I wish to:

1. Suppress section numbers both in the text and the table of contents.
2. Make subsection numbers continuous within a chapter.
3. Present the subsection numbers in the X.YYY format where X = chapter number.
4. Move the subsection numbers out to the margins. The idea is to use them instead of page numbers.
• Not really no. The section number and title arrives at the toc as a single unit. It may be possible to separate them, but will be quite hard – daleif Dec 28 '13 at 21:35

This is a basic solution. You still have to modify the parameters for the table of contents for suppressing the chapter page number and the dots for the sections.

\documentclass{memoir}

\counterwithout{subsection}{section} % subsection is not reset with section
\counterwithin{subsection}{chapter}  % subsection is reset with chapter

% subsection numbers are X.YYY
\renewcommand{\thesubsection}{\thechapter.\threedigits{subsection}}
\newcommand{\threedigits}[1]{%
\ifnum\value{#1}<100 0\fi
\ifnum\value{#1}<10 0\fi
\arabic{#1}%
}

\setsecnumformat{\csname #1secnumformat\endcsname}
% no numbering shown for section titles
\newcommand\sectionsecnumformat{}
% numbering shown for subsection titles

% modify the TOC macros not to use the section number
\makeatletter
\let\memoir@l@section\l@section
\def\l@section#1#2{%
\mihai@gobble@number#1\@nil
}
\def\mihai@gobble@number\numberline#1#2\@nil{%
\memoir@l@section{#2}{}%
}
% modify the TOC macros to use the subsection number as the page number
\let\memoir@l@subsection\l@subsection
\def\l@subsection#1#2{%
\mihai@get@number#1\@nil
}
\def\mihai@get@number\numberline#1#2\@nil{%
\memoir@l@section{#2}{#1}%
}
\makeatother

\settocdepth{subsection}
\setsecnumdepth{subsection}

\begin{document}
\frontmatter
\makeatletter\show\l@section
\tableofcontents*
\mainmatter
\chapter{Animals}
x
\section{Mammals}
x
\subsection{Cows}
x
\subsection{Bulls}
x
\subsection{Calves}
x

\section{Amphibians}
x
\subsection{Frogs}
x
\subsection{Turtles}
x
\subsection{Newts}
x

\chapter{Plants}
x
\section{Trees}
\subsection{Pines}
x
\subsection{Oaks}
x
\subsection{Maples}
x
\section{Shrubs}
x
\subsection{Brambles}
x
\subsection{Brooms}
x
\subsection{Lilacs}
x

\end{document}

• Wow. That's quite a hack for a 'basic solution'! ;-) Many thanks, egreg. The compiler gives me an error in the part modifying the TOC macros, but at least thanks to you I have something to play with and learn along the way. – Mihai Nagy Dec 29 '13 at 20:12