# convert outcome of reference to regular number

Is it possible to transform the outcome of a reference (e.g., a line number) to a regular number that I can use in a calculation? I have this (and works fine):

\FPeval{\result}{clip(5+6)} $\result$


Now I want to do a calculation involving \lineref{myline}. However,

\FPeval{\result}{clip(5+\lineref{myline})} $\result$


doesn't work because \lineref{myline} is not recognized as a number, I guess.

Any ideas?

-

You easiest is to use the refcount package which allows for expandable versions of functions to retrieve counter numbers. Here's a small example where line number is extracted from an algorithm:

\documentclass{article}
\usepackage{refcount}% http://ctan.org/pkg/refcount
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{fp}% http://ctan.org/pkg/fp
\begin{document}

\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$\label{myline}% This is line 6 in the algorithm
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}

Result: \FPeval{\result}{clip(5+\getrefnumber{myline})} $\result$
\end{document}​


\getrefnumber{<label>} retrieves the counter associated with <label>. For calculation of page references, an analogous \getpagerefnumber is provided.

-
simply perfect, thank you! – john Jul 18 '12 at 1:26
\getrefnumber is expandable, therefore it cannot notify LaTeX that the reference is used &mdash; LaTeX wants to warn because of undefined references. Therefore package refcount provides \refused that tells LaTeX about the reference. \refused{myline} is then used outside the expandable context of \FPeval. – Heiko Oberdiek Aug 6 '12 at 18:13