I have started using Latex to do our company manuals, everything seemed to be going well, apart from the odd hiccup.
Part of these manuals have tables of information, one of the rows needs to include the number of rows in the particular table.
This all seemed to work well using the totcount package. However after more work was done placing the tables in a macro, the whole table and totcount affair fell apart.
After investigating it further I have come up with a MWE that replicates the basic idea/problem, but simplified a lot.
Code: Select all
\documentclass[11pt,portrait]{article}
\usepackage{totcount}
\newcommand\currentProtocol{p1}
\newcommand{\createCounter}[1]
{
\newtotcounter{mbc#1 Ac}
\setcounter{mbc#1 Ac}{0}
creating counter:'mbc#1 Ac'
}
\newcommand{\addToCounter}[2]
{
\addtocounter{mbc#1 Ac}{#2}
incrementing counter:'mbc#1 Ac' by #2
}
\newcommand{\printCounter}[1]
{
total of the counter = \total{mbc#1 Ac}
}
\begin{document}
\renewcommand\currentProtocol{p1}
protocol: \currentProtocol
\createCounter{\currentProtocol}
\addToCounter{\currentProtocol}{1}
\addToCounter{\currentProtocol}{10}
\printCounter{\currentProtocol}
\rule{\linewidth}{1pt}
\renewcommand\currentProtocol{p4}
protocol: \currentProtocol
\createCounter{\currentProtocol}
\addToCounter{\currentProtocol}{4}
\addToCounter{\currentProtocol}{40}
\printCounter{\currentProtocol}
\rule{\linewidth}{1pt}
\newtotcounter{mbcNEWONE Ac}
\end{document}
I believe the problems lies in the fact that as there could be lots of tables in my document I am having to create new total counters on the fly with a name given by the value of the macro
\currentProtocol
. It is as if the counters are only generated using the final value of the macro \currentProtocol
.Looking at the .aux file this does appear to be the case as I am guessing there should be a line in that file for each counter:
Code: Select all
\relax
\expandafter\ifx\csname c@mbcp4 Ac@totc\endcsname\relax\newcounter{mbcp4 Ac@totc}\fi\setcounter{mbcp4 Ac@totc}{44}
\expandafter\ifx\csname c@mbcp4 Ac@totc\endcsname\relax\newcounter{mbcp4 Ac@totc}\fi\setcounter{mbcp4 Ac@totc}{44}
\expandafter\ifx\csname c@mbcNEWONE Ac@totc\endcsname\relax\newcounter{mbcNEWONE Ac@totc}\fi\setcounter{mbcNEWONE Ac@totc}{0}
Does anyone have any ideas on how to resolve or get round this?
I did think that maybe I could do it with luatex but unfortunately I am using a landscape page with hyperlinks on nodes which appears to be a known bug, so that is out of the question.
Many thanks in advance.