1 %% hypernat.sty v1.0b (C) 2001 Jens Berger
3 %% This packages makes the hyperref package and the natbib package
4 %% with options `numbers' and `sort&compress' work together. This
5 %% means, that the citations (e.g [3,2,1]) will be compressed to
6 %% [1-3], where the `1' and the `3' are (color-)linked to the
9 %% The changes I made here are suggested (in August 2000) for the
10 %% next natbib release.
12 %% This package will disappear from CTAN, when natbib will do
13 %% the job by himself.
15 %% Load this package after natbib and hyperref!
17 %% Please make sure that you are using at least natbib v7.0!
21 %% v1.0b 2001/07/09 anchor for all citations in the list added
22 %% to make backref options working (bug reported by Günter Keusen)
23 %% v1.0a 2001/01/22 \noexpand for some \hyper@natlinkend added
24 %% (bug reported by Frank Meißen), hypernat.sty
25 %% is working now for `dvips --> ps2pdf' or `dvips -> Distiller'
27 \ProvidesPackage{hypernat}[2001/07/09 v1.0b hyperref and natbib compatibility (jb)]
28 \AtBeginDocument{\def\NAT@sort{2}}
29 \def\NAT@citexnum[#1][#2]#3{%
32 \@cite{\def\NAT@num{-1}\let\NAT@last@yr\relax\let\NAT@nm\@empty
33 \@for\@citeb:=\NAT@cite@list\do
34 {\edef\@citeb{\expandafter\@firstofone\@citeb}%
35 \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
36 \@ifundefined{b@\@citeb\@extra@b@citeb}{%
37 {\reset@font\bfseries?}
38 \NAT@citeundefined\PackageWarning{natbib}%
39 {Citation `\@citeb' on page \thepage \space undefined}}%
40 {\let\NAT@last@num\NAT@num\let\NAT@last@nm\NAT@nm
42 \ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
43 \let\NAT@name=\NAT@all@names
44 \global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
46 \ifNAT@full\let\NAT@nm\NAT@all@names\else
47 \let\NAT@nm\NAT@name\fi
49 \ifnum\NAT@ctype>1\relax\@citea
50 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
51 \ifnum\NAT@ctype=2\relax\NAT@test{\NAT@ctype}%
53 \fi\hyper@natlinkend\else
55 \begingroup\catcode`\_=8
56 \ifcat _\ifnum\z@<0\NAT@num _\else A\fi
57 \global\let\NAT@nm=\NAT@num \else \gdef\NAT@nm{-2}\fi
58 \ifcat _\ifnum\z@<0\NAT@last@num _\else A\fi
59 \global\@tempcnta=\NAT@last@num \global\advance\@tempcnta by\@ne
60 \else \global\@tempcnta\m@ne\fi
62 % v0.1b anchor added to make backref's working, watch for errors!
63 \ifnum\NAT@nm=\@tempcnta
64 \ifHy@backref\hyper@natlinkstart{\@citeb\@extra@b@citeb}\hyper@natlinkend\fi
65 \ifx\NAT@last@yr\relax
66 % \edef\NAT@last@yr{\@citea \mbox{\noexpand\citenumfont{\NAT@num}}}%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 \edef\NAT@last@yr{\@citea \mbox{\noexpand%
69 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
70 \noexpand\citenumfont{\NAT@num}%
71 \noexpand\hyper@natlinkend}%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % \edef\NAT@last@yr{--\penalty\@m\mbox{\noexpand\citenumfont{\NAT@num}}}%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 \edef\NAT@last@yr{--\penalty\@m\mbox{\noexpand%
78 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
79 \noexpand\citenumfont{\NAT@num}%
80 \noexpand\hyper@natlinkend}%
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % \NAT@last@yr \@citea \mbox{\citenumfont{\NAT@num}}%
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 \NAT@last@yr \@citea \mbox{%
88 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
89 \citenumfont{\NAT@num}%
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 \let\NAT@last@yr\relax
95 \@citea \mbox{\hyper@natlinkstart{\@citeb\@extra@b@citeb}%
96 {\citenumfont{\NAT@num}}\hyper@natlinkend}%
99 \def\@citea{\NAT@sep\penalty\@m\NAT@space}%
101 \ifcase\NAT@ctype\relax
102 \ifx\NAT@last@nm\NAT@nm \NAT@yrsep\penalty\@m\NAT@space\else
103 \@citea \NAT@test{1}\ \NAT@@open
104 \if*#1*\else#1\ \fi\fi \NAT@mbox{%
105 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
106 {\citenumfont{\NAT@num}}\hyper@natlinkend}%
107 \def\@citea{\NAT@@close\NAT@sep\penalty\@m\ }%
109 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
110 \NAT@test{\NAT@ctype}\hyper@natlinkend
111 \def\@citea{\NAT@sep\penalty\@m\ }%
113 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
114 \NAT@test{\NAT@ctype}\hyper@natlinkend
115 \def\@citea{\NAT@sep\penalty\@m\ }%
117 \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
118 \NAT@alias\hyper@natlinkend
119 \def\@citea{\NAT@sep\penalty\@m\ }%
123 \ifnum\NAT@sort>1\relax\NAT@last@yr\fi
124 \ifNAT@swa\else\ifnum\NAT@ctype=0\if*#2*\else
125 \NAT@cmt#2\fi \NAT@@close\fi\fi}{#1}{#2}%