diff options
author | Karl Berry <karl@freefriends.org> | 2009-11-19 18:33:38 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-11-19 18:33:38 +0000 |
commit | d3cf783af3eef0576a9acb15fb345ac082f53d66 (patch) | |
tree | 3952733cf7217fce1512283b2673a5da17015e5a /Master/texmf-dist/tex/latex | |
parent | 6f0fb49f5f8c48e2f746b8a6f622eb0d67f53dbf (diff) |
new latex package pagerange (29oct09)
git-svn-id: svn://tug.org/texlive/trunk@16079 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/pagerange/pagerange.sty | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/pagerange/pagerange.sty b/Master/texmf-dist/tex/latex/pagerange/pagerange.sty new file mode 100644 index 00000000000..a002d738707 --- /dev/null +++ b/Master/texmf-dist/tex/latex/pagerange/pagerange.sty @@ -0,0 +1,147 @@ +%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% +% This is file 'pagerange.sty'. % +% % +% When a given page range xx-yy (simple/plain characters) or % +% \pages (command token, eg, \def\pages{xx-yy}) is submitted to the macro % +% \pagerange (eg, \pagerange{xx-yy} or \pagerange\pages), this package % +% splits the range as xx in the macro \pagestart and yy in \pageend. % +% The counter equivalents of these are \prg@cnta and \prg@cntb. % +% The command token (eg, \pages) is fully expanded before the page % +% range is split. % +% % +% If you specify a range consisting of a hyphen (or any tie) but with % +% one or two empty page numbers, the following will happen: % +% 1. a range of the form -34 is taken to mean pages 1 to 34; % +% 2. a range of the form 12- is taken to mean page 12 to last page; % +% 3. a range of the form - (only hyphen) is taken to mean page 1 to % +% last page; % +% % +% An empty or blank page range (ie, containing no argument and no % +% hyphen/tie) is taken to mean range 1-1 or it may prompt a fatal error, % +% depending on whether the boolean 'acceptempty' is 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 pagerange can be any single % +% non-active character; its default is the hyphen '-'. 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. % +% % +% Because of the need for the last page of the document, at leat 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. % +% % +% The LPPL maintenance status of this software is 'author-maintained'. % +% % +% This software is provided 'as it is', without warranty of any kind, % +% either expressed or implied, including, but not limited to, the % +% implied warranties of merchantability and fitness for a particular % +% purpose. % +% % +% Copyright (c) 2009 Ahmed Musa (a.musa@rocketmail.com). % +%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + +\ProvidesPackage{pagerange}[2009/05/10 v0.1 Split page ranges intelligently] +\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] +\newcount\orighyphencode\orighyphencode=\the\catcode045\relax +\AtEndOfPackage{\catcode045=\orighyphencode} +\catcode045=12\relax +\define@boolkeys[KV]{pagerange}[prg@]{acceptempty,hyperlink}[true] +\define@cmdkey[KV]{pagerange}[prg@]{tie}[-]{} +\DeclareOptionX*{\prg@warn{Unknown option '\CurrentOption' ignored}} +\ExecuteOptionsX<pagerange>{tie} +\ProcessOptionsX*<pagerange>\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% + \relax + \else + \prg@forall#2\do{#3} + \fi +} +\begingroup +\catcode`\&=3\relax +\long\gdef\prg@ifblank#1{% adapted from ifmtarg.sty + \i@prg@ifblank#1&&\@secondoftwo\@firstoftwo:} +\long\gdef\i@prg@ifblank#1#2#4#5:{#4} +\endgroup +\long\def\prg@x@ifblank#1{\begingroup + \protected@edef\@tempa{\endgroup\noexpand\prg@ifblank{#1}} + \@tempa +} +\let\pagestart\@empty +\let\pageend\@empty +\newcount\prg@cntx\prg@cntx=\z@\relax +\long\def\prg@split@pagerange#1{% + \def\reserved@a{#1}% + \ifx\reserved@a\prg@tie + \advance\prg@cntx\@ne + \fi + \ifnum\prg@cntx=\z@ + \g@addto@macro\pagestart{#1}% + \else\ifnum\prg@cntx=\@ne + \ifx\reserved@a\prg@tie\else + \g@addto@macro\pageend{#1}% + \fi + \else\ifnum\prg@cntx>\@ne + \prg@err{Multiple ties in page range} + \fi\fi\fi +} +\newcount\prg@cnta\prg@cnta=\z@\relax +\newcount\prg@cntb\prg@cntb=\z@\relax +\def\pagerange#1{% + \let\pagestart\@empty + \let\pageend\@empty + \prg@cntx=\z@\relax + \prg@x@ifblank{#1}{% + \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}% + \else + \prg@err{Blank page range} + \fi + }{% + \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}% + \fi + \fi + \prg@cnta=\pagestart\relax + \ifx\@empty\pageend + \prg@cntb=100000\relax + \ifnum\prg@cntx=\@ne + \ifprg@hyperlink + \def\pageend{\pageref{LastPage}} + \else + \def\pageend{\pageref*{LastPage}} + \fi + \fi + \else + \prg@cntb=\number\pageend\relax + \fi + \ifnum\prg@cnta>\prg@cntb + \prg@err{Inconsistent page range} + \fi +} + +\endinput
\ No newline at end of file |