Paste number 147711: untitled

Paste number 147711: untitled
Pasted by: gsl
When:6 years, 4 months ago
Share:Tweet this! | http://paste.lisp.org/+35Z3
Channel:None
Paste contents:
Raw Source | XML | Display As
\documentclass[12pt]{book}
\usepackage{assoccnt}

\usepackage{xpatch}
\newcounter{totalsections}[chapter] % Does not work with `chapter*`

% Automatically provide for resetting of the section counter each time 
%`\chapter` or `\chapter*` is used -- in this setup this is requested.
\xpretocmd{\chapter}{\setcounter{totalsections}{0}}{}{}


\DeclareAssociatedCounters{section}{totalsections}

\begin{document}
\chapter*{First Chapter}

The total number of sections in this chapter should be 3.

There \number\value{totalsections} sections in this chapter


\section{First Section}
First text

\section{Second Section}
Second text

\section{Third Section}
Third text


\chapter*{Last Chapter}

\section{First Section}
First text

There \number\value{totalsections} sections in this chapter

\end{document}

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.