[Tex/LaTex] How to calculate a percentage and use result in progressbar

calculationscounters

With the progressbar package, I want to show bars on pages depending on a counter.

Progressbar works like:

\progressbar{0.7}

I use the calc package anyway, so I thought it should be easy to calculate the ratio for the bar for each page, like this:

\newcounter{y}
\setcounter{y}{5 / 1}  % check that calc is working

\newcounter{total}
\setcounter{total}{30}

But, none of the below seem to work:

\progressbar{\value{y}/\value{total}}\\
\progressbar{\value{y} / \value{total}}\\
\progressbar{\they{}/\thetotal{}}\\

I get the error: Illegal unit of measure (pt inserted).

What am I doing wrong?

Best Answer

Package progessbar uses packages calc's \real which accepts only a decimal number, not a ratio. Package calc provides \ratio but unfortunately it seems \real{\ratio{\lenA}{\lenB}} is not legal syntax.

Hence, in despair, you may use:

\makeatletter
\expandafter\progressbar\expandafter {\strip@pt \dimexpr \value{y}pt/\value{total}\relax}
\makeatother

This should be wrapped in a macro, naturally.

Related Question