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}
3
  • Please provide the link where you took the solution from, so that we can see the original.
    – Ahmed Musa
    Feb 14, 2012 at 18:18
  • Just click on "This page" in my message.
    – projetmbc
    Feb 14, 2012 at 19:41
  • It would help if you cold show the resulting output.
    – user10274
    Feb 14, 2012 at 22:20

1 Answer 1

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.

1
  • That's right Ahmed Musa.
    – projetmbc
    Feb 15, 2012 at 10:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .