numcompress.sty 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. %%
  2. %% This is file 'numcompress'.
  3. %%
  4. %% Copyright (C) 2009-2012 River Valley Technologies
  5. %% <[email protected]>
  6. %%
  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.
  10. %%
  11. %% $Id: numcompress.sty 187 2012-08-18 09:36:35Z rishi $
  12. %% $URL: http://lenova.river-valley.com/svn/elsbst/trunk/numcompress.sty $
  13. %%
  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
  28. \DeclareOption{dots}{\global\dotstrue}
  29. \DeclareOption{nodots}{\global\dotsfalse}
  30. \DeclareOption{compress}{\global\numcompresstrue}
  31. \DeclareOption{nocompress}{\global\numcompressfalse}
  32. \ProcessOptions
  33. \def\removeDot#1{\def\tmp{#1}%
  34. \ifx\tmp\@empty\else\@removeDot#1\@nil\fi}
  35. \def\@removeDot#1\@nil{\edef\fchar{\expandafter\@car#1\@nil}%
  36. \edef\rchar{\expandafter\@cdr#1!\@nil}%
  37. \def\@xmltempa{.}\def\@xmltempb{!}%
  38. \ifx\fchar\@xmltempb\relax\else%
  39. \ifx\fchar\@xmltempa\relax\else%
  40. \fchar\ignorespaces\fi\removeDot{\rchar}\fi}
  41. \def\First[#1]{\csname First#1\endcsname}
  42. \def\Second[#1]{\csname Second#1\endcsname}
  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. \def\parseSecondPage#1{\@tempcnta=0
  50. \@tfor\@digits:=#1\do{%
  51. {\global\advance\@tempcnta by 1
  52. \expandafter\xdef\csname
  53. Second\the\@tempcnta\endcsname{\@digits}%
  54. \xdef\llength{\the\@tempcnta}}}}
  55. \newif\ifdissimilar\dissimilarfalse
  56. \def\checkequal#1#2{\edef\Farg{#1}\edef\Sarg{#2}%
  57. \edef\One{A}%
  58. \ifcat\One\Farg \relax\else%
  59. \ifdissimilar\Sarg\else%
  60. \ifnum\Farg=\Sarg\relax\else\Sarg\dissimilartrue\fi\fi\fi}
  61. %
  62. \let\@@fpage\@empty
  63. \let\@@lpage\@empty
  64. \def\fpage@compress#1{%
  65. \gdef\@@fpage{#1}%
  66. \edef\llength{0}%
  67. \parseFirstPage{#1}%
  68. \ifnum\flength=\llength%
  69. \gdef\@fpage{\@@fpage}%
  70. \gdef\@lpage{%
  71. \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
  72. \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
  73. \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
  74. \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
  75. \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
  76. }%
  77. \else%
  78. \gdef\@fpage{\@@fpage}%
  79. \gdef\@lpage{\@@lpage}%
  80. \fi}
  81. \def\lpage@compress#1{%
  82. \gdef\@@lpage{#1}%
  83. \parseSecondPage{#1}%
  84. \ifnum\flength=\llength%
  85. \gdef\@fpage{\@@fpage}%
  86. \gdef\@lpage{%
  87. \edef\One{A}%
  88. \edef\xFirst{\First[1]}%
  89. \edef\xSecond{\Second[1]}%
  90. \ifcat\One\xSecond\relax%
  91. \ifx\xFirst\xSecond%
  92. \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
  93. \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
  94. \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
  95. \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
  96. \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
  97. \else#1\fi%
  98. \else%
  99. \ifx\xFirst\xSecond%
  100. \@ifundefined{Second1}{}{\checkequal{\First[1]}{\Second[1]}}%
  101. \@ifundefined{Second2}{}{\checkequal{\First[2]}{\Second[2]}}%
  102. \@ifundefined{Second3}{}{\checkequal{\First[3]}{\Second[3]}}%
  103. \@ifundefined{Second4}{}{\checkequal{\First[4]}{\Second[4]}}%
  104. \@ifundefined{Second5}{}{\checkequal{\First[5]}{\Second[5]}}%
  105. \else#1\fi%
  106. \fi%
  107. }%
  108. \else
  109. \gdef\@fpage{\@@fpage}%
  110. \gdef\@lpage{%
  111. \edef\Targ{#1}%
  112. \edef\One{A}%
  113. \edef\xFirst{\First[1]}%
  114. \edef\xSecond{\Second[1]}%
  115. \ifx\xFirst\xSecond
  116. \ifcat\One\xSecond\relax\else\@@lpage\fi%
  117. \else#1\fi%
  118. }%
  119. \fi}
  120. %\newwrite\xx
  121. %\immediate\openout\xx=tmpbib.tex
  122. \gdef\@@lpage@compress#1--#2\@nil{\lpage@compress{#1}}
  123. \gdef\@@@pages#1#2{\def\next{#2}%
  124. % \immediate\write\xx{[\the\c@NAT@ctr.]\space [#1][#2]}%
  125. \fpage@compress{#1}%\ifx\next\@empty\relax\else
  126. \@@lpage@compress#2\@nil%\fi
  127. {\@fpage\ifx\next\@empty\relax\else
  128. --\@lpage\fi}\resetall}
  129. \gdef\@@@page#1{#1\resetall}
  130. \def\mk@empty#1{\@tempcnta=1
  131. \loop\ifnum\@tempcnta<6
  132. \expandafter\let\csname#1\the\@tempcnta\endcsname\relax
  133. \advance\@tempcnta by 1 \repeat}
  134. \def\resetall{\let\@lpage\@empty\let\@fpage\@empty
  135. \def\flength{0}\def\llength{0}%
  136. \let\@@fpage\@empty\let\@@lpage\@empty
  137. \mk@empty{First}\mk@empty{Second}}
  138. \ifdots
  139. \gdef\xfnm[#1]{\unskip\space#1}
  140. \def\bibinfo#1#2{\@ifnextchar.{\@@bibinfo{#1}{#2}}{\@@@bibinfo{#1}{#2}}}
  141. \def\@@@bibinfo#1#2{\def\next{#1}%
  142. \def\@@@pg{pages}\def\@@@au{author}%
  143. \ifx\next\@@@pg\bibpages{#2}\else
  144. \ifx\next\@@@au\bibauthor{#2}\else
  145. #2\fi\fi}
  146. \def\@@bibinfo#1#2.{\def\next{#1}%
  147. \def\@@@pg{pages}\def\@@@au{author}%
  148. \ifx\next\@@@pg\bibpages{#2}.\else
  149. \ifx\next\@@@au\bibauthor{#2}\else
  150. #2.\fi\fi}
  151. \else
  152. \gdef\xfnm[#1]{\unskip\space\removeDot{#1}}
  153. \def\bibinfo#1#2{\def\next{#1}%
  154. \def\@@@pg{pages}\def\@@@au{author}%
  155. \ifx\next\@@@pg\bibpages{#2}\else
  156. \ifx\next\@@@au\bibauthor{#2}\else
  157. #2\fi\fi}
  158. \fi
  159. \ifnumcompress
  160. \def\bibpages#1{\@@bibpages#1--\\\@nil}
  161. \def\@@bibpages#1--#2\@nil{%
  162. \ifx\\#2\relax\@@@page{#1}\else
  163. \@@@pages{#1}{#2}\fi}
  164. \else
  165. \def\bibpages#1{#1}
  166. \fi
  167. \def\bibauthor#1{#1}
  168. \endinput
  169. %%
  170. %% End of package 'numcompress.sty'
  171. %%