Take the 2-minute tour ×
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.

The varioref package can also cite page ranges by defining a reference to 2 different labels with \vpagerefrange. I did not find information about an option which allows to typeset

  • "5-6" as "5f"
  • and every range spanning more than 2 pages to "5ff"

Is there a package or an option which allows to do that automatically?

share|improve this question
2  
Take a look at the latest development version of cleveref. –  Martin Schröder Oct 19 '11 at 6:38

1 Answer 1

The varioref package provides \vrefpagenum{<macro>}{<ref>} which stores the page number of the given reference in the macro so that users can define their own vario-style macros. There is an example on page 2f ;-) of the manual.

Here an example implementation. The tests could be optimized a little more.

\documentclass{article}

\usepackage{varioref}

\makeatletter

\newcommand*{\vrefff}[2]{%
    \begingroup
    \vrefpagenum\@tempa{#1}%
    \vrefpagenum\@tempb{#2}%
    \if ?\@tempa\else
    \if ?\@tempb\else
    \ifx\@tempa\@tempb
        \@tempa%
    \else
        \ifnum\@tempa>\@tempb\relax
            \let\@tempc\@tempb
            \let\@tempb\@tempa
            \let\@tempa\@tempc
        \fi
        \ifnum\@tempb=\numexpr\@tempa+1\relax\relax
            \@tempa f%
        \else
            \@tempa ff%
        \fi
    \fi
    \fi
    \fi
    \endgroup
}
\makeatother

\begin{document}

i-vi: \vrefff{i}{vi}

i-ii: \vrefff{i}{ii}

ii-iii: \vrefff{ii}{iii}

iii-ii: \vrefff{iii}{ii}

i-i: \vrefff{i}{i}

iii-vi: \vrefff{iii}{vi}

\section{}\label{i}\newpage
\section{}\label{ii}\newpage
\section{}\label{iii}\newpage
\section{}\label{iv}\newpage
\section{}\label{v}\newpage
\section{}\label{vi}\newpage

\end{document}

Results in:

i-vi: 1ff
i-ii: 1f
ii-iii: 2f
iii-ii: 2f
i-i: 1
iii-vi: 3ff
share|improve this answer

Your Answer

 
discard

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.