TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
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

Your Answer


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.