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}.)

  • 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

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}
  • You had several spurious spaces in your code. – egreg Apr 6 '14 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.