# Create two semi-independent lists of material, which share their counter

I successfully used \newlistof{listofA}{A}{List of As} and \newlistentry{mycounter}{A}{0} to create a list of A, whose contents gets added using \addcontentsline{A}{mycounter}{\protect\numberline{\themycounter}...}. Now I want to have a list of B's that shares the counter mycounter. I have \newlistof{listofB}{B}{List of Bs}. \newlistentry{mycounter}{B}{0} fails with a few Command ... already defined. Without it, using \addcontentsline{B}{mycounter}{...}, both lists turn out empty. What am I doing wrong?

• Can you, instead of providin a recipe with sie notes, just add a minimal working example, that we can copy/paste and compile and directly see the issue you see? Jan 29 '17 at 15:29
• I guess I should. Jan 29 '17 at 15:30
• Because, the minimal non-working example does actually work! My bad. I'll delete in a few hours. Jan 29 '17 at 15:38

## 1 Answer

With the xassoccnt package it is possible to couple multiple counters, i.e. if one of the counters is stepped, to other ones are stepped too.

Declare a counters group with some 'arbitrary' name and assign the relevant counters to them.

Using the same counter is not possible since \newlistof expects a non-existing counter, say, foo and generates a bunch of commands out of the counter name.

\documentclass{article}

\usepackage{tocloft}
\usepackage{xassoccnt}

\usepackage{blindtext}

\newcommand{\listoffooname}{List of foo environments}
\newcommand{\listoffoobarname}{List of foobar environments}

\newlistof[section]{foo}{foo}{\listoffooname}
\newlistof[section]{foobar}{foobar}{\listoffoobarname}

\DeclareCoupledCountersGroup{foofoobar}
\DeclareCoupledCounters[name=foofoobar]{foo,foobar}

% Dummy usage of the counter and generating a 'ToC' entry
\newenvironment{foo}[1]{%
\refstepcounter{foo}
\par\noindent\textbf{Foo \thefoo. #1}
\addcontentsline{foo}{foo}{\protect\numberline{\thefoo} #1}\par%
}{\hrule}

\newenvironment{foobar}[1]{%
\refstepcounter{foobar}
\par\noindent\textbf{Foobar \thefoobar. #1}
\addcontentsline{foobar}{foobar}{\protect\numberline{\thefoobar} #1}\par%
}{\hrule}

\begin{document}
\listoffoo
\listoffoobar

\section{Where foo starts}

\begin{foo}{A nice foo}

\blindtext[2]
\end{foo}

\begin{foobar}{A nice foobar}

\blindtext[2]
\end{foobar}

\begin{foo}{A nice foo again}

\blindtext[2]
\end{foo}

\begin{foo}{A nice foo again}

\blindtext[2]
\end{foo}

\begin{foobar}{A nice foobar again}

\blindtext[2]
\end{foobar}

\section{Where foo ends}

\begin{foo}{Another nice foo too}

\blindtext[1]
\end{foo}

\begin{foobar}{Another nice foobar}

\blindtext[2]
\end{foobar}

\end{document}


• Another, 'quicker' method \let\c@foobar\c@foo
– user31729
Jan 29 '17 at 16:09