6

In some typographic conventions page-ranges are shortened to save space, e.g. writing "1234-35" or even "1234-5" instead of "1234-1235". I would like to have a \pageref{foo}--\pageref{bar} automatically shortened to either of these formats.

I gather from the answer to Reference to page-range: can LaTeX convert "3-4" to p. 4f or "3-5" to p. 3ff ? that varioref should be able to do this, but adapting Martin Scharrer's customisation to my problem is frankly over my head.

How could I do this?

Or have I overlooked another package, that does this out of the box?

3

As there weren't any takers, I experimented my way to the following, using Martin Scharrer's example mentioned above. Improvements are very welcome!

Commenting out the first conditional results in the "1234-35"-format.

\documentclass[a3paper]{scrartcl}

\usepackage{varioref}


\makeatletter


\newcommand*{\vrefabbr}[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\numexpr(\@tempa-5)/10= \numexpr(\@tempb-5)/10\relax
            \@tempa --\the\numexpr\@tempb-(\@tempb-5)/10*10\relax
        \else
            \ifnum\numexpr(\@tempa-50)/100= \numexpr(\@tempb-50)/100\relax
                \@tempa --\the\numexpr\@tempb-(\@tempb-50)/100*100\relax
            \else
                \ifnum\numexpr(\@tempa-500)/1000= \numexpr(\@tempb-500)/1000\relax
                    \@tempa --\the\numexpr\@tempb-(\@tempb-500)/1000*1000\relax
                \else
                    \@tempa --\@tempb%
                \fi
            \fi
        \fi
    \fi
    \fi
    \fi
\endgroup
}
\makeatother

\begin{document}


ix--x: \vrefabbr{ix}{x}

ix--xiv: \vrefabbr{ix}{xiv}

xi--xiv: \vrefabbr{xi}{xiv}

xi--xv: \vrefabbr{xi}{xv}

xi--xvi: \vrefabbr{xi}{xvi}

xi--xii: \vrefabbr{xi}{xii}

xii--xiii: \vrefabbr{xii}{xiii}

xiii--xii: \vrefabbr{xiii}{xii}

xi--xi: \vrefabbr{xi}{xi}

xiii--xvi: \vrefabbr{xiii}{xvi}

xiii--xx: \vrefabbr{xiii}{xx}

xx--xxi: \vrefabbr{xx}{xxi}

xx--xxii: \vrefabbr{xx}{xxii}

xi--xxi: \vrefabbr{xi}{xxi}

xi--xx: \vrefabbr{xi}{xx}

cxix--cxvi: \vrefabbr{cxix}{cxvi}

cxix--cxii: \vrefabbr{cxix}{cxxii}

cxii--cxiii: \vrefabbr{cxii}{cxiii}

cxiii--cxii: \vrefabbr{cxiii}{cxxii}

cxi--cxi: \vrefabbr{cxi}{cxi}

cxiii--cxvi: \vrefabbr{cxiii}{cxvi}

cxiii--cxx: \vrefabbr{cxiii}{cxx}

cxx--cxxi: \vrefabbr{cxx}{cxxi}

cxx--cxxii: \vrefabbr{cxx}{cxxii}

cxi--cxxi: \vrefabbr{cxi}{cxxi}

cxi--cxx: \vrefabbr{cxi}{cxx}

cxi--cxxii: \vrefabbr{cxi}{cxxii}

mcxi--mcxvi: \vrefabbr{mcxi}{mcxvi}

mcxi--mcxii: \vrefabbr{mcxi}{mcxii}

mcxii--mcxiii: \vrefabbr{mcxii}{mcxiii}

mcxiii--mcxii: \vrefabbr{mcxiii}{mcxii}

mcxi--mcxi: \vrefabbr{mcxi}{mcxi}

mcxiii--mcxvi: \vrefabbr{mcxiii}{mcxvi}

mcxiii--mcxx: \vrefabbr{mcxiii}{mcxx}

mcxx--mcxxi: \vrefabbr{mcxx}{mcxxi}

mcxx--mcxxii: \vrefabbr{mcxx}{mcxxii}

mcxi--mcxxi: \vrefabbr{mcxi}{mcxxi}

mcxi--mcxx: \vrefabbr{mcxi}{mcxx}

mcxi--mcxxii: \vrefabbr{mcxi}{mcxxii}

cxi--mcxxii: \vrefabbr{cxi}{mcxxii}

cxi--mcxxii: \vrefabbr{cxi}{mcxxii}

xi--mcxxii: \vrefabbr{xi}{mcxxii}

ix--mcxxii: \vrefabbr{ix}{mcxxii}

mccxxxiv--mccxxxv \vrefabbr{mccxxxiv}{mccxxxv}


\setcounter{page}{9}
\section{}\label{ix}\newpage
\section{}\label{x}\newpage
\section{}\label{xi}\newpage
\section{}\label{xii}\newpage
\section{}\label{xiii}\newpage
\section{}\label{xiv}\newpage
\section{}\label{xv}\newpage
\section{}\label{xvi}\newpage
\section{}\label{xvii}\newpage
\section{}\label{xviii}\newpage
\section{}\label{xix}\newpage
\section{}\label{xx}\newpage
\section{}\label{xxi}\newpage
\section{}\label{xxii}\newpage

\setcounter{page}{111}
\section{}\label{cxi}\newpage
\section{}\label{cxii}\newpage
\section{}\label{cxiii}\newpage
\section{}\label{cxiv}\newpage
\section{}\label{cxv}\newpage
\section{}\label{cxvi}\newpage
\section{}\label{cxvii}\newpage
\section{}\label{cxviii}\newpage
\section{}\label{cxix}\newpage
\section{}\label{cxx}\newpage
\section{}\label{cxxi}\newpage
\section{}\label{cxxii}\newpage

\setcounter{page}{1111}
\section{}\label{mcxi}\newpage
\section{}\label{mcxii}\newpage
\section{}\label{mcxiii}\newpage
\section{}\label{mcxiv}\newpage
\section{}\label{mcxv}\newpage
\section{}\label{mcxvi}\newpage
\section{}\label{mcxvii}\newpage
\section{}\label{mcxviii}\newpage
\section{}\label{mcxix}\newpage
\section{}\label{mcxx}\newpage
\section{}\label{mcxxi}\newpage
\section{}\label{mcxxii}\newpage

\setcounter{page}{1234}
\section{}\label{mccxxxiv}\newpage
\section{}\label{mccxxxv}\newpage




\end{document}

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.