TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

I'd like to have something like 5--10 in the header of an article (my document is a journal issue) if it spans the pages 5-10, and 5 (as opposed to 5--5) if it is short and fits on one page. I use \labels in some hooks when including the individual articles which insert things like \label{\articlename:beginning} and \label{\articlename:ending}. Now the question is: how to check whether the two labels fall on the same page? Currently, I use something like

\expandafter\ifx\csname r@\articlename:beginning\expandafter\endcsname
  \csname r@\articlename:ending\endcsname\else

(Quite obviously, this can be simplified using etoolbox's \ifcsequal – I'm in the process of moving to etoolbox and that's why I didn't use it before.)

My question is: is there a better way than using \csname r@ something\endcsname (or its equivalent with etoolbox), which seems to me a bit dirty-hackish? Maybe there's a ready-made package for this? (varioref comes to mind, which does similar things, but AFAIK it does not have any public interface like \iflabelsonthesamepage{label1}{label2}{true}{false}.)

share|improve this question
I am using the refcount package for this task. – Malipivo Apr 6 '14 at 9:26
@Malipivo: this is great! Can you write an answer about refcount? – mbork Apr 6 '14 at 9:28
I can't do that right now, but I can do that tomorrow, well I am sure someone will be faster with answering this nice question. – Malipivo Apr 6 '14 at 9:32
up vote 6 down vote accepted

Here's a solution based on refcount and etoolbox. I made a new command called pagespan, which prints your output wherever placed:





Should be different (dash-dash expected): \pagespan{start}{end}


Should be the same (one number expected): \pagespan{start2}{end2}
share|improve this answer
You had several spurious spaces in your code. – egreg Apr 6 '14 at 11:07

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.