                mcite:

Multiple Citations on One Key

Thorsten Ohl^{∗} Technische Hochschule Darmstadt Schloßgartenstr. 9 D-64289 Darmstadt Germany April 4, 1996

Abstract This L^{A}TEX 2ε package provides support for collapsing multiple cita-

tions into one, as custumoary in physics journals.

Contents

1 Introduction 1 2 Implementation 3

2.1 Collecting Information . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2 Producing the Output . . . . . . . . . . . . . . . . . . . . . . . . 5

A Driver File 6 B Copying 7

1 Introduction

Imagine we want to refer to the standard model [1] of particle physics. Instead of the standard BibTEX [2] format

[1] Sheldon Glashow. Partial symmetries of weak interactions. Nucl. Phys., 22:579, 1961.

[2] Abdus Salam. Weak and electromagnetic interactions. In W. Svartholm, editor, Elementary Particle Theory, page 367, Stockholm, 1968. Almquist and Wiksell.

[3] Steven Weinberg. A model of leptons. Phys. Rev. Lett., 19:1264, 1967. it is customary in physics journals to collapse such references into one

∗e-mail: Thorsten.Ohl@Physik.TH-Darmstadt.de

[1] Sheldon Glashow, Nucl. Phys. 22 (1961) 579; Abdus Salam, in: W. Svartholm (ed.), Elementary Particle Theory, p. 367, Stockholm, 1968; Steven Weinberg, Phys. Rev. Lett. 19 (1967) 1264.

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.

\cite This package overloads the L^{A}TEX [3] \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 [4, 3, 1] was created

by \cite{texbook,latex,*latex-companion,Glashow,*Salam,*Weinberg}.

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

 FUNCTION {fin.entry}
 { add.period$
   write$
   newline$
 }

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:

 FUNCTION {fin.entry}
 { write$
   "\relax" write$
   newline$
   "\relax" write$
 }

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 re-
placed 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.

Bugs and Deficiencies

The following bugs and deficiencies are known:

1. mcite only works with unsorted bibliography styles. Without modifications to BibTEX, it seems impossible to support sorted bibliography styles.

2. mcite’s \cite is less forgiving about bogus spaces. This can be fixed.

2 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:

1 ⟨∗package⟩

 2 \def\fileversion{v0.04}
 3 \NeedsTeXFormat{LaTeX2e}
 4 {\def\RCS#1#2\endRCS{%
 5 \ifx$#1%
 6  \@RCS $#2 \endRCS
 7 \else
 8  \@RCS $*: #1#2$ \endRCS
 9 \fi}%
10 \def\@RCS $#1: #2,v #3 #4 #5 #6$ \endRCS{%
11 \gdef\filename{#2}%
12 \gdef\filerevision{v#3}%
13 \gdef\filedate{#4}%
14 \gdef\docdate{#4}}%
15 \RCS $Id: mcite.dtx,v 1.6 1996/01/01 23:52:29 ohl Exp $ \endRCS}%

And now the standard procedure:

16 \ProvidesPackage{mcite}[\filedate\space multiple citations]
17 \typeout{Package: `mcite'
18 \fileversion\space <\filedate> (tho) PRELIMINARY TEST RELEASE}
19 \wlog{English documentation \@spaces<\docdate> (tho)}

2.1 Collecting Information

20 \def\@enamedef#1{\expandafter\edef\csname #1\endcsname}
21 \def\mc@single#1{\global\@enamedef{mc*sg*#1}{}}
22 \def\mc@head#1#2{\global\@enamedef{mc*hd*#1}{#2}}
23 \def\mc@tail#1#2{\global\@enamedef{mc*tl*#1}{#2}}
24 \def\mc@ifsingle#1#2#3{\@ifundefined{mc*sg*#1}{#3}{#2}}
25 \def\mc@ifhead#1#2#3{\@ifundefined{mc*hd*#1}{#3}{#2}}
26 \def\mc@iftail#1#2#3{\@ifundefined{mc*tl*#1}{#3}{#2}}
27 \def\mc@thehead#1{\@nameuse{mc*tl*#1}}
28 \def\mc@thetail#1{\@nameuse{mc*hd*#1}}
\mcite We are overloading the original \cite command such that \cite{latex,*latex-companion,texbook}

will give “[3, 4]”.

29 \let\orig@cite\cite
30 \def\mcite{%
31 \@ifnextchar[%
32  {\PackageWarning{mcite}%
33  {optional argument to \protect\cite\space not supported}%
34  \@tempswatrue
35  \expandafter\mc@citex\mc@gobbleopt}%
36  {\@tempswatrue
37  \mc@cite}}

Gobble up all optional arguments

38 \def\mc@gobbleopt[#1]{}

\cite 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 before mcite.sty.
39 \AtBeginDocument{\let\cite\mcite}

\mc@cite First of all: expand the argument:

40 \def\mc@cite#1{%
41 \edef\mc@temp{#1}%
42 \expandafter\mc@cite@\expandafter{\mc@temp}}

Here we do the actual “preprocessing” of the \cite keys.

43 \def\mc@cite@#1{%
44 \mc@firsttrue
45 \@for\mc@@@:=#1\do{%

It the key starts with a *, mark it as tail. Otherwise mark it as head.

46  \expandafter\mc@ifstar\mc@@@\sentinel%
47  {\ifmc@first
48  \PackageWarning{mcite}%
49  {tail `\mc@key' appears as first item in \protect\cite}%
50  \mc@dohead
51  \else
52  \mc@dotail
53  \fi}%
54  {\mc@dohead}%

Write a \citation command to the .aux file in any case. This gives some duplication but keeps things in order.

55  \if@filesw
56  \immediate\write\@auxout{\string\citation{\mc@key}}%
57  \fi}%
58 \expandafter\orig@cite\expandafter{\mc@list}}
59 \def\mc@dohead{%
60 \mc@iftail{\mc@key}%
61  {\PackageWarning{mcite}%
62  {head `\mc@key' already used as tail of `\mc@thehead{\mc@key}'}}%
63  {}%
64 \mc@head{\mc@key}{}%
65 \edef\mc@curhead{\mc@key}%
66 \ifmc@first
67  \mc@firstfalse
68  \edef\mc@list{\mc@key}%
69 \else
70  \edef\mc@list{\mc@list,\mc@key}%
71 \fi}
72 \def\mc@dotail{%
73 \mc@ifhead{\mc@key}%
74  {\PackageWarning{mcite}%
75  {tail `\mc@key' already used as head}}%
76  {}%
77 \mc@tail{\mc@key}{\mc@curhead}}
78 \def\mc@ifstar#1#2\sentinel#3#4{%
79 \ifx*#1%

80  \def\mc@key{#2}%
81  #3%
82 \else
83  \def\mc@key{#1#2}%
84  #4%
85 \fi}
86 \newif\ifmc@first

2.2 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):

87 \let\orig@bibitem\@bibitem
88 \def\@bibitem#1{%

If the BibTEX style supports mcite, we have to provide punctuation ourselves.

89 \ifmc@bstsupport
90  \mc@iftail{#1}%
91  {;\space\ignorespaces}%
92  {\ifmc@first\else.\fi\orig@bibitem{#1}}
93  \mc@firstfalse
94 \else
95  \mc@iftail{#1}%
96  {\ignorespaces}%
97  {\orig@bibitem{#1}}%
98 \fi}%
99 \newif\ifmc@bstsupport
100 \mc@bstsupportfalse

We can’t handle \bibitems with an optional argument; tell the user.

101 \def\@lbibitem[#1]#2{%
102 \PackageError{mcite}%
103  {You can't use the optional argument of \protect\bibitem}%
104  {Hey, *I* have to fool around with the labels!}%
105 \@bibitem{#2}}

The mcbibliography environment instructs mcite to provide its own punctuation.

106 \def\mcbibliography{%
107 \mc@bstsupporttrue
108 \mc@firsttrue
109 \thebibliography}
110 \def\endmcbibliography{%

111 .%

112 \endthebibliography}

That’s it!

113 ⟨/package⟩

References

[1] Sheldon Glashow. Partial symmetries of weak interactions. Nucl. Phys., 22:579, 1961.

Abdus Salam. Weak and electromagnetic interactions. In W. Svartholm, editor, Elementary Particle Theory, page 367, Stockholm, 1968. Almquist and Wiksell.

Steven Weinberg. A model of leptons. Phys. Rev. Lett., 19:1264, 1967.

[2] Oren Patashnik. BibTEXing. Documentation for general BibTEX users, 8 February 1988.

Oren Patashnik. Designing BibTEX styles. The part of BibTEX’s documentation that’s not meant for general users, 8 February 1988.

[3] Leslie Lamport. L^{A}TEX: A Document Preparation System. Addison-Wesley, Reading (Mass.), 2nd edition, 1994.

Michel Goosens, Frank Mittelbach, and Alexander Samarin. The L^{A}TEX Companion. Addison-Wesley, Reading (Mass.), 1994.

[4] Donald E. Knuth. The TEXbook. Addison-Wesley, Reading (Mass.), 1986.

Index

The italic numbers denote the pages where the corresponding entry is described, numbers underlined point to the definition, all others indicate the places where it is used.

AtBeginDocument=  \subitem *+\AtBeginDocument+, 39
bibitem=  \subitem *+\bibitem+, 103
bibliographystyle=  \subitem *+\bibliographystyle+, 140
bitem=  \subitem *+\bitem+, 122
citation=  \subitem *+\citation+, 56
cite=  \subitem *+\cite+, \usage{2}, 29, 33, \main{39}, 49
do=  \subitem *+\do+, 45
DoNotIndex=  \subitem *+\DoNotIndex+, 125--138
edef=  \subitem *+\edef+, 20, 41, 65, 68, 70
endmcbibliography=  \subitem *+\endmcbibliography+, 110
endRCS=  \subitem *+\endRCS+, 4, 6, 8, 10, 15
endthebibliography=  \subitem *+\endthebibliography+, 112
filerevision=  \subitem *+\filerevision+, 12
global=  \subitem *+\global+, 21--23
filesw=  \subitem filesw+, 55
bstsupport=  \subitem bstsupport+, 89, 99
first=  \subitem first+, 47, 66, 86, 92

ignorespaces=  \subitem *+\ignorespaces+, 91, 96
immediate=  \subitem *+\immediate+, 56
makeatletter=  \subitem *+\makeatletter+, 121
makeatother=  \subitem *+\makeatother+, 123
bstsupportfalse=  \subitem bstsupportfalse+, 100
bstsupporttrue=  \subitem bstsupporttrue+, 107
cite=  \subitem cite+, 37, \main{40}
citex=  \subitem citex+, 35
curhead=  \subitem curhead+, 65, 77
dohead=  \subitem dohead+, 50, 54, 59
dotail=  \subitem dotail+, 52, 72
firstfalse=  \subitem firstfalse+, 67, 93
firsttrue=  \subitem firsttrue+, 44, 108
gobbleopt=  \subitem gobbleopt+, 35, 38
head=  \subitem head+, 22, 64
ifhead=  \subitem ifhead+, 25, 73
ifsingle=  \subitem ifsingle+, 24
ifstar=  \subitem ifstar+, 46, 78
iftail=  \subitem iftail+, 26, 60, 90, 95
key=  \subitem key+, 49, 56, 60, 62, 64, 65, 68, 70, 73, 75, 77, 80, 83
list=  \subitem list+, 58, 68, 70
single=  \subitem single+, 21
tail=  \subitem tail+, 23, 77

                         temp=  \subitem temp+, 41, 42
                         thehead=  \subitem thehead+, 27, 62
                         thetail=  \subitem thetail+, 28
                         mcbibliography=  \subitem *+\mcbibliography+, 106
                         MCITE=  \subitem *+\MCITE+, 124
                         mcite=  \subitem *+\mcite+, \main{29}, 39
                         bibitem=  \subitem bibitem+, 87, 92, 97
                         cite=  \subitem cite+, 29, 58
                         PackageError=  \subitem *+\PackageError+, 102
                         PackageWarning=  \subitem *+\PackageWarning+, 32, 48, 61, 74
                         protect=  \subitem *+\protect+, 33, 49, 103
                         ProvidesPackage=  \subitem *+\ProvidesPackage+, 16
                         RCS=  \subitem *+\RCS+, 4, 15
                         sentinel=  \subitem *+\sentinel+, 46, 78
                         string=  \subitem *+\string+, 56
                         thebibliography=  \subitem *+\thebibliography+, 109
                         typeout=  \subitem *+\typeout+, 17
                         write=  \subitem *+\write+, 56

A Driver File

In general we will of course format this documentation with itself.

114 ⟨∗driver⟩

115 \documentclass[a4paper]{article}
116 \usepackage{doc}
117 \usepackage{mcite}
118 \EnableCrossrefs
119 \RecordChanges
120 \CodelineIndex
121 \makeatletter
122 \def\bitem#1{\item[\@biblabel{#1}]}
123 \makeatother
124 \def\MCITE/{\texttt{mcite}}
125 \DoNotIndex{\\,\advance,\baselineskip,\batchmode,\begin,\catcode,\char}
126 \DoNotIndex{\CodelineIndex,\csname,\def,\divide,\docdate,\DocInput}
127 \DoNotIndex{\documentclass,\else,\emph,\EnableCrossrefs,\end,\endcsname}
128 \DoNotIndex{\errmessage,\errorstopmode,\expandafter,\fbox,\fi,\filedate}
129 \DoNotIndex{\filename,\fileversion,\font,\fontencoding,\fontfamily}
130 \DoNotIndex{\fontseries,\fontshape,\fontsize,\gdef,\goodbreak,\hfil}
131 \DoNotIndex{\hoffset,\hskip,\ifcase,\ifx,\InputIfFileExists,\item,\let}
132 \DoNotIndex{\line,\LoadClass,\makebox,\mbox,\multiply,\NeedsTeXFormat}
133 \DoNotIndex{\newdimen,\newenvironment,\newif,\nobreak,\normalfont}
134 \DoNotIndex{\normalsize,\nullfont,\or,\oval,\pagestyle,\par,\parbox}
135 \DoNotIndex{\parindent,\parskip,\PassOptionsToClass,\ProcessOptions}
136 \DoNotIndex{\ProvidesClass,\put,\quad,\raisebox,\RecordChanges,\relax,\rule}
137 \DoNotIndex{\selectfont,\space,\ss,\texttt,\textwidth,\the,\thispagestyle}
138 \DoNotIndex{\topmargin,\usepackage,\voffset,\vskip,\vspace,\wlog}
139 \begin{document}
140 \bibliographystyle{unsrt}%%%{physics}
141 \DocInput{mcite.dtx}
142 \end{document}

143 ⟨/driver⟩

B Copying

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.