summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/citesidx/citesidx.sty
blob: fc19847f5eb98f9ab2db7d9845d3f430ee478be5 (plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
% File: CITESIDX.STY
% (Based on fancycites.sty and windex.tex)
% Author: Frank Buchholz, Dortmund, Germany, Dez. 1992
%
% Main purpose:
% 	Add reference-page-list to bibliography-items.
%	This is done by using the index-facility.
%
% USAGE:
% Switch index-commands on:
%	\makeindex
%
% User selection:
% Put indexed terms into the margin (not ready):
%	\indexmark{margin}
% Mark indexed terms with a vertical rule:
%	\indexmark{rule}
%
% User selection:
% Put references of cites into index
%	\indexstyle{citesinind}
% Put references of cites into bibliography (default)
%	\indexstyle{citesinbib}
%
% Switch sorting of numeric keys on:
%	\sortcitekeys
%
% Put some text in front of bibliography 
% (Use '\\[\parskip]' instead of '\par'):
%	\bibintro{<Text>}
%
% Run LaTeX to create the <file>.idx
% Run BiBTeX if neccesary.
% Run 'makeindex -s citesidx.isty <file>' to create <file>.ind
% Run LaTeX twice to get correct references (Maybe you need even more, if you
% are using crossrefs in the bibliography.)

\typeout{Document style option `citesidx' - Frank Buchholz, Dez. 1992}

% REDEFINITION OF \@wrindex#1 TO CALL \@indexmark#1
% see LATEX.TEX

\def\@wrindex#1{%
  \@indexmark{#1}%
  \let\thepage\relax%
  \edef\@tempa{\write\@indexfile{%
    \string\indexentry{#1}{\thepage}}}%
  \expandafter\endgroup\@tempa%
  \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}

% REDEFINITION OF \@citex[#1]#2 TO FACILITATE REFERENCE BACKPOINTERS AND SORTING
% see LATEX.TEX

\def\@citex[#1]#2{%
  \if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
  \@sortkeys{#2}% new
  %\def\@citea{}%
  \let\@citea\@empty
  \@cite{\@for\@citeb:=#2\do{%
      \indexcite{\@citeb}% new
      \@citea\def\@citea{,\penalty\@m\ }%
      \@ifundefined{b@\@aref{\@citeb}}{{\reset@font\bf ?}\@warning%
        {Citation `\@aref{\@citeb}' on page \thepage \space undefined}}%
      \hbox{\csname b@\@aref{\@citeb}\endcsname}}}%
    {#1}}

% REDEFINITION OF \enddocument TO DEFINE \windcite
% see LATEX.TEX

% \enddocument is the user's command for ending the manuscript file.
\def\enddocument{\@checkend{document}\clearpage\begingroup  
  \if@filesw \immediate\closeout\@mainaux
    \def\global\@namedef##1##2{}%
    \def\newlabel{\@testdef r}%
    \def\windcite{\@testdef {bp}}% new
    \def\bibcite{\@testdef b}
    \@tempswafalse 
    \makeatletter
    \input \jobname.aux
    \if@tempswa \@warning{Label(s) may have changed.  Rerun to get
    cross-references right}\fi
  \fi\endgroup\deadcycles\z@\@@end}

% REDEFINITION OF \@idxitem#1#2
% see ARTICLE.STY, REPORT.STY, BOOK.STY
 
%\let\@orig@idxitem=\@idxitem
%\def\@idxitem#1#2 \par{\@orig@idxitem#1{#2}}

% DEFINITION OF \printindex
% see MAKEIDX.STY

\def\printindex{\@input{\jobname.ind}}

%%% NEW COMMANDS

% WARNING MESSAGE

\def\@fcwarning#1{\typeout{CitesIdx Warning: #1.}}

% MAKING BACKPOINTERS FROM REFERENCES TO WHERE CITED

% not used ???
%\def\@backcite#1{\@for\@citeb:=#1\do{\indexcite{\@citeb}}}

% used by \@citex[#1]#2
% used by \@backcite#1
\def\indexcite#1{\index{\@ifundefined{b@#1}{#1}{\@nameuse{b@#1}}%
  \string @\string\indexciteitem{#1}}}

% used by \indexcite#1
\def\indexciteitem#1#2{%
  \auxout@citationpages{#1}{#2}%
  \@indexciteitem{#1}{#2}}

% used by \indexciteitem#1#2
\def\auxout@citationpages#1#2{%
  \if@filesw \immediate\write\@auxout{%
    \string\windcite{#1}{\@stripcom#2\@nil}}\fi}

% used by \auxout@citationpages#1#2
\def\@stripcom, #1\@nil{#1}

% Read References from aux-file
\def\windcite#1#2{\global\@namedef{bp@#1}{#2}}

% USER SELECTION OF INDEXSTYLE

\def\indexstyle{\@ifstar{\@emptyindex}{\@selectindexstyle}}
\def\@selectindexstyle#1{\@nameuse{is@#1}}

% Select style: Cites in index
\def\is@citesinind{%
  \def\@indexciteitem##1{\refdescriptor{\@reflabel{##1}}}
}

% Select Style: Cites in bibliography
\def\is@citesinbib{%
  \def\@indexciteitem##1##2{}% Ignore 
  % see LATEX.TEX
  \def\bibitem{\@ifnextchar[{\@@lbibitem}{\@@bibitem}}%
}

% Default style
\is@citesinbib

% used by \is@citesinbib
\def\@@lbibitem[#1]#2#3\par{\@lbibitem[#1]{#2}#3\bibitempages{\@refpages{#2}}}
\def\@@bibitem#1#2\par{\@bibitem{#1}#2\bibitempages{\@refpages{#1}}}

% used by \@@lbibitem[#1]#2#3\par
\def\@refpages#1{%
  \@ifundefined{bp@#1}
    {{\bf -}\@fcwarning{Citations to #1 not indexed}}
    {\@nameuse{bp@#1}}}

% used by \@@lbibitem[#1]#2#3\par
% used by \@@bibitem#1#2\par
\def\bibitempages#1{\newblock [#1]}

% used by \bibitempages#1 
% see ARTICLE.STY, REPORT.STY, BOOK.STY
\def\newblock{\hskip .11em plus .33em minus -.07em}%

% used by \is@citesinind
\def\refdescriptor#1{Referenz [#1]}%
\def\@reflabel#1{\@ifundefined{b@#1}{{\bf ?}}{\@nameuse{b@#1}}}

%  MAKING CITATION KEYS PRINT IN SORTED ORDER

\def\@edefname#1{\expandafter\edef\csname #1\endcsname}

\def\@aref#1{\@nameuse{array@#1}}
\def\@aset#1#2{\@edefname{array@#1}{#2}}

\def\@refnum#1{\@ifundefined {b@\@aref{#1}}{0}{\@nameuse{b@\@aref{#1}}}}
\def\@swap#1#2{\edef\@swaptemp{\@aref{#1}}%
\@aset{#1}{\@aref{#2}}\@aset{#2}{\@swaptemp}}

\def\@carcom#1,#2\@nil{#1}
\def\@cdrcom#1,#2\@nil{#2}

\def\@sortkeys#1{\@for\@lpctri:=#1\do {\@aset{\@lpctri}{\@lpctri}}}

\newif\ifmorelist
% \loop macro used instead of \@for for inner loop of \@sortkeys in order to
% avoid exceeding parameter stack size.
% Note bizarre variation on bubble sort.  The loop counter on both inner and
% outer loop goes through entire array.  Since the sort would be correct if
% the inner loop counter would stop when it reaches the outer loop counter,
% the sort here is correct.  When the inner loop counter passes the outer
% counter and does some perverse swaps, it does not change the invariant that
% the portion of the array up to the outer loop counter is sorted.

% Switch sorting of numeric keys on
\def\sortcitekeys{%
  \def\@sortkeys##1{%
    \@for\@lpctri:=##1\do {\@aset{\@lpctri}{\@lpctri}}%
    \@for\@lpctri:=##1\do {%
      \edef\@rest{##1,\empty,}%
      \morelisttrue
      \loop
      \edef\@lpctrj{\expandafter\@carcom\@rest\@nil}%
      \edef\@rest{\expandafter\@cdrcom\@rest\@nil}%
      \ifx\@lpctrj\empty\morelistfalse\else\fi
      \ifmorelist
      \ifnum\@refnum{\@lpctrj}>\@refnum{\@lpctri}%
      \@swap{\@lpctri}{\@lpctrj}\else\fi
      \repeat}
}}

% PUT SOME TEXT IN FRONT OF THE BIBLIOGRAPHY

\def\bibintro#1{%
  \let\@origthebib=\thebibliography
  \let\@origlist=\list
  \def\thebibliography{\def\list{#1\par\bigskip\@origlist}\@origthebib}%
}

% USER SELECTION: MARK INDEXED TERMS

\def\indexmark{\@ifstar{\@emptyindex}{\@selectindexmark}}
\def\@selectindexmark#1{\@nameuse{is@index#1}}

% Put indexed terms into the margin:
\def\is@indexmargin{%
  \def\@indexmark##1{\marginpar{\fbox{\parbox[t]{\marginparwidth}{\tiny ##1}}}}
} 	

% Mark indexed terms with a vertical rule:
\def\is@indexrule{%
  \def\@indexmark##1{\unskip\hbox{\vrule depth0pt width1pt height 2ex}}
}

% no default
\def\@indexmark#1{}				

% Make all characters ``other'' so that par box doesn't give errors
% used by \is@indexmargin
\def\@makeallother{%
\@makeother a\@makeother n\@makeother A\@makeother N%
\@makeother b\@makeother o\@makeother B\@makeother O%
\@makeother c\@makeother p\@makeother C\@makeother P%
\@makeother d\@makeother q\@makeother D\@makeother Q%
\@makeother e\@makeother r\@makeother E\@makeother R%
\@makeother f\@makeother s\@makeother F\@makeother S%
\@makeother g\@makeother t\@makeother G\@makeother T%
\@makeother h\@makeother u\@makeother H\@makeother U%
\@makeother i\@makeother v\@makeother I\@makeother V%
\@makeother j\@makeother w\@makeother J\@makeother W%
\@makeother k\@makeother x\@makeother K\@makeother X%
\@makeother l\@makeother y\@makeother L\@makeother Y%
\@makeother m\@makeother z\@makeother M\@makeother Z%
\@makeother /\@makeother !\@makeother <\@makeother >%
\@makeother \$\@makeother [\@makeother ]%
%\@makeother\ 
\@makeother\\\@makeother\$\@makeother\&%
\@makeother\#\@makeother\^\@makeother\^^K\@makeother\_\@makeother\^^A%
\@makeother\%\@makeother\~}