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?

1 Answer 1


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:

enter image description here

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

  \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
  \State \textbf{return} $b$\Comment{The gcd is b}

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

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

  • \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. Aug 6, 2012 at 18:13

This site is temporarily in read-only mode and not accepting new answers.

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