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

What I want to do is the following:

I want to refer to an earlier block of text. I could do this by using the \label and the \ref commands like so:

\label{x} Lorem ipsum dolor sit amet, consectetur adipiscing elit.

See page \ref{x}.

This would create something like "See page 1" out of the second line of code.

However, let's say the sentence above, in the first line of code, spans over more than one page. Then I would like the readout to be "See pages 1-2". Now I could solve this by doing the following:

\label{x} Lorem ipsum dolor sit amet, consectetur adipiscing elit. \label{y}

See pages \ref{x}-\ref{y}.

This would create something like "See pages 1-2" out of the second line of code.

However, this is not flexible enough. If the sentence doesn't span over several pages, I would end up with something like "See pages 1-1", something I definitely wouldn't want.

So, I guess you can see my dilemma here. Is there any way for me to do what I want?

share|improve this question
a tip: you can use backticks ` to mark your inline code as I did in my edit. – Hendrik Vogt Mar 16 '11 at 8:52
Thanks for the tip! – Speldosa Mar 16 '11 at 12:02
up vote 8 down vote accepted

This would be a solution using the varioref package, as Martin mentioned:



See \vpagerefrange{text1start}{text1stop} and \vpagerefrange{text2start}{text2stop}


It's output in this case:

enter image description here

share|improve this answer
This was great. I'll use this for the time being and switch over to Martin's suggestion if I need to have greater control over my output. – Speldosa Mar 18 '11 at 15:07
@Speldosa: Note that there seem to be some problems when the varioref package is used together with the hyperref package. To quote the hyperref ReadMe: “Perhaps you are lucky and some of the features of varioref work […]” – mhp Sep 1 '11 at 8:17
@mhp: Thanks for the heads up. I'll be on the lookout for problems. – Speldosa Sep 2 '11 at 7:29

The standard \labels are normally only for sectioning commands and captions etc., not for pieces of text. Also its implementation is redefined by packages like hyperref so it is difficult to use them and ensuring 100% compatibility with existing packages.

Instead you could define an own label macro like \textlabel and then \textref which takes two arguments and checks if both refer to the same page. The following code does this. A possible improvement would be to non hard-code the 'page' text but use a macro which can be changed, e.g. to a different language.

    % Write label which holds current page
    % Also add a normal label to be able to use `hyperref`s `\pageref` later
    % Get saved label values:
    \expandafter\let\expandafter\labela\csname textlabel@#1\endcsname
    \expandafter\let\expandafter\labelb\csname textlabel@#2\endcsname

See \textref{a}{b} and \textref{x}{y}.


Edit: Added use of \pageref in the final output. The varioref package might also be of interest.

share|improve this answer
Why do you define a new type of label instead of simply comparing the two original \pageref's? E.g. \ifthenelse{\equal{\pageref{x}}{\pageref{y}}}{see page \ref{x}}{see page \ref{x} to \ref{y}} – Ulrike Fischer Mar 16 '11 at 9:04
@Ulrike: I do this to be independent of redefinitions of \pageref e.g. by hyperref. Because its \pageref isn't fully expandable \ifthenelse doesn't work (for me). I like to access the page number directly without any typesetting or hyperref material. – Martin Scharrer Mar 16 '11 at 9:44
I don't have any problems with the \ifthenelse even if I load hyperref. – Ulrike Fischer Mar 16 '11 at 11:33
@Ulrike: Yes, you are right, \ifthenelse works fine with \pageref. My bad, I had two minor errors in my test file which caused the trouble. I must look on the source code of ifthen.sty to learn how it expands \pageref successfully. A simple \edef fails. You should post your code as an answer (but replace \ref with \pageref). – Martin Scharrer Mar 16 '11 at 12:05
I prefer meep.meep's sollution because of its simpleness but your's seem great if I want to customize the output further. – Speldosa Mar 18 '11 at 15:08

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.