2 %% This is file 'numcompress'.
4 %% Copyright (C) 2009-2012 River Valley Technologies
5 %% <latex.support@river-valley.com>
7 %% This package may be distributed under the terms of the LaTeX Project
8 %% Public License, as described in lppl.txt in the base LaTeX distribution.
9 %% Either version 1.0 or, at your option, any later version.
11 %% $Id: numcompress.sty 187 2012-08-18 09:36:35Z rishi $
12 %% $URL: http://lenova.river-valley.com/svn/elsbst/trunk/numcompress.sty $
14 \NeedsTeXFormat{LaTeX2e}
15 \def\Fileversion$#1: #2 ${\gdef\fileversion{#2}}
16 \def\Filedate$#1: #2-#3-#4 #5 #6 #7 ${\gdef\filedate{#2/#3/#4}}
17 \Fileversion$Rev: 187 $
18 \Filedate$LastChangedDate: 2012-08-18 15:06:35 +0530 (Sat, 18 Aug 2012) $
19 \ProvidesPackage{numcompress}
20 [\filedate\space\fileversion\space numcompress (CVR)]
21 \PackageWarningNoLine{numcompress}
22 {****************************************\MessageBreak
23 Package numcompress v,\fileversion\space loaded\MessageBreak
24 [Compress numbers (CVR)]\MessageBreak
25 ****************************************}
26 \newif\ifdots \dotsfalse
27 \newif\ifnumcompress \numcompresstrue
29 \DeclareOption{dots}{\global\dotstrue}
30 \DeclareOption{nodots}{\global\dotsfalse}
31 \DeclareOption{compress}{\global\numcompresstrue}
32 \DeclareOption{nocompress}{\global\numcompressfalse}
36 \def\removeDot#1{\def\tmp{#1}%
37 \ifx\tmp\@empty\else\@removeDot#1\@nil\fi}
39 \def\@removeDot#1\@nil{\edef\fchar{\expandafter\@car#1\@nil}%
40 \edef\rchar{\expandafter\@cdr#1!\@nil}%
41 \def\@xmltempa{.}\def\@xmltempb{!}%
42 \ifx\fchar\@xmltempb\relax\else%
43 \ifx\fchar\@xmltempa\relax\else%
44 \fchar\ignorespaces\fi\removeDot{\rchar}\fi}
46 \def\First[#1]{\csname First#1\endcsname}
47 \def\Second[#1]{\csname Second#1\endcsname}
49 \def\parseFirstPage#1{\@tempcnta=0
50 \@tfor\@digits:=#1\do{%
51 {\global\advance\@tempcnta by 1
52 \expandafter\xdef\csname
53 First\the\@tempcnta\endcsname{\@digits}%
54 \xdef\flength{\the\@tempcnta}}}}
56 \def\parseSecondPage#1{\@tempcnta=0
57 \@tfor\@digits:=#1\do{%
58 {\global\advance\@tempcnta by 1
59 \expandafter\xdef\csname
60 Second\the\@tempcnta\endcsname{\@digits}%
61 \xdef\llength{\the\@tempcnta}}}}
63 \newif\ifdissimilar\dissimilarfalse
64 \def\checkequal#1#2{\edef\Farg{#1}\edef\Sarg{#2}%
66 \ifcat\One\Farg \relax\else%
67 \ifdissimilar\Sarg\else%
68 \ifnum\Farg=\Sarg\relax\else\Sarg\dissimilartrue\fi\fi\fi}
72 \def\fpage@compress#1{%
76 \ifnum\flength=\llength%
77 \gdef\@fpage{\@@fpage}%
79 \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
80 \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
81 \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
82 \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
83 \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
86 \gdef\@fpage{\@@fpage}%
87 \gdef\@lpage{\@@lpage}%
90 \def\lpage@compress#1{%
93 \ifnum\flength=\llength%
94 \gdef\@fpage{\@@fpage}%
97 \edef\xFirst{\First[1]}%
98 \edef\xSecond{\Second[1]}%
99 \ifcat\One\xSecond\relax%
101 \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
102 \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
103 \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
104 \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
105 \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
109 \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
110 \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
111 \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
112 \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
113 \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
118 \gdef\@fpage{\@@fpage}%
122 \edef\xFirst{\First[1]}%
123 \edef\xSecond{\Second[1]}%
125 \ifcat\One\xSecond\relax\else\@@lpage\fi%
131 %\immediate\openout\xx=tmpbib.tex
132 \gdef\@@lpage@compress#1--#2\@nil{\lpage@compress{#1}}
133 \gdef\@@@pages#1#2{\def\next{#2}%
134 % \immediate\write\xx{[\the\c@NAT@ctr.]\space [#1][#2]}%
135 \fpage@compress{#1}%\ifx\next\@empty\relax\else
136 \@@lpage@compress#2\@nil%\fi
137 {\@fpage\ifx\next\@empty\relax\else
138 --\@lpage\fi}\resetall}
140 \gdef\@@@page#1{#1\resetall}
142 \def\mk@empty#1{\@tempcnta=1
143 \loop\ifnum\@tempcnta<6
144 \expandafter\let\csname#1\the\@tempcnta\endcsname\relax
145 \advance\@tempcnta by 1 \repeat}
146 \def\resetall{\let\@lpage\@empty\let\@fpage\@empty
147 \def\flength{0}\def\llength{0}%
148 \let\@@fpage\@empty\let\@@lpage\@empty
149 \mk@empty{First}\mk@empty{Second}}
153 \gdef\xfnm[#1]{\unskip\space#1}
154 \def\bibinfo#1#2{\@ifnextchar.{\@@bibinfo{#1}{#2}}{\@@@bibinfo{#1}{#2}}}
155 \def\@@@bibinfo#1#2{\def\next{#1}%
156 \def\@@@pg{pages}\def\@@@au{author}%
157 \ifx\next\@@@pg\bibpages{#2}\else
158 \ifx\next\@@@au\bibauthor{#2}\else
160 \def\@@bibinfo#1#2.{\def\next{#1}%
161 \def\@@@pg{pages}\def\@@@au{author}%
162 \ifx\next\@@@pg\bibpages{#2}.\else
163 \ifx\next\@@@au\bibauthor{#2}\else
166 \gdef\xfnm[#1]{\unskip\space\removeDot{#1}}
167 \def\bibinfo#1#2{\def\next{#1}%
168 \def\@@@pg{pages}\def\@@@au{author}%
169 \ifx\next\@@@pg\bibpages{#2}\else
170 \ifx\next\@@@au\bibauthor{#2}\else
175 \def\bibpages#1{\@@bibpages#1--\\\@nil}
176 \def\@@bibpages#1--#2\@nil{%
177 \ifx\\#2\relax\@@@page{#1}\else
178 \@@@pages{#1}{#2}\fi}
188 %% End of package 'numcompress.sty'