# How to use \ifnum for arguments (expanding macros)?

I want to count my section's, figure's etc. using the totcount package. To get a general useable template I want to show only counters which are larger than zero. But it seems that total{counter} would not evaluated.

I tried the following but none of the both hide calls generate any output:

\documentclass{article}

\usepackage{totcount}

\regtotcounter{section}

\newcommand{\hide}[2] {
\ifnum0<0#1
#2
\fi
}

\begin{document}

\section{Section One}
\section{Section Two}
\section{Section Three}

% should print "Sections: 3" but doesn't show anything
\hide{\total{section}}{Sections: \total{section}}
% should print nothing
\hide{\total{figure}}{Figures: \total{figure}}

\end{document}


If I wrote the numbers manually it works like expected:

% prints "Sections: 3"
\hide{3}{Sections: \total{section}}
% prints nothing
\hide{0}{Figures: \total{figure}}


What am I doing wrong? Is there a better approach to get the expected result?

-
Welcome to TeX.SX! –  Papiro Jun 29 '13 at 23:13

Macro \total of package is not expandable, it starts with a definition. Use \totvalue instead, it maps the name to the internal counter register that can be used with \ifnum. From totcount.sty:

%%   Returns the numeric total value of a registered total counter that is
%%   passed as argument. Note that if the counter's value is not yet computed
%%   (at the first time \LaTeX\ runs on the document) this macro returns |-1|.
\newcommand\totvalue[1]{\value{#1@totc}}


Example file (I have added the missing \regtotcounter{figure}):

\documentclass{article}

\usepackage{totcount}

\regtotcounter{section}
\regtotcounter{figure}

\newcommand{\hide}[2] {
\ifnum\totvalue{#1}>0
#2
\fi
}

\begin{document}

\section{Section One}
\section{Section Two}
\section{Section Three}

% should print "Sections: 3"
\hide{section}{Sections: \total{section}}
% should print nothing
\hide{figure}{Figures: \total{figure}}

\end{document}


-
Thanks, I have to read the documentation more carefully. –  sgibb Jun 30 '13 at 7:36