summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/mcite/mcite.dtx
blob: f856f1aadec64ba8ef8020fc6a14246f22b8a258 (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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
% \iffalse % mcite.dtx - multiple citations on one key
% Copyright (C) 1994 by Thorsten.Ohl@Physik.TH-Darmstadt.de
% $Header: /home/sources/ohl/tex/thotex/mcite/mcite.dtx,v 1.6 1996/01/01 23:52:29 ohl Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Mcite is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by 
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% Mcite is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \fi
%
%% \CheckSum{212}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \MakeShortVerb{\|}
%
% \title{%
%   \MCITE/: \\
%   Multiple Citations on One Key}
%
% \author{%
%   Thorsten Ohl\thanks{e-mail:
%     \texttt{Thorsten.Ohl@Physik.TH-Darmstadt.de}}\\
%   \hfil \\
%   Technische Hochschule Darmstadt \\
%   Schlo\ss gartenstr. 9 \\
%   D-64289 Darmstadt \\
%   Germany}
%
% \maketitle
%
% \begin{abstract}
%   This \LaTeXe{} package provides support for collapsing multiple
%   citations into one, as custumoary in physics journals.
% \end{abstract}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \tableofcontents
% \unitlength=1mm
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Introduction}
%
% Imagine we want to refer to the standard
% model~\cite{Glashow,*Salam,*Weinberg} of particle physics.  Instead
% of the standard \BibTeX{}~\cite{btxdoc,*btxhak} format
% \begin{itemize}
%   \bitem{1} Sheldon Glashow. Partial symmetries of weak interactions.
%     {\em Nucl.~Phys.}, 22:579, 1961.
%   \bitem{2} Abdus Salam. Weak and electromagnetic interactions.
%     In W.~Svartholm, editor, {\em Elementary Particle Theory}, page 367,
%     Stockholm, 1968. Almquist and Wiksell.
%   \bitem{3} Steven Weinberg.  A model of leptons.
%     {\em Phys.~Rev.~Lett.}, 19:1264, 1967.
% \end{itemize}
% it is customary in physics journals to collapse such references into one
% \begin{itemize}
%   \bitem{1} Sheldon Glashow, Nucl.~Phys.~\textbf{22} (1961) 579; 
%     Abdus Salam, in: W.~Svartholm (ed.), \textit{Elementary
%     Particle Theory}, p.~367, Stockholm, 1968;
%     Steven Weinberg, Phys.~Rev.~Lett.~\textbf{19} (1967) 1264.
% \end{itemize}
% The slight typographyical changes are easily taken care of by
% changing the \BibTeX{} style, i.e.~by using |phaip.bst|.  The hard
% part is to convince \BibTeX{} to collapse the entries.  \MCITE/
% takes care of that.
%
% \DescribeMacro{\cite}
% This package overloads the \LaTeX{}~\cite{latex,*latex-companion}
% |\cite| command.  All keys starting with a |*| (which should be
% sufficiently unlikely in a \BibTeX{} key) will be added to the
% previous item.  For example the following
% reference~\cite{texbook,latex,*latex-companion,Glashow,*Salam,*Weinberg}
% was created by
% |\cite{texbook,latex,*latex-companion,Glashow,*Salam,*Weinberg}|.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection*{Hacking the \BibTeX{} Style}
%
% With the standard \BibTeX{} styles, it is almost impossible to
% provide proper punctuation (i.e.~``|;|'' between collapsed items).
% In principle one could play tricks with an active ``|.|'', but there
% are too many special cases in real life \BibTeX{} entries that can go
% wrong.  Fortunately, it is fairly easy to customize \BibTeX{} styles
% for our purposes.
%
% Almost all \BibTeX{} styles known to (wo)mankind contain a function
% \begin{verbatim}
% FUNCTION {fin.entry}
% { add.period$
%   write$
%   newline$
% }
% \end{verbatim}
% removing the |add.period$| and escaping the |newline$| with |\relax|
% will take care of the paragraph breaks and allow \MCITE/ to provide
% the proper punctuation:
% \begin{verbatim}
% FUNCTION {fin.entry}
% { write$
%   "\relax" write$
%   newline$
%   "\relax" write$
% }
% \end{verbatim}
% Note that |%| would be almost as good as |\relax| but the latter
% also works if the |\catcode| of |%| has been changed.
%
% In the function |begin.bib|, the |\begin{thebibliography}| should be
% replaced by |\begin{mcbibliography}|.  Similary, in |end.bib| the
% |\end{thebibliography}| by |\end{mcbibliography}|.  The
% |mcbibliography| environment will inform \MCITE/ that it has to
% provide the punctuation.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection*{Bugs and Deficiencies}
%
% The following bugs and deficiencies are known:
% \begin{enumerate}
%   \item{} \MCITE/ only works with unsorted bibliography styles.
%     Without modifications to \BibTeX, it seems impossible to support
%     sorted bibliography styles.
%   \item{} \MCITE/'s |\cite| is less forgiving about bogus spaces.
%     This can be fixed.
% \end{enumerate}
%
% \StopEventually{}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Implementation}
%
% It's is good practice to identify this version of this package.
% We do this by parsing an RCS |Id| string and storing the
% result in the conventional \TeX{} control sequences:
%    \begin{macrocode}
%<*package>
\def\fileversion{v0.04}
\NeedsTeXFormat{LaTeX2e}
{\def\RCS#1#2\endRCS{%
  \ifx$#1%
    \@RCS $#2 \endRCS
  \else
    \@RCS $*: #1#2$ \endRCS
  \fi}%
 \def\@RCS $#1: #2,v #3 #4 #5 #6$ \endRCS{%
   \gdef\filename{#2}%
   \gdef\filerevision{v#3}%
   \gdef\filedate{#4}%
   \gdef\docdate{#4}}%
\RCS $Id: mcite.dtx,v 1.6 1996/01/01 23:52:29 ohl Exp $ \endRCS}%
%    \end{macrocode}
%
% And now the standard procedure:
%    \begin{macrocode}
\ProvidesPackage{mcite}[\filedate\space multiple citations]
\typeout{Package: `mcite'
   \fileversion\space <\filedate> (tho) PRELIMINARY TEST RELEASE}
\wlog{English documentation \@spaces<\docdate> (tho)}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Collecting Information}
%
%    \begin{macrocode}
\def\@enamedef#1{\expandafter\edef\csname #1\endcsname}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\mc@single#1{\global\@enamedef{mc*sg*#1}{}}
\def\mc@head#1#2{\global\@enamedef{mc*hd*#1}{#2}}
\def\mc@tail#1#2{\global\@enamedef{mc*tl*#1}{#2}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\mc@ifsingle#1#2#3{\@ifundefined{mc*sg*#1}{#3}{#2}}
\def\mc@ifhead#1#2#3{\@ifundefined{mc*hd*#1}{#3}{#2}}
\def\mc@iftail#1#2#3{\@ifundefined{mc*tl*#1}{#3}{#2}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\mc@thehead#1{\@nameuse{mc*tl*#1}}
\def\mc@thetail#1{\@nameuse{mc*hd*#1}}
%    \end{macrocode}
%
% \begin{macro}{\mcite}
% We are overloading the original |\cite| command such that
% |\cite{latex,*latex-companion,texbook}| will give
% ``\cite{latex,*latex-companion,texbook}''.
%    \begin{macrocode}
\let\orig@cite\cite
\def\mcite{%
  \@ifnextchar[%
    {\PackageWarning{mcite}%
       {optional argument to \protect\cite\space not supported}%
     \@tempswatrue
     \expandafter\mc@citex\mc@gobbleopt}%
    {\@tempswatrue
     \mc@cite}}
%    \end{macrocode}
% \end{macro}
% Gobble up all optional arguments
%    \begin{macrocode}
\def\mc@gobbleopt[#1]{}
%    \end{macrocode}
% \begin{macro}{\cite}
% \changes{v0.04}{1996/01/01}{%
%   Better coexistence with \texttt{cite.sty}: overload
%   later, \texttt{AtBeginDocument}.}
% If we postpone the overloading of |\cite| until the
% |\begin{document}|, we can coexist with |cite.sty|.  If we were to
% do it now, we would have to demand that |cite.sty| is loaded
% \emph{before} |mcite.sty|.
%    \begin{macrocode}
\AtBeginDocument{\let\cite\mcite}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mc@cite}
% First of all: expand the argument: 
%    \begin{macrocode}
\def\mc@cite#1{%
  \edef\mc@temp{#1}%
  \expandafter\mc@cite@\expandafter{\mc@temp}}
%    \end{macrocode}
% Here we do the actual ``preprocessing'' of the |\cite| keys.
%    \begin{macrocode}
\def\mc@cite@#1{%
  \mc@firsttrue
  \@for\mc@@@:=#1\do{%
%    \end{macrocode}
% It the key starts with a |*|, mark it as tail.  Otherwise mark it as
% head.
%    \begin{macrocode}
    \expandafter\mc@ifstar\mc@@@\sentinel%
      {\ifmc@first
         \PackageWarning{mcite}%
           {tail `\mc@key' appears as first item in \protect\cite}%
         \mc@dohead
       \else
         \mc@dotail
       \fi}%
      {\mc@dohead}%
%    \end{macrocode}
% Write a |\citation| command to the |.aux| file in any case.  This
% gives some duplication but keeps things in order.
%    \begin{macrocode}
    \if@filesw
      \immediate\write\@auxout{\string\citation{\mc@key}}%
    \fi}%
  \expandafter\orig@cite\expandafter{\mc@list}}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\def\mc@dohead{%
  \mc@iftail{\mc@key}%
    {\PackageWarning{mcite}%
       {head `\mc@key' already used as tail of `\mc@thehead{\mc@key}'}}%
    {}%
  \mc@head{\mc@key}{}%
  \edef\mc@curhead{\mc@key}%
  \ifmc@first
    \mc@firstfalse
    \edef\mc@list{\mc@key}%
  \else
    \edef\mc@list{\mc@list,\mc@key}%
  \fi}
%    \end{macrocode}
%    \begin{macrocode}
\def\mc@dotail{%
  \mc@ifhead{\mc@key}%
    {\PackageWarning{mcite}%
       {tail `\mc@key' already used as head}}%
    {}%
  \mc@tail{\mc@key}{\mc@curhead}}
%    \end{macrocode}
%    \begin{macrocode}
\def\mc@ifstar#1#2\sentinel#3#4{%
  \ifx*#1%
    \def\mc@key{#2}%
    #3%
  \else
    \def\mc@key{#1#2}%
    #4%
  \fi}
%    \end{macrocode}
%    \begin{macrocode}
\newif\ifmc@first
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Producing the Output}
%
% The simplest approach is to just drop the |\@bibitem| if we're
% processing a continuation (it is just an |\item| with associated
% |.aux| file action):
%    \begin{macrocode}
\let\orig@bibitem\@bibitem
\def\@bibitem#1{%
%    \end{macrocode}
% If the \BibTeX{} style supports \MCITE/, we have to provide
% punctuation ourselves.
%    \begin{macrocode}
  \ifmc@bstsupport
    \mc@iftail{#1}%
      {;\space\ignorespaces}%
      {\ifmc@first\else.\fi\orig@bibitem{#1}}
    \mc@firstfalse
  \else
    \mc@iftail{#1}%
      {\ignorespaces}%
      {\orig@bibitem{#1}}%
  \fi}%
%    \end{macrocode}
%    \begin{macrocode}
\newif\ifmc@bstsupport
\mc@bstsupportfalse
%    \end{macrocode}
% We can't handle |\bibitem|s with an optional argument; tell the user.
%    \begin{macrocode}
\def\@lbibitem[#1]#2{%
  \PackageError{mcite}%
    {You can't use the optional argument of \protect\bibitem}%
    {Hey, *I* have to fool around with the labels!}%
  \@bibitem{#2}}
%    \end{macrocode}
% The |mcbibliography| environment instructs \MCITE/ to provide its
% own punctuation.
%    \begin{macrocode}
\def\mcbibliography{%
  \mc@bstsupporttrue
  \mc@firsttrue
  \thebibliography}
\def\endmcbibliography{%
  .%
  \endthebibliography}
%    \end{macrocode}
%
% That's it!
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \Finale
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \bibliography{mcite}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \PrintIndex
% \PrintChanges
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \appendix
% \section{Driver File}
%
% In general we will of course format this documentation with itself.
%    \begin{macrocode}
%<*driver>
\documentclass[a4paper]{article}
\usepackage{doc}
\usepackage{mcite}
\EnableCrossrefs
\RecordChanges
\CodelineIndex
\makeatletter
\def\bitem#1{\item[\@biblabel{#1}]}
\makeatother
\def\MCITE/{\texttt{mcite}}
\DoNotIndex{\\,\advance,\baselineskip,\batchmode,\begin,\catcode,\char}
\DoNotIndex{\CodelineIndex,\csname,\def,\divide,\docdate,\DocInput}
\DoNotIndex{\documentclass,\else,\emph,\EnableCrossrefs,\end,\endcsname}
\DoNotIndex{\errmessage,\errorstopmode,\expandafter,\fbox,\fi,\filedate}
\DoNotIndex{\filename,\fileversion,\font,\fontencoding,\fontfamily}
\DoNotIndex{\fontseries,\fontshape,\fontsize,\gdef,\goodbreak,\hfil}
\DoNotIndex{\hoffset,\hskip,\ifcase,\ifx,\InputIfFileExists,\item,\let}
\DoNotIndex{\line,\LoadClass,\makebox,\mbox,\multiply,\NeedsTeXFormat}
\DoNotIndex{\newdimen,\newenvironment,\newif,\nobreak,\normalfont}
\DoNotIndex{\normalsize,\nullfont,\or,\oval,\pagestyle,\par,\parbox}
\DoNotIndex{\parindent,\parskip,\PassOptionsToClass,\ProcessOptions}
\DoNotIndex{\ProvidesClass,\put,\quad,\raisebox,\RecordChanges,\relax,\rule}
\DoNotIndex{\selectfont,\space,\ss,\texttt,\textwidth,\the,\thispagestyle}
\DoNotIndex{\topmargin,\usepackage,\voffset,\vskip,\vspace,\wlog}
\begin{document}
  \bibliographystyle{unsrt}%%%{physics}
  \DocInput{mcite.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Copying}
% \label{sec:GPL}
%
% \MCITE/ is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by 
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% \MCITE/ is distributed in the hope that it will be useful, but
% \emph{without any warranty}; without even the implied warranty of
% \emph{merchantability} or \emph{fitness for a particular purpose}.
% See the GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
Local Variables:
mode:LaTeX
fill-prefix:"% "
page-delimiter:"^%%%%%%%%%%%*\n"
End: