I use the glossaries and minitoc packages. Minitocs are generated for all glossaries printed in the table of content, eg with the toc option for the glossaries package. When one prints the glossaries before the chapters, the not-yet printed minitoc of the glossaries are printed instead of the chapter ones, effectively offsetting the minitocs with regards to the chapters.
Manually, this can be solved by offsetting the mtc counter of the minitocs, eg \addtocounter{mtc}{2} if there are 2 glossaries (acronyms + actual glossary for example).
I'm trying to automatically do that shift to embed it in a package. First is getting the number of glossaries. The glossaries package define the macro \@glo@types as a comma-separated list of the names of the glossaries defined.
Thus, I can print the number of glossaries with:
\expandafter\listLength\expandafter{\@glo@types}
where the \listLength macro, inspired by this answer and relying on etoolbox, is:
\makeatletter
\newcounter{listlength@cnt}
\newcommand*{\listlength@add}[1]{\stepcounter{listlength@cnt}}
\newcommand*{\listLength}[1]{%
\setcounter{listlength@cnt}{0}%
\forcsvlist{\listlength@add}{#1}%
\thelistlength@cnt%
}
\makeatother
However, when I try to use the value in the addtocounter command, it doesn't work anymore. For the same example:
\expandafter\listLength\expandafter{\@glo@types}prints 2\addtocounter{mtc}{\expandafter\listLength\expandafter{\@glo@types}}outputs a "Missing number" error. I tried with different combinations of\expandafterbefore/in that command, but as you might have picked up, I have troubles with the expansion process.
So, how can I offset a counter to a value derived by expansion?
Here is a MWE:
\documentclass{report}
\usepackage[nohints]{minitoc}
\usepackage{etoolbox}
\usepackage[acronym,xindy,toc]{glossaries}
\makeglossaries
\begin{filecontents}{glossary.tex}
\newacronym{nraa}{NRAA}{Not Really An Acronym}
\newglossaryentry{stuff}{
name={stuff},
description={a test}%
}
\end{filecontents}
\loadglsentries{glossary}
% macro to count args of csv-list
\makeatletter
\newcounter{listlength@cnt}
\newcommand*{\listlength@add}[1]{\stepcounter{listlength@cnt}}
\newcommand*{\listLength}[1]{%
\setcounter{listlength@cnt}{0}%
\forcsvlist{\listlength@add}{#1}% % from etoolbox
\thelistlength@cnt%
}
\makeatother
\begin{document}
\dominitoc % Generating mini-toc
\tableofcontents
\glsaddall % adding all glossary entries for the test
\printglossary[type=\acronymtype]
\printglossary[type=main]
\addtocounter{mtc}{2} % manual offset
\newpage
\makeatletter
number of glossaries:
\expandafter{\expandafter\listLength\expandafter{\@glo@types} % prints 2
%\addtocounter{mtc}{\expandafter\listLength\expandafter{\@glo@types}}
% results in error, missing number
\makeatother
\chapter{chap1}
chapter's toc is:
\minitoc
Content is:
\section{s1}
\subsection{s11}
\end{document}

\documentclass, including packages, etc.), to help those wanting to help you. – Steven B. Segletes Apr 23 '15 at 15:39expl3's\exp_args:no:) – Sean Allred Apr 23 '15 at 16:28