Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

1 Answer 1

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.

share|improve this answer
    
That's right Ahmed Musa. –  projetmbc Feb 15 '12 at 10:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.