6

I want to use totcount to get the number of parts and chapters in my document. To get the correct number of chapters in the presence of appendices, I use assoccnt (see totcount gives wrong chapter count when appendices present). At the same time, I need to use calc for reasons that are not important for this question. When both assoccnt and calc are used, the chapter count is incorrect. With calc commented out, the chapter count is correct. The order of the usepackage commands is immaterial. How can I keep using calc but get assoccnt to work properly?

MWE:

\documentclass{book}
\usepackage{totcount}
\usepackage{assoccnt}
\regtotcounter{part}
\newtotcounter{chaptertot}
\DeclareAssociatedCounters{chapter}{chaptertot}
\usepackage{calc}
\begin{document}
There are \total{part} parts and \total{chaptertot} chapters.
\part{I}
\chapter{A}
\chapter{B}
\part{II}
\chapter{E}
\chapter{F}
\appendix
\chapter{C}
\end{document} 
user1362373
  • 2,859
  • Correct, I was not precise enough and will amend my question. – user1362373 Sep 27 '15 at 08:22
  • @HarishKumar: Here I am... and unfortunately : There's some error, yes. I've to investigate this bug –  Sep 27 '15 at 08:37
  • Yes, the package calc does some 'weird' things I had not in mind when I wrote assoccnt about one year ago. I've to do some redesign, perhaps I can get this done today. I had a rewrite in mind using expl3 for the future. –  Sep 27 '15 at 09:22
  • 4
    I'm voting to close this question as off-topic because it's a bug in a package that has been fixed. – Gonzalo Medina Sep 27 '15 at 15:31
  • @GonzaloMedina: Yes, that's a good idea –  Sep 27 '15 at 16:37

1 Answers1

5

Edit (2017/04/16)

The newer version xassoccnt (starting from v1.2) has a combined feature of total counters and association to a driver counter), see the shorter version of the originally posted solution at the end,please.

Yes, there was a stupid bug in my package assoccnt -- it's related to the fact that counters from the driver counter reset list are stepped too, which is complete non-sense -- it was my fault.

I've made a bug-fix -- it's available from my github directory:

Edit There was another bug introduced when the first bug was done ;-)

I've uploaded assoccnt version 0.7 to CTAN. Place assoccnt.sty from that package in the local directory of your source. (I've just uploaded it to CTAN as well)

This should compile now correctly, with the correct values:

\documentclass{book}

\usepackage{totcount}
\usepackage{calc}
\usepackage{assoccnt}

\regtotcounter{part}
\newtotcounter{chaptertot}
\newtotcounter{tabletot}

\DeclareAssociatedCounters{chapter}{chaptertot}
\DeclareAssociatedCounters{table}{tabletot}



\begin{document}

There are \total{part} parts and \total{chaptertot} chapters and \total{tabletot} tables.
\part{I}
\chapter{A}

\begin{table}
  \caption{First table}
\end{table}

\begin{table}
  \caption{Second table}
\end{table}


\chapter{B}
\part{II}
\chapter{E}
\chapter{F}
\appendix
\chapter{C}

\end{document} 

enter image description here

\documentclass{book}

\usepackage{totcount}
\usepackage{calc}
\usepackage{xassoccnt}

\regtotcounter{part}

\DeclareTotalAssociatedCounters{chapter}{chaptertot}
\DeclareTotalAssociatedCounters{table}{tabletot}



\begin{document}

There are \total{part} parts and \TotalValue{chaptertot} chapters and \TotalValue{tabletot} tables.
\part{I}
\chapter{A}

\begin{table}
  \caption{First table}
\end{table}

\begin{table}
  \caption{Second table}
\end{table}


\chapter{B}
\part{II}
\chapter{E}
\chapter{F}
\appendix
\chapter{C}

\end{document} 
  • So you were busy for the day :) –  Sep 27 '15 at 22:40
  • @HarishKumar: No, not all. The bug was quite easy to find ;-) –  Sep 28 '15 at 03:53
  • Not sure how to best handle this because my question was put on hold, but for the benefit of anybody else who might stumble across this problem, I just wanted to note that I contacted Christian directly via email because I could not reproduce the behavior with the new assoccnt.sty. He's since updated it once more, which has fixed the problem I reported. – user1362373 Sep 29 '15 at 06:14