1 | %% |
---|
2 | %% This is file 'numcompress.sty', |
---|
3 | %% |
---|
4 | %% Copyright (C) 2009 River Valley Technologies |
---|
5 | %% <latex.support@river-valley.com> |
---|
6 | %% |
---|
7 | %% This file may be distributed and/or modified under the |
---|
8 | %% conditions of the LaTeX Project Public License, either version 1.2 |
---|
9 | %% of this license or (at your option) any later version. |
---|
10 | %% The latest version of this license is in |
---|
11 | %% http://www.latex-project.org/lppl.txt |
---|
12 | %% and version 1.2 or later is part of all distributions of LaTeX |
---|
13 | %% version 1999/12/01 or later. |
---|
14 | %% |
---|
15 | %% $Id: numcompress.sty 144 2009-10-08 04:04:13Z rishi $ |
---|
16 | %% |
---|
17 | %% $URL: http://lenova.river-valley.com/svn/elsbst/trunk/numcompress.sty $ |
---|
18 | %% |
---|
19 | \newif\ifdots \dotstrue |
---|
20 | \newif\ifnumcompress \numcompresstrue |
---|
21 | |
---|
22 | \DeclareOption{dots}{\global\dotstrue} |
---|
23 | \DeclareOption{nodots}{\global\dotsfalse} |
---|
24 | \DeclareOption{compress}{\global\numcompresstrue} |
---|
25 | \DeclareOption{nocompress}{\global\numcompressfalse} |
---|
26 | |
---|
27 | \ProcessOptions |
---|
28 | |
---|
29 | \def\removeDot#1{\def\tmp{#1}% |
---|
30 | \ifx\tmp\@empty\else\@removeDot#1\@nil\fi} |
---|
31 | |
---|
32 | \def\@removeDot#1\@nil{\edef\fchar{\expandafter\@car#1\@nil}% |
---|
33 | \edef\rchar{\expandafter\@cdr#1!\@nil}% |
---|
34 | \def\@xmltempa{.}\def\@xmltempb{!}% |
---|
35 | \ifx\fchar\@xmltempb\relax\else% |
---|
36 | \ifx\fchar\@xmltempa\relax\else% |
---|
37 | \fchar\ignorespaces\fi\removeDot{\rchar}\fi} |
---|
38 | |
---|
39 | |
---|
40 | \def\First[#1]{\csname First#1\endcsname} |
---|
41 | \def\Second[#1]{\csname Second#1\endcsname} |
---|
42 | |
---|
43 | \def\parseFirstPage#1{\@tempcnta=0 |
---|
44 | \@tfor\@digits:=#1\do{% |
---|
45 | {\global\advance\@tempcnta by 1 |
---|
46 | \expandafter\xdef\csname |
---|
47 | First\the\@tempcnta\endcsname{\@digits}% |
---|
48 | \xdef\flength{\the\@tempcnta}}}} |
---|
49 | |
---|
50 | \def\parseSecondPage#1{\@tempcnta=0 |
---|
51 | \@tfor\@digits:=#1\do{% |
---|
52 | {\global\advance\@tempcnta by 1 |
---|
53 | \expandafter\xdef\csname |
---|
54 | Second\the\@tempcnta\endcsname{\@digits}% |
---|
55 | \xdef\llength{\the\@tempcnta}}}} |
---|
56 | |
---|
57 | \newif\ifdissimilar\dissimilarfalse |
---|
58 | \def\checkequal#1#2{\edef\Farg{#1}\edef\Sarg{#2}% |
---|
59 | \edef\One{A}% |
---|
60 | \ifcat\One\Farg \relax\else% |
---|
61 | \ifdissimilar\Sarg\else% |
---|
62 | \ifnum\Farg=\Sarg\relax\else\Sarg\dissimilartrue\fi\fi\fi} |
---|
63 | % |
---|
64 | \let\@@fpage\@empty |
---|
65 | \let\@@lpage\@empty |
---|
66 | \def\fpage@compress#1{% |
---|
67 | \gdef\@@fpage{#1}% |
---|
68 | \edef\llength{0}% |
---|
69 | \parseFirstPage{#1}% |
---|
70 | \ifnum\flength=\llength% |
---|
71 | \gdef\@fpage{\@@fpage}% |
---|
72 | \gdef\@lpage{% |
---|
73 | \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}% |
---|
74 | \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}% |
---|
75 | \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}% |
---|
76 | \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}% |
---|
77 | \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}% |
---|
78 | }% |
---|
79 | \else% |
---|
80 | \gdef\@fpage{\@@fpage}% |
---|
81 | \gdef\@lpage{\@@lpage}% |
---|
82 | \fi} |
---|
83 | |
---|
84 | \def\lpage@compress#1{% |
---|
85 | \gdef\@@lpage{#1}% |
---|
86 | \parseSecondPage{#1}% |
---|
87 | \ifnum\flength=\llength% |
---|
88 | \gdef\@fpage{\@@fpage}% |
---|
89 | \gdef\@lpage{% |
---|
90 | \edef\One{A}% |
---|
91 | \edef\xFirst{\First[1]}% |
---|
92 | \edef\xSecond{\Second[1]}% |
---|
93 | \ifcat\One\xSecond\relax% |
---|
94 | \ifx\xFirst\xSecond% |
---|
95 | \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}% |
---|
96 | \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}% |
---|
97 | \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}% |
---|
98 | \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}% |
---|
99 | \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}% |
---|
100 | \else#1\fi% |
---|
101 | \else% |
---|
102 | \ifx\xFirst\xSecond% |
---|
103 | \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}% |
---|
104 | \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}% |
---|
105 | \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}% |
---|
106 | \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}% |
---|
107 | \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}% |
---|
108 | \else#1\fi% |
---|
109 | \fi% |
---|
110 | }% |
---|
111 | \else |
---|
112 | \gdef\@fpage{\@@fpage}% |
---|
113 | \gdef\@lpage{% |
---|
114 | \edef\Targ{#1}% |
---|
115 | \edef\One{A}% |
---|
116 | \edef\xFirst{\First[1]}% |
---|
117 | \edef\xSecond{\Second[1]}% |
---|
118 | \ifx\xFirst\xSecond |
---|
119 | \ifcat\One\xSecond\relax\else\@@lpage\fi% |
---|
120 | \else#1\fi% |
---|
121 | }% |
---|
122 | \fi} |
---|
123 | |
---|
124 | \newwrite\xx |
---|
125 | \immediate\openout\xx=tmpbib.tex |
---|
126 | |
---|
127 | \gdef\@@@pages#1#2{\def\next{#2}% |
---|
128 | \immediate\write\xx{[\the\c@NAT@ctr.]\space [#1][#2]}% |
---|
129 | \fpage@compress{#1}%\ifx\next\@empty\relax\else |
---|
130 | \lpage@compress{#2}%\fi |
---|
131 | {\@fpage\ifx\next\@empty\relax\else |
---|
132 | --\@lpage\fi}\resetall} |
---|
133 | |
---|
134 | \def\mk@empty#1{\@tempcnta=1 |
---|
135 | \loop\ifnum\@tempcnta<6 |
---|
136 | \expandafter\let\csname#1\the\@tempcnta\endcsname\relax |
---|
137 | \advance\@tempcnta by 1 \repeat} |
---|
138 | \def\resetall{\let\@lpage\@empty\let\@fpage\@empty |
---|
139 | \def\flength{0}\def\llength{0}% |
---|
140 | \let\@@fpage\@empty\let\@@lpage\@empty |
---|
141 | \mk@empty{First}\mk@empty{Second}} |
---|
142 | |
---|
143 | |
---|
144 | \ifdots |
---|
145 | \gdef\xfnm[#1]{\unskip\space#1} |
---|
146 | \def\bibinfo#1#2{\@ifnextchar.{\@@bibinfo{#1}{#2}}{\@@@bibinfo{#1}{#2}}} |
---|
147 | \def\@@@bibinfo#1#2{\def\next{#1}% |
---|
148 | \def\@@@pg{pages}\def\@@@au{author}% |
---|
149 | \ifx\next\@@@pg\bibpages{#2}\else |
---|
150 | \ifx\next\@@@au\bibauthor{#2}\else |
---|
151 | #2\fi\fi} |
---|
152 | \def\@@bibinfo#1#2.{\def\next{#1}% |
---|
153 | \def\@@@pg{pages}\def\@@@au{author}% |
---|
154 | \ifx\next\@@@pg\bibpages{#2}.\else |
---|
155 | \ifx\next\@@@au\bibauthor{#2}\else |
---|
156 | #2.\fi\fi} |
---|
157 | \else |
---|
158 | \gdef\xfnm[#1]{\unskip\space\removeDot{#1}} |
---|
159 | \def\bibinfo#1#2{\def\next{#1}% |
---|
160 | \def\@@@pg{pages}\def\@@@au{author}% |
---|
161 | \ifx\next\@@@pg\bibpages{#2}\else |
---|
162 | \ifx\next\@@@au\bibauthor{#2}\else |
---|
163 | #2\fi\fi} |
---|
164 | \fi |
---|
165 | |
---|
166 | \ifnumcompress |
---|
167 | \def\bibpages#1{\@@bibpages#1\@nil} |
---|
168 | \def\@@bibpages#1--#2\@nil{\@@@pages{#1}{#2}} |
---|
169 | \else |
---|
170 | \def\bibpages#1{#1} |
---|
171 | \fi |
---|
172 | |
---|
173 | \def\bibauthor#1{#1} |
---|
174 | |
---|
175 | |
---|