From e359d674f651a5bec03fb71d8ce17c22fca3b6dc Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 17 Dec 2009 23:52:16 +0000 Subject: pagerange 0.3 (16dec09) git-svn-id: svn://tug.org/texlive/trunk@16438 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/pagerange/README | 2 +- .../doc/latex/pagerange/pagerange-guide.pdf | Bin 91597 -> 82727 bytes .../doc/latex/pagerange/pagerange-guide.tex | 82 ++++++------- .../tex/latex/pagerange/pagerange-guide.cfg | 6 +- .../texmf-dist/tex/latex/pagerange/pagerange.sty | 129 ++++++++++++--------- 5 files changed, 117 insertions(+), 102 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/pagerange/README b/Master/texmf-dist/doc/latex/pagerange/README index b80be0a1d74..878888e88d7 100644 --- a/Master/texmf-dist/doc/latex/pagerange/README +++ b/Master/texmf-dist/doc/latex/pagerange/README @@ -1,4 +1,4 @@ -This is the README file for 'pagerange' package, version 0.2. +This is the README file for 'pagerange' package, version 0.3. When a given page range xx-yy (simple/plain characters) or \pages (command token, eg, \def\pages{xx-yy}) is submitted to the macro diff --git a/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.pdf b/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.pdf index c73d3c0168a..c0e5e1e1767 100644 Binary files a/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.pdf and b/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.pdf differ diff --git a/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.tex b/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.tex index 6c1a330b496..db78f40c054 100644 --- a/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.tex +++ b/Master/texmf-dist/doc/latex/pagerange/pagerange-guide.tex @@ -2,9 +2,12 @@ \InputIfFileExists{pagerange-guide.cfg}{}{% \errmessage{No file pagerange-guide.cfg}} \pagestyle{fancyplain} + \begin{document} +\label{page:first} + \MakeShortVerb{\+} -\title{\textbf{The {\tt pagerange} Package}\\[1ex] Version 0.2} +\title{\textbf{The {\tt pagerange} Package}\\[1ex] Version 0.3} \author{Ahmed Musa\\[.5ex]University of Central Lancashire\\ Preston, United Kingdom\\[1ex]\email{a.musa@rocketmail.com} } @@ -19,31 +22,32 @@ When a given page range +xx-yy+ (simple/plain characters) or +\pages+ (control s If you specify a range consisting of a hyphen (or any tie) but with one or two empty page numbers, the following will happen: \begin{compactenum}[a)] -\item a range of the form ``+-34+'' is taken to mean pages~1 to 34; -\item a range of the form ``+12-+'' is taken to mean page~12 to last page; -\item a range of the form ``+-+'' (\ie, only hyphen and no pages) is taken to mean page~1 to the last page. +\item A range of the form ``+-34+'' is taken to mean pages +defaultfirstpage+ to 34. The default value of +defaultfirstpage+ is 1; it can be changed via +\pagerangeoptions+. +\item A range of the form ``+12-+'' is taken to mean page~12 to +defaultlastpage+, where the default value of +defaultlastpage+ is the document's last page. +\item A range of the form ``+-+'' (\ie, only hyphen and no pages) is taken to mean from +defaultfirstpage+ to +defaultlastpage+. +\item An empty or blank page range (\ie, containing no argument and no hyphen/tie) is taken to mean the range +defaultfirstpage+ to +defaultlastpage+, or it may prompt a fatal error, depending on whether the boolean +acceptempty+ is set true or false (respectively). \end{compactenum} -An empty or blank page range (\ie, containing no argument and no hyphen/tie) is taken to mean the range +1-1+ or it may prompt a fatal error, depending on whether the boolean +acceptempty+ is set true or false (respectively). - Page ranges containing more than one hyphen/tie cause fatal error. If the upper limit of the page range is smaller than the lower limit, a fatal error is flagged. -The tie between the pages in the page range can be any single non-active character; its default is the hyphen character ``+-+''. It can be changed in the call to the package (\eg, +\usepackage[tie=*]{pagerange}+) or at any moment through +\pagerangeoptions{tie=*}+. Of course, active characters can't be used as ties. The package easily terminates with a warning when an active character is passed as +tie+. +The tie between the pages in the page range can be any single non-active character; its default is the hyphen character ``+-+''. It can be changed in the call to the package (\eg, +\usepackage[tie=*]{pagerange}+) or at any moment through +\pagerangeoptions{tie=*}+. Active characters can't, unfortunately, be used as ties. The package easily terminates with a warning when an active character is passed as +tie+. It wouldn't be safe to change the catcode of an active character submitted as +tie+ through +\pagerangeoptions+, since at the time the macro +\pagerangeoptions+ is invoked, the page may already be in the process of being built. Because of the need for the last page of the document, at least~2 runs/passes are needed to obtain the correct last page. -This package has been tested with the +hyperref+ package, which redefines the label used by the +lastpage+ package. By default, the last page is not hyperlinked. If you want the last page to be hyperlinked, you should set the boolean option +hyperlink=true+ in +\usepackage{pagerange}+ or in +\pagerangeoptions+. +This package has been tested with the +hyperref+ package, which redefines the label used by the +lastpage+ package. -\section{Package options} -The package has only three options, namely, +\section{Package options}\label{sec:package-options} +The package options are as follows: -\begin{tabularx}{\linewidth}{m{2.5cm}m{2.0cm}X} -\bf Option & \bf Default & \bf Meaning\\ -+tie+ & hyphen (+-+) & The tie that show the breakpoint for the page range.\\ -+acceptempty+ & +false+ & The boolean option that specifies if empty page ranges (\ie, no page numbers and no tie) submitted to the package should be accepted. If +true+, the page range is assumed to be from page~1 to the last page.\\ -+hyperlink+& +false+& The boolean switch that determines if the last page (of the page range) should be hyperlinked.\\ +\begin{tabularx}{\linewidth}{p{3cm}p{2.0cm}X} +\hline +\bf Option & \bf Default & \bf Meaning\\\hline ++tie+ & hyphen (+-+) & The tie that show the breakpoint for the page range.\\\hline ++acceptempty+ & +false+ & The boolean option that specifies if empty page ranges (\ie, no page numbers and no tie) submitted to the package should be accepted. If true, the page range is assumed to be from page~1 to the last page.\\\hline ++defaultfirstpage+ & +1+ & The default start page number, used as the starting page when no starting page number is specified by the user.\\\hline ++defaultlastpage+ & document's last page & The default last page number, used as the last page when no last page number is specified by the user.\\\hline \end{tabularx} \section{Examples} @@ -99,42 +103,13 @@ The following \pagerange{-34} produces \result{Pages~\pagestart\space to\space\pageend}. -\pgexample{Hyperlinking of last page} - -The package was loaded as -\par\medskip -\centerline{\tt\string\usepackage[acceptempty,hyperlink]\{pagerange\},} - -in which both +acceptempty+ and +hyperlink+ are +true+. They can, of course, both be reversed (\ie, set as +false+). Since the prevailing value of +hyperlink+ is +true+, we see that - -\begin{pverbatim} -\pagerange{1-} -\end{pverbatim} - -\pagerange{1-} -yields \result{Pages~\pagestart\space to\space\pageend}. - -\pgexample{No hyperlinking of last page} -In the following the value of +hyperlink+ is +false+: - -\begin{pverbatim} -\pagerangeoptions{hyperlink=false} -\pagerange{1-} -\end{pverbatim} - -\pagerangeoptions{hyperlink=false} -\pagerange{1-} -which produces \result{Pages~\pagestart\space to\space\pageend}. - \pgexample{No page numbers given} The following \begin{pverbatim} -\pagerangeoptions{hyperlink=true} \pagerange{-} \end{pverbatim} -\pagerangeoptions{hyperlink=true} \pagerange{-} \par\medskip\noindent produces \result{Pages~\pagestart\space to\space\pageend}. @@ -146,6 +121,7 @@ The following logs a warning message or issues fatal error, depending on the sta \pagerange{} \end{pverbatim} +%\pagerangeoptions{acceptempty} %\pagerange{} %Page~\pagestart\space to\space\pageend @@ -295,8 +271,22 @@ The following \pagerange{2034X2135} correctly yields \result{Pages~\pagestart\space to\space\pageend}. -\section{To-do} +\section{Using page labels} + +From version 0.3 of the package, it has been possible to obtain page ranges from \LaTeX{} references, \eg, as in + +\begin{pverbatim} +\label{page:label} +\pagerangeoptions{tie=-} +\let\getpage\getpagenumber +\pagerange{\getpage{page:first}-\getpage{page:last}}, +\end{pverbatim} + +\label{page:last} +\pagerangeoptions{tie=-} +\pagerange{\getpagenumber{page:first}-\getpagenumber{page:last}} +which yields \result{Pages~\pagestart\space to\space\pageend}. -To provide for calls such as in +\pagerange{\pageref{page:label}-200}+. +The command +\getpagenumber+ is provided in the package and may, in general, be used to convert page labels into page numbers even in expansion contexts, where +\pageref+ will normally fail. If the page label or reference is undefined, the default start page number (+defaultfirstpage+) is used. The +defaultfirstpage+ is a package option (see Section~\ref{sec:package-options}). \end{document} \ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/pagerange/pagerange-guide.cfg b/Master/texmf-dist/tex/latex/pagerange/pagerange-guide.cfg index 623df949a11..1647320f8b5 100644 --- a/Master/texmf-dist/tex/latex/pagerange/pagerange-guide.cfg +++ b/Master/texmf-dist/tex/latex/pagerange/pagerange-guide.cfg @@ -1,5 +1,7 @@ \ProvidesFile{pagerange-guide.cfg}% - [2009/11/07 v0.2 Configuration file for pagerange-guide.tex (A.Musa)] + [2009/12/10 v0.3 Configuration file for pagerange-guide.tex (A.Musa)] +\usepackage{mathpazo} +\usepackage[scaled=0.9]{helvet} \usepackage{xspace} \usepackage{xcolor} \usepackage{shortvrb} @@ -46,4 +48,4 @@ \definecolor{xgreen}{rgb}{0.00,0.59,0.00} \newcommand*\result[1]{\textcolor{xgreen}{#1}} -\endinput \ No newline at end of file +\endinput \ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/pagerange/pagerange.sty b/Master/texmf-dist/tex/latex/pagerange/pagerange.sty index 36d7b3ca408..97d2b9361c7 100644 --- a/Master/texmf-dist/tex/latex/pagerange/pagerange.sty +++ b/Master/texmf-dist/tex/latex/pagerange/pagerange.sty @@ -1,5 +1,5 @@ %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% -% This is file 'pagerange.sty', version 0.2. % +% This is file 'pagerange.sty', version 0.3. % % % % This work may be distributed and/or modified under the conditions % % of the LaTeX Project Public License, either version 1.3 of this % @@ -17,68 +17,82 @@ % Copyright (c) 2009 Ahmed Musa (a.musa@rocketmail.com). % %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% -\ProvidesPackage{pagerange}[2009/11/10 v0.2 Split page ranges intelligently] +\ProvidesPackage{pagerange}% + [2009/11/10 v0.3 Split page ranges intelligently (Ahmed Musa)] \NeedsTeXFormat{LaTeX2e}[1996/12/01] \def\prg@warn#1{\PackageWarningNoLine{pagerange}{#1}} \def\prg@err#1{\PackageError{pagerange}{#1}{\@ehc}} -\RequirePackage{lastpage}[1994/06/25] -\RequirePackage{xkeyval}[2008/08/13] -\ifcase\ifx\eTeXversion\@undefined\@ne\else - \ifnum\eTeXversion<\tw@\@ne\fi\fi\z@ +\@ifpackageloaded{lastpage}{}{\RequirePackage{lastpage}[1994/06/25]} +\@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}[2008/08/13]} +\ifcase0% + \ifx\eTeXversion\@undefined 1\else\ifnum\eTeXversion<\tw@ 1\fi\fi \else - \prg@err{This package requires eTeX version 2 or later}% + \prg@err{eTeX not loaded or old version.\MessageBreak + This package requires eTeX version 2 or later.} \fi \def\prg@ifdef#1{\csname @\ifdefined#1\expandafter first\else \expandafter second\fi oftwo\endcsname } \def\prg@ifundef#1{% - \prg@ifdef#1{\csname @\ifx#1\relax\expandafter first\else + \prg@ifdef{#1}{\csname @\ifx#1\relax\expandafter first\else \expandafter second\fi oftwo\endcsname}{\@firstoftwo}% } +\def\prg@ifcsundef#1{\expandafter\prg@ifundef\csname#1\endcsname} \def\prg@check@ifdef#1{% - \expandafter\prg@ifundef\csname#1\endcsname{}{% + \prg@ifcsundef{#1}{}{% \prg@err{\expandafter\noexpand\csname#1\endcsname already defined}}% \prg@check@ifdef } -\prg@check@ifdef{pagerange}{pagestart}{pageend}{orighyphencode}% +\prg@check@ifdef{pagerange}{pagestart}{pageend}{getpagenumber}% \iffalse\fi\fi\endcsname{}{} -\newcount\orighyphencode\orighyphencode=\the\catcode45\relax -\AtEndOfPackage{\catcode45=\orighyphencode} -\@makeother\- -\chardef\active=13\relax -\begingroup - \catcode`\&=3\relax - \long\gdef\prg@ifblank#1{% credit: ifmtarg.sty - \prg@ifblank@i#1&&\@secondoftwo\@firstoftwo:} - \long\gdef\prg@ifblank@i#1#2#4#5:{#4} -\endgroup -\long\def\prg@xifblank#1{\begingroup - \protected@edef\@tempa{\endgroup\noexpand\prg@ifblank{#1}}% - \@tempa +\edef\prg@restorecodes{% + \catcode45=\the\catcode45\relax % - + \catcode38=\the\catcode38\relax % & } -\define@boolkeys[KV]{pagerange}[prg@]{acceptempty,hyperlink}[true] -\define@cmdkey[KV]{pagerange}[prg@]{tie}[-]{% - \edef\prg@tie{\prg@tie}% - \prg@ifmacro\prg@tie +\AtEndOfPackage{\prg@restorecodes} +\catcode38=3\relax +\@makeother\-% +\long\gdef\prg@ifblank#1{% macro credit: ifmtarg.sty + \prg@ifblank@aux#1&&\@secondoftwo\@firstoftwo:} +\long\gdef\prg@ifblank@aux#1#2#4#5:{#4} +\long\def\prg@xifblank#1{\begingroup + \protected@edef\x{\endgroup\noexpand\prg@ifblank{#1}}\x% } +\chardef\active=13\relax \def\prg@ifmacro#1{% - \prg@ifdef#1{% - \expandafter\def\expandafter\getparameter - \detokenize{macro}:##1->##2##3@stop{\prg@ifblank{##1}{% - \prg@ifblank{##3}{}{\prg@ismacro@err#1}}{\prg@ismacro@err#1} + \prg@ifdef{#1}\relax{\prg@err{\string#1 undefined}}% + \begingroup + \edef\x{\endgroup + \noexpand\def\noexpand\getparameter####1\detokenize{macro}:####2&{% + \noexpand\prg@ifblank{####2}{\noexpand\@secondoftwo}% + {\noexpand\@firstoftwo}% }% - \expandafter\getparameter\meaning#1@stop - }{\prg@err{\string#1 undefined}}% + \noexpand\expandafter\noexpand\getparameter% + \noexpand\meaning\noexpand#1\detokenize{macro}:&% + }\x +} +\def\prg@ismacro@err#1{% + \prg@err{% + Illegal tie '#1'.\MessageBreak + Note that the 'tie' has been fully expanded \MessageBreak + and may be different from what you submitted.\MessageBreak + Perhaps you've used an active character as 'tie' + }% +} +\define@boolkeys[KV]{pagerange}[prg@]{acceptempty}[true] +\define@cmdkey[KV]{pagerange}[prg@]{tie}[-]{% + \edef\prg@tie{\prg@tie}% + \expandafter\prg@ifmacro\prg@tie{\prg@ismacro@err\prg@tie}{} } -\def\prg@ismacro@err#1{\prg@err{Illegal 'tie'}} +\define@cmdkey[KV]{pagerange}[prg@]{defaultfirstpage}[1]{} +\define@cmdkey[KV]{pagerange}[prg@]{defaultlastpage}[\getpagenumber{LastPage}]{} \DeclareOptionX*{\prg@warn{Unknown option '\CurrentOption' ignored}} -\ExecuteOptionsX{tie} +\ExecuteOptionsX{tie,defaultfirstpage,defaultlastpage} \ProcessOptionsX*\relax \gdef\pagerangeoptions#1{\setkeys[KV]{pagerange}{#1}} \long\def\prg@forall#1#2\do#3{% #3{#1}% - \begingroup\expandafter\expandafter\expandafter\endgroup - \ifx\relax#2\relax% + \ifx\\#2\\% \relax \else \prg@forall#2\do{#3}% @@ -90,7 +104,7 @@ \long\def\prg@split@pagerange#1{% \def\reserved@a{#1}% \ifx\reserved@a\prg@tie - \advance\prg@cntx\@ne + \advance\prg@cntx\@ne\relax \fi \ifnum\prg@cntx=\z@ \g@addto@macro\pagestart{#1}% @@ -99,7 +113,8 @@ \g@addto@macro\pageend{#1}% \fi \else\ifnum\prg@cntx>\@ne - \prg@err{Multiple ties in page range} + \prg@err{Multiple ties in page range.\MessageBreak + Please use only one tie}% \fi\fi\fi } \newcount\prg@cnta\prg@cnta=\z@\relax @@ -112,38 +127,46 @@ \ifprg@acceptempty \prg@warn{Blank page range supplied:\MessageBreak I've therefore set the range as 1-1 and continued} - \def\pagestart{1}% - \def\pageend{1}% + \let\pagestart\prg@defaultfirstpage + \let\pageend\prg@defaultlastpage \else - \prg@err{Blank page range} + \prg@err{Blank page range.\MessageBreak + If you really mean blank pagerange,\MessageBreak + then also use 'acceptempty' boolean option + }% \fi }{% - \begingroup - \edef\@tempa{\endgroup% + \begingroup\edef\@tempa{\endgroup% \noexpand\prg@forall#1\noexpand\do{\noexpand\prg@split@pagerange}}% \@tempa }% \ifx\@empty\pagestart \ifnum\prg@cntx=\@ne - \def\pagestart{1}% + \let\pagestart\prg@defaultfirstpage \fi \fi - \prg@cnta=\pagestart\relax + \prg@cnta=\number\pagestart\relax \ifx\@empty\pageend - \prg@cntb=100000\relax + \prg@cntb=\@M\relax \ifnum\prg@cntx=\@ne - \ifprg@hyperlink - \def\pageend{\pageref{LastPage}}% - \else - \def\pageend{\pageref*{LastPage}}% - \fi + \let\pageend\prg@defaultlastpage \fi \else \prg@cntb=\number\pageend\relax \fi \ifnum\prg@cnta>\prg@cntb - \prg@err{Inconsistent page range} + \prg@err{Inconsistent page range: Page \pageend\space > \pagestart}% \fi } +\def\prg@carr#1#2#3\@nil{% + \ifx\relax#3\relax\prg@err{Problem with page reference}\fi + #2% +} +\def\getpagenumber#1{% + \prg@ifcsundef{r@#1}{\prg@defaultfirstpage}{% + \expandafter\expandafter\expandafter\prg@carr + \csname r@#1\endcsname\prg@defaultfirstpage\@nil + }% +} \endinput \ No newline at end of file -- cgit v1.2.3