This repository has been archived by the owner on Nov 19, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numcompress.sty
189 lines (171 loc) · 6.03 KB
/
numcompress.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
%%
%% This is file 'numcompress'.
%%
%% Copyright (C) 2009-2012 River Valley Technologies
%% <[email protected]>
%%
%% This package may be distributed under the terms of the LaTeX Project
%% Public License, as described in lppl.txt in the base LaTeX distribution.
%% Either version 1.0 or, at your option, any later version.
%%
%% $Id: numcompress.sty 187 2012-08-18 09:36:35Z rishi $
%% $URL: http://lenova.river-valley.com/svn/elsbst/trunk/numcompress.sty $
%%
\NeedsTeXFormat{LaTeX2e}
\def\Fileversion$#1: #2 ${\gdef\fileversion{#2}}
\def\Filedate$#1: #2-#3-#4 #5 #6 #7 ${\gdef\filedate{#2/#3/#4}}
\Fileversion$Rev: 187 $
\Filedate$LastChangedDate: 2012-08-18 15:06:35 +0530 (Sat, 18 Aug 2012) $
\ProvidesPackage{numcompress}
[\filedate\space\fileversion\space numcompress (CVR)]
\PackageWarningNoLine{numcompress}
{****************************************\MessageBreak
Package numcompress v,\fileversion\space loaded\MessageBreak
[Compress numbers (CVR)]\MessageBreak
****************************************}
\newif\ifdots \dotsfalse
\newif\ifnumcompress \numcompresstrue
\DeclareOption{dots}{\global\dotstrue}
\DeclareOption{nodots}{\global\dotsfalse}
\DeclareOption{compress}{\global\numcompresstrue}
\DeclareOption{nocompress}{\global\numcompressfalse}
\ProcessOptions
\def\removeDot#1{\def\tmp{#1}%
\ifx\tmp\@empty\else\@removeDot#1\@nil\fi}
\def\@removeDot#1\@nil{\edef\fchar{\expandafter\@car#1\@nil}%
\edef\rchar{\expandafter\@cdr#1!\@nil}%
\def\@xmltempa{.}\def\@xmltempb{!}%
\ifx\fchar\@xmltempb\relax\else%
\ifx\fchar\@xmltempa\relax\else%
\fchar\ignorespaces\fi\removeDot{\rchar}\fi}
\def\First[#1]{\csname First#1\endcsname}
\def\Second[#1]{\csname Second#1\endcsname}
\def\parseFirstPage#1{\@tempcnta=0
\@tfor\@digits:=#1\do{%
{\global\advance\@tempcnta by 1
\expandafter\xdef\csname
First\the\@tempcnta\endcsname{\@digits}%
\xdef\flength{\the\@tempcnta}}}}
\def\parseSecondPage#1{\@tempcnta=0
\@tfor\@digits:=#1\do{%
{\global\advance\@tempcnta by 1
\expandafter\xdef\csname
Second\the\@tempcnta\endcsname{\@digits}%
\xdef\llength{\the\@tempcnta}}}}
\newif\ifdissimilar\dissimilarfalse
\def\checkequal#1#2{\edef\Farg{#1}\edef\Sarg{#2}%
\edef\One{A}%
\ifcat\One\Farg \relax\else%
\ifdissimilar\Sarg\else%
\ifnum\Farg=\Sarg\relax\else\Sarg\dissimilartrue\fi\fi\fi}
%
\let\@@fpage\@empty
\let\@@lpage\@empty
\def\fpage@compress#1{%
\gdef\@@fpage{#1}%
\edef\llength{0}%
\parseFirstPage{#1}%
\ifnum\flength=\llength%
\gdef\@fpage{\@@fpage}%
\gdef\@lpage{%
\@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
\@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
\@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
\@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
\@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
}%
\else%
\gdef\@fpage{\@@fpage}%
\gdef\@lpage{\@@lpage}%
\fi}
\def\lpage@compress#1{%
\gdef\@@lpage{#1}%
\parseSecondPage{#1}%
\ifnum\flength=\llength%
\gdef\@fpage{\@@fpage}%
\gdef\@lpage{%
\edef\One{A}%
\edef\xFirst{\First[1]}%
\edef\xSecond{\Second[1]}%
\ifcat\One\xSecond\relax%
\ifx\xFirst\xSecond%
\@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
\@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
\@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
\@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
\@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
\else#1\fi%
\else%
\ifx\xFirst\xSecond%
\@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
\@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
\@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
\@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
\@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
\else#1\fi%
\fi%
}%
\else
\gdef\@fpage{\@@fpage}%
\gdef\@lpage{%
\edef\Targ{#1}%
\edef\One{A}%
\edef\xFirst{\First[1]}%
\edef\xSecond{\Second[1]}%
\ifx\xFirst\xSecond
\ifcat\One\xSecond\relax\else\@@lpage\fi%
\else#1\fi%
}%
\fi}
%\newwrite\xx
%\immediate\openout\xx=tmpbib.tex
\gdef\@@lpage@compress#1--#2\@nil{\lpage@compress{#1}}
\gdef\@@@pages#1#2{\def\next{#2}%
% \immediate\write\xx{[\the\c@NAT@ctr.]\space [#1][#2]}%
\fpage@compress{#1}%\ifx\next\@empty\relax\else
\@@lpage@compress#2\@nil%\fi
{\@fpage\ifx\next\@empty\relax\else
--\@lpage\fi}\resetall}
\gdef\@@@page#1{#1\resetall}
\def\mk@empty#1{\@tempcnta=1
\loop\ifnum\@tempcnta<6
\expandafter\let\csname#1\the\@tempcnta\endcsname\relax
\advance\@tempcnta by 1 \repeat}
\def\resetall{\let\@lpage\@empty\let\@fpage\@empty
\def\flength{0}\def\llength{0}%
\let\@@fpage\@empty\let\@@lpage\@empty
\mk@empty{First}\mk@empty{Second}}
\ifdots
\gdef\xfnm[#1]{\unskip\space#1}
\def\bibinfo#1#2{\@ifnextchar.{\@@bibinfo{#1}{#2}}{\@@@bibinfo{#1}{#2}}}
\def\@@@bibinfo#1#2{\def\next{#1}%
\def\@@@pg{pages}\def\@@@au{author}%
\ifx\next\@@@pg\bibpages{#2}\else
\ifx\next\@@@au\bibauthor{#2}\else
#2\fi\fi}
\def\@@bibinfo#1#2.{\def\next{#1}%
\def\@@@pg{pages}\def\@@@au{author}%
\ifx\next\@@@pg\bibpages{#2}.\else
\ifx\next\@@@au\bibauthor{#2}\else
#2.\fi\fi}
\else
\gdef\xfnm[#1]{\unskip\space\removeDot{#1}}
\def\bibinfo#1#2{\def\next{#1}%
\def\@@@pg{pages}\def\@@@au{author}%
\ifx\next\@@@pg\bibpages{#2}\else
\ifx\next\@@@au\bibauthor{#2}\else
#2\fi\fi}
\fi
\ifnumcompress
\def\bibpages#1{\@@bibpages#1--\\\@nil}
\def\@@bibpages#1--#2\@nil{%
\ifx\\#2\relax\@@@page{#1}\else
\@@@pages{#1}{#2}\fi}
\else
\def\bibpages#1{#1}
\fi
\def\bibauthor#1{#1}
\endinput
%%
%% End of package 'numcompress.sty'
%%