1

In this page, I've found one way to display one counter only if it is used at least two times.

The problem with this solution is that it doesn't work with two counters. Is there a way to allow this kind of feature ?

\documentclass{article}
    \makeatletter
        \newcommand{\defineoneshotcounter}[1]{%
            \newcounter{#1}
            \newcounter{#1@helper}
            \expandafter\newcommand\csname show#1\endcsname[1][\arabic]{%
                \stepcounter{#1}%
                \stepcounter{#1@helper}%
                \@ifundefined{#1@reset@\the\csname c@#1@helper\endcsname}{##1{#1}}{}%
            }
            \@namedef{reset#1}{%
                \ifnum\csname c@#1\endcsname=1\if@filesw
                \immediate\write\@auxout{%
                    \string\global\string\@namedef{#1@reset@\the\csname c@#1@helper\endcsname}{}%
                }%
                \fi\fi
                \setcounter{#1}{0}%
            }
        }
    \makeatother

    \defineoneshotcounter{FirstCounter}
    \newcommand{\FirstCounterStyle}[1]{\{\arabic{#1}\}}

    \defineoneshotcounter{SecundCounter}
    \newcommand{\SecundCounter}[1]{\{\arabic{#1}\}}

    \setlength{\parindent}{0cm}


\begin{document}

\section{First counter}

TEST : \showFirstCounter,
TEST : \showFirstCounter,
TEST : \showFirstCounter,
RESET : \resetFirstCounter

TEST : \showFirstCounter[\alph],
TEST : \showFirstCounter[\alph],
RESET : \resetFirstCounter

TEST : \showFirstCounter,
RESET : \resetFirstCounter

TEST : \showFirstCounter[\FirstCounterStyle],
TEST : \showFirstCounter[\FirstCounterStyle],
TEST : \showFirstCounter[\FirstCounterStyle],
TEST : \showFirstCounter[\FirstCounterStyle],
RESET : \resetFirstCounter

TEST : \showFirstCounter,
RESET : \resetFirstCounter

TEST : \showFirstCounter,
TEST : \showFirstCounter,
RESET : \resetFirstCounter


\section{Secund counter}

TEST : \showSecundCounter,
TEST : \showSecundCounter,
TEST : \showSecundCounter,
RESET : \resetSecundCounter

TEST : \showSecundCounter[\alph],
TEST : \showSecundCounter[\alph],
RESET : \resetSecundCounter

TEST : \showSecundCounter

\end{document}
projetmbc
  • 13,315

1 Answers1

2

The second solution at Hiding a counter if it is only displayed only one time works for several counters defined at the same time or different times.

@Marc van Dongen: See projetmbc's output below. enter image description here

I guess he's saying that the last \showSecundCounter shouldn't have produced any result, because it was called only once after SecundCounter was reset.

Ahmed Musa
  • 11,742