mcite: Multiple Citations on One Key Thorsten Ohl∗ Technische Hochschule Darmstadt Schloßgartenstr. 9 D-64289 Darmstadt Germany October 2, 2005

Abstract This LATEX 2ε package provides support for collapsing multiple citations into one, as custumoary in physics journals.

Contents 1 Introduction

1

2 Implementation 2.1 Collecting Information . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Producing the Output . . . . . . . . . . . . . . . . . . . . . . . .

3 3 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. ∗ e-mail:

[email protected]

1

it is customary in physics journals to collapse such references into one [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.

\cite

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. This package overloads the LATEX [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 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.

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

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: h∗packagei \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}% 1

2

And now the standard procedure: 16 17 18 19

\ProvidesPackage{mcite}[\filedate\space multiple citations] \typeout{Package: ‘mcite’ \fileversion\space (tho) PRELIMINARY TEST RELEASE} \wlog{English documentation \@spaces (tho)}

2.1 20

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

21

\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}}

22 23 24 25 26 27 28

\mcite

Collecting Information

\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}} \def\mc@thehead#1{\@nameuse{mc*tl*#1}} \def\mc@thetail#1{\@nameuse{mc*hd*#1}}

We are overloading the original \cite command such that \cite{latex,*latex-companion,texbook} will give “[3, 4]”. 29 30 31 32 33 34 35 36 37

\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}}

Gobble up all optional arguments 38

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

3

\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

\mc@cite

\AtBeginDocument{\let\cite\mcite}

First of all: expand the argument: 40 41 42

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

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

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

It the key starts with a *, mark it as tail. Otherwise mark it as head. 46 47 48 49 50 51 52 53 54

\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}%

Write a \citation command to the .aux file in any case. This gives some duplication but keeps things in order. 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

\if@filesw \immediate\write\@auxout{\string\citation{\mc@key}}% \fi}% \expandafter\orig@cite\expandafter{\mc@list}} \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} \def\mc@dotail{% \mc@ifhead{\mc@key}% {\PackageWarning{mcite}% {tail ‘\mc@key’ already used as head}}% {}% \mc@tail{\mc@key}{\mc@curhead}} \def\mc@ifstar#1#2\sentinel#3#4{% \ifx*#1%

4

\def\mc@key{#2}% #3% \else \def\mc@key{#1#2}% #4% \fi}

80 81 82 83 84 85 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 88

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

If the BibTEX style supports mcite, we have to provide punctuation ourselves. 89 90 91 92 93 94 95 96 97 98 99 100

\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}% \newif\ifmc@bstsupport \mc@bstsupportfalse

We can’t handle \bibitems with an optional argument; tell the user. \def\@lbibitem[#1]#2{% \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}} 101 102

The mcbibliography environment instructs mcite to provide its own punctuation. \def\mcbibliography{% \mc@bstsupporttrue 108 \mc@firsttrue 109 \thebibliography} 110 \def\endmcbibliography{% 111 .% 112 \endthebibliography} 106 107

That’s it! 113

h/packagei

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

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. LATEX: A Document Preparation System. Addison-Wesley, Reading (Mass.), 2nd edition, 1994. Michel Goosens, Frank Mittelbach, and Alexander Samarin. The LATEX Companion. Addison-Wesley, Reading (Mass.), 1994. [4] Donald E. Knuth. The TEXbook. Addison-Wesley, Reading (Mass.), 1986.

A

Driver File

In general we will of course format this documentation with itself. h∗driveri \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 h/driveri 114

115

6

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.

7