summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/collref/collref.dtx
blob: bf9078c6ca65275edf63dd14febad9f98b17ba06 (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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
% \iffalse
%
% collref.dtx Copyright (C) 2003-2018 Niklas Beisert
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Niklas Beisert.
%
% This work consists of the files collref.dtx and collref.ins
% and the derived files collref.sty and collsamp.tex
%
%<package|sample>\NeedsTeXFormat{LaTeX2e}[1996/12/01]
%<package>\ProvidesPackage{collref}[2018/01/17 v2.0c Collect References]
%<sample>\ProvidesFile{collsamp.tex}[2018/01/17 v2.0c Sample for Collect References]
%<*driver>
%\ProvidesFile{collref.drv}[2018/01/17 v2.0c Collect References Manual file]
\PassOptionsToClass{10pt,a4paper}{article}
\documentclass{ltxdoc}

\usepackage[margin=35mm]{geometry}
\usepackage{hyperref}
\usepackage{hyperxmp}

\hypersetup{colorlinks=true}
\hypersetup{pdfstartview=FitH}
\hypersetup{pdfpagemode=UseNone}
\hypersetup{pdfsource={}}
\hypersetup{pdflang={en-UK}}
\hypersetup{pdfcopyright={Copyright 2003-2018 Niklas Beisert.
  This work may be distributed and/or modified under the
  conditions of the LaTeX Project Public License, either version 1.3
  of this license or (at your option) any later version.}}
\hypersetup{pdflicenseurl={http://www.latex-project.org/lppl.txt}}
\hypersetup{pdfcontactaddress={ETH Zurich, ITP, HIT K, Wolfgang-Pauli-Strasse 27}}
\hypersetup{pdfcontactpostcode={8093}}
\hypersetup{pdfcontactcity={Zurich}}
\hypersetup{pdfcontactcountry={Switzerland}}
\hypersetup{pdfcontactemail={nbeisert@itp.phys.ethz.ch}}
\hypersetup{pdfcontacturl={http://people.phys.ethz.ch/\xmptilde nbeisert/}}

\newenvironment{thebib}
{\list{[\theenumi]}{\parsep0pt\usecounter{enumi}}}
{\endlist}

\begin{document}

\title{The \textsf{collref} Package\thanks{%
Earlier versions developed at: Max-Planck-Institut f\"ur Gravitationsphysik
(Albert-Einstein-Institut), Potsdam, Germany;
\texttt{AEI-2009-054}}}
\hypersetup{pdftitle={The collref Package}}
\author{Niklas Beisert\\[2ex]
  Institut f\"ur Theoretische Physik\\
  Eidgen\"ossische Technische Hochschule Z\"urich\\
  Wolfgang-Pauli-Strasse 27, 8093 Z\"urich, Switzerland\\[1ex]
  \href{mailto:nbeisert@itp.phys.ethz.ch}
  {\texttt{nbeisert@itp.phys.ethz.ch}}}
\hypersetup{pdfauthor={Niklas Beisert}}
\hypersetup{pdfsubject={Manual for the LaTeX2e Package collref}}
\date{17 January 2018, \textsf{v2.0c}}
\maketitle

\begin{abstract}\noindent
\textsf{collref} is a \LaTeXe{} package to automatically collect
multiple |\bibitem| references which always appear in the same sequence
in |\cite| into a single |\bibitem| block.
\end{abstract}

\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}

Suppose a manuscript uses the following set of four references:
%
\begin{thebib}
\item Reference A
\item Reference B
\item Reference C
\item Reference D
\end{thebib}
%
Now if references B and C cover similar or related material,
they might always be cited together as in ``[\ldots, 2, 3, \ldots]''
throughout the manuscript.
In some (physics) journals it is then customary to collect the two
references into a single reference
%
\begin{thebib}
\item Reference A
\item Reference B
\par Reference C
\item Reference D
\end{thebib}
%
and cite it by ``[\ldots, 2, \ldots]''.
The package \textsf{collref} automates this process
by analysing the |\cite| commands
and identifying blocks of references
which always appear in conjunction.
These blocks are collapsed to a single item
in the bibliography.
Please note that \textsf{collref} requires the sequence
of |\bibitem| entries to match with
the sequence of |\cite| blocks.
This is most easily achieved through the use of \BibTeX{}
with any \emph{unsorted} style.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Usage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Inclusion.}

To use \textsf{collref} simply add the command
\begin{center}|\usepackage{collref}|\end{center}
to the preamble of your \LaTeX{} document.
No further interaction is required.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Punctuation.}

\textsf{collref} provide basic punctuation between collected references.
This is specified through the package options
|\usepackage[|\textit{opt}|]{collref}|
where \textit{opt} is one of the following
\par\vspace{2ex}\noindent%
\begin{minipage}[t]{0.24\linewidth}
\centerline{\texttt{nosep} (default)}\par\vspace{1ex}
no separator:
\begin{thebib}
\item A
\item B C
\item D
\end{thebib}
\end{minipage}%
\begin{minipage}[t]{0.24\linewidth}
\centerline{\texttt{parsep}}\par\vspace{1ex}
separated by |\par|:
\begin{thebib}
\item A
\item B
\par C
\item D
\end{thebib}
\end{minipage}%
\begin{minipage}[t]{0.24\linewidth}
\centerline{\texttt{bulletsep}}\par\vspace{1ex}
separated by `\textbullet':
\begin{thebib}
\item A
\item B \textbullet{} C
\item D
\end{thebib}
\end{minipage}%
\begin{minipage}[t]{0.28\linewidth}
\centerline{\texttt{punctsep}}\par\vspace{1ex}
punctuated by `;' and '.':
\begin{thebib}
\item A .
\item B ; C .
\item D .
\end{thebib}
cf.\ note on spacing below.
\end{minipage}%
\par\vspace{2ex}\noindent
%
Alternative separators can be specified in the preamble through the
command:
\begin{center}
|\collectsep[|\textit{punctuation}|]{|\textit{separator}|}|
\end{center}
The \textit{separator} appears between references in a block and
the \textit{punctuation} at the end of a block of references.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Bibliography Preparation.}

Please note that only such blocks of references can be collapsed
which appear in the same order for
|\cite| commands as for |thebibliography|.
It is recommended to prepare the bibliography through \BibTeX{}
which does this automatically.
You must use a style which does not sort the references
but preserves the order in which they were |\cite|'d,
e.g.\ \texttt{unsrt.bst}.

Also note that \textsf{collref} suppresses
new paragraphs invoked by empty lines in the bibliography.
This allows to use standard \BibTeX{} styles
which commonly separate reference entries by empty lines.
If these empty lines would be expanded to new paragraphs,
\textsf{collref} would not be able to join two references properly.
Therefore new paragraphs have to be invoked by the
command |\par|.

If you wish to use the style \texttt{punctsep}, please
refer to the following note on spacing and punctuation.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Spacing and Punctuation.}

References are usually punctuated in some way.
Three of the predefined styles --
\texttt{nosep}, \texttt{parsep} and \texttt{bulletsep} --
preserve the punctuation from the bibliography.

The fourth predefined style -- \texttt{punctsep} --
automatically performs the punctuation.
This however requires care in the preparation
of the bibliography:
The entries have to be provided \emph{without} punctuation.
Furthermore, there must not be \emph{whitespaces} at the
end of an entry.
They can be suppressed with `|%|'
or |\ignorespaces|
directly following the last word of the entry.
See Appendix \ref{sec:sample} for an example.
The standard \BibTeX{} styles, e.g.\ \texttt{unsrt.bst},
have to be adjusted to remove the punctuation and whitespaces.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Control.}


The package \textsf{collref} provides one command to control
which references (not) to collect:
%
\begin{center}
|\nocollect{|\textit{label}|}|
\end{center}
%
It ensures that the label \textit{label} starts
a new block of references.
It is not collapsed with earlier references.
Later references, however, can still be collapsed
to the end of \textit{label}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Labels for Blocks of References.}

While \textsf{collref} aims to automatically
collect similar references into a single block, it is often
convenient for the author to refer to such blocks
with a single citation label.
Standard \TeX/\LaTeX{} commands can be used to define such a block:
\begin{center}
|\newcommand{|\textit{$\backslash$blocklabel}|}{|\textit{label1, label2, \ldots}|}|
\end{center}
Subsequently this block can be referenced with
|\cite{|\textit{\ldots, $\backslash$blocklabel, \ldots}|}|.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Information}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Copyright}

\begingroup
\parskip1ex
\parindent0pt

Copyright \copyright{} 2003--2018 Niklas Beisert

This work may be distributed and/or modified under the
conditions of the \LaTeX{} Project Public License, either version 1.3
of this license or (at your option) any later version.
The latest version of this license is in
  \url{http://www.latex-project.org/lppl.txt}
and version 1.3 or later is part of all distributions of \LaTeX{}
version 2005/12/01 or later.

This work has the LPPL maintenance status `maintained'.

The Current Maintainer of this work is Niklas Beisert.

This work consists of the files |README.txt|, |collref.ins| and |collref.dtx|
as well as the derived files |collref.sty|, |collsamp.tex| and |collref.pdf|.

\endgroup

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Files and Installation}

The package consists of the files
%
\begin{center}
\begin{tabular}{ll}
    |README.txt|  & readme file \\
    |collref.ins| & installation file \\
    |collref.dtx| & source file \\
    |collref.sty| & package file \\
    |collsamp.tex|& sample file \\
    |collref.pdf| & manual
\end{tabular}
\end{center}
%
The distribution consists of the files
|README.txt|, |collref.ins| and |collref.dtx|.
%
\begin{itemize}
\item
Run (pdf)\LaTeX{} on |collref.dtx|
to compile the manual |collref.pdf| (this file).
\item
Run \LaTeX{} on |collref.ins| to create the package |collref.sty|
and the sample |collsamp.tex|.
Copy the file |collref.sty| to an appropriate directory of your \LaTeX{}
distribution, e.g.\ \textit{texmf-root}|/tex/latex/collref|.
Alternatively, you may copy |collref.sty| to the local directories of
manuscripts for which you wish to use \textsf{collref}.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Related CTAN Packages}

The objective and some of the implementation
of the \textsf{collref} package is similar to the CTAN packages
\href{http://www.ctan.org/pkg/mcite}
{\textsf{mcite}} by Thorsten Ohl
and \href{http://www.ctan.org/pkg/mciteplus}
{\textsf{mciteplus}} by Michael Shell,
but the functionality is different is several respects:
%
\begin{itemize}
\item
\textsf{collref} is intended to work transparently:
\LaTeX{} documents which compile with \textsf{collref}
should also compile fine without invoking \textsf{collref}
(obviously without collected references).
The package decides automatically which references
can be collapsed,
no further interaction of the author is required.

\textsf{mcite} and \textsf{mciteplus} leave the
decision/duty to collapse certain references
using the modified syntax |\cite{A,*B,*C}|.

\item
\textsf{mcite} and \textsf{mciteplus} are intended to handle punctuations
in collapsed references correctly.
This requires a specialised \BibTeX{} style.

No effort is made in \textsf{collref} in this regard.
Some minor modification in \texttt{collref.sty}
together with a modified \BibTeX{} style
might achieve basic punctuation features similar to \textsf{mcite}.
\end{itemize}
%
The package \textsf{collref} has been tested with other
CTAN packages concerned with citations and the bibliography:
%
\begin{itemize}
\item
\textsf{collref} works in conjunction with
\href{http://www.ctan.org/pkg/cite}{\textsf{cite}}.
Note that you must load \textsf{cite} \emph{before} \textsf{collref}
so that the latter can pass the correctly reduced list of
references down to \textsf{cite}.
Tested with v5.1 and v5.3 (2010/09/10).

\item
\textsf{collref} works in conjunction with
\href{http://www.ctan.org/pkg/hyperref}{\textsf{hyperref}}.
The two packages can be loaded in any sequence.
Tested with v6.78s and v6.83m (2012/11/06).

\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\subsection{Feature Suggestions}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Revision History}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v2.0c:} 2018/01/17

\begin{itemize}
\item
manual rearranged
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v2.0b:} 2014/08/31

\begin{itemize}
\item
updated author addresses
\item
minor internal changes
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v2.0:} 2009/09/07

\begin{itemize}
\item
proper punctuation added
(thanks to Oleg Zhirov for suggestion)
\item
blocks of references enabled
(thanks to Oleg Zhirov for suggestion)
\item
manual extended
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v1.0:} 2009/06/09

\begin{itemize}
\item
streamlined detection of chains
\item
manual and installation package added
\item
renamed package to \textsf{collref} due to name clash on CTAN
\item
first version published on CTAN
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.9:}

\begin{itemize}
\item
package named \textsf{collect}; unpublished
\end{itemize}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\appendix

\settowidth\MacroIndent{\rmfamily\scriptsize 000\ }
\parskip1ex
\parindent0pt

 \DocInput{collref.dtx}

\end{document}
%</driver>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Sample File}\label{sec:sample}
%\iffalse
%<*sample>
%\fi
%
% In this section we provide a sample file.
%
%    \begin{macrocode}
\documentclass{article}

%%\usepackage{cite}
\usepackage[punctsep]{collref}
%%\usepackage{hyperref}

\begin{document}

\def\tworef{c8,c9}

\cite{c1,c2,c3,c4}
\nocollect{c3}
\cite{c5,c6,c7,\tworef}
\cite{c5,c6,c7}
\cite{c7,\tworef}

\begin{thebibliography}{11}
\bibitem{c1} reference 1%
\bibitem{c2} reference 2%
\bibitem{c3} reference 3%
\bibitem{c4} reference 4%
\bibitem{c5} reference 5
\bibitem{c6} reference 6
\bibitem{c7} reference 7 %
\bibitem{c8} reference 8\ignorespaces
\bibitem{c9} reference 9\ignorespaces
\end{thebibliography}

\end{document}
%    \end{macrocode}
%\iffalse
%</sample>
%\fi
% It produces the output:
% \vspace{2ex}
%
% [1, 2]  [3, 4, 5] [3, 4] [4, 5]
%
% \begin{thebib}
% \item reference 1; reference 2.
% \item reference 3; reference 4.
% \item reference 5 ; reference 6 .
% \item reference 7 .
% \item reference 8; reference 9.
% \end{thebib}
% Note the different behaviour for references 5, 6 and 7
% for which trailing whitespaces were not removed.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Implementation}
%\iffalse
%<*package>
%\fi
%
% In this section we describe the package |collref.sty|.

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Internal Lists.}
%
% For each bibliography label \textit{label} the package
% maintains a predecessor |\nc@p@|\textit{label}
% and a successor |\nc@s@|\textit{label}.
% These are initially undefined.
% When a label \textit{label} is first cited these labels
% are set to the \textit{predecessor} and \textit{successor} labels, respectively,
% in |\cite{|\textit{\ldots, predecessor, label, successor, \ldots}|}|.
% An empty |\nc@p@|\textit{label} or |\nc@s@|\textit{label}
% refers to the beginning and end of a block, respectively.
% Whenever |\cite| finds conflicting blocks
% (non-matching predecessors or successors in two |\cite|'s),
% it terminates the blocks to the maximum common overlap.
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Interface.}
%
% The package provides two public commands, described above:
%    \begin{macrocode}
\newcommand{\collectsep}[2][]{\def\nc@punct{#1}\def\nc@sep{#2}}
\newcommand{\nocollect}[1]{\nc@breakbefore{#1}\ignorespaces}
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Package Options.}
%
% The package provides four predefined separators described above:
%    \begin{macrocode}
\DeclareOption{nosep}{\collectsep{}}
\DeclareOption{parsep}{\collectsep{\par}}
\DeclareOption{bulletsep}{\collectsep{\textbullet{} }}
\DeclareOption{punctsep}{\collectsep[.]{; }}
\ExecuteOptions{nosep}
\ProcessOptions
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Internal Commands.}
%
% Some internal commands for abbreviation:
%    \begin{macrocode}
\newcommand{\nc@getcsname}[1]{\csname #1\endcsname}
\newcommand{\nc@setcsname}[2]{\expandafter\xdef\csname #1\endcsname{#2}}
%    \end{macrocode}
% Command to terminate the chain before a label:
% The predecessor of the label is terminated.
% If the predecessor was active, its successor is also terminated.
%    \begin{macrocode}
\newcommand{\nc@breakbefore}[1]{%
  \edef\nc@citepred{\@ifundefined{nc@p@#1}{}{\nc@getcsname{nc@p@#1}}}%
  \ifx\nc@citepred\@empty\else\nc@setcsname{nc@s@\nc@citepred}{}\fi%
  \nc@setcsname{nc@p@#1}{}%
}
%    \end{macrocode}
% Command to terminate the chain after a label. Similar to the above command.
%    \begin{macrocode}
\newcommand{\nc@breakafter}[1]{%
  \edef\nc@citesucc{\@ifundefined{nc@s@#1}{}{\nc@getcsname{nc@s@#1}}}%
  \ifx\nc@citesucc\@empty\else\nc@setcsname{nc@p@\nc@citesucc}{}\fi%
  \nc@setcsname{nc@s@#1}{}%
}
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Citations.}
%
% Hack for |\@citex|:
% It is assumed that (as in \LaTeXe) |\cite| eventually
% passes down to |\@citex|.
%    \begin{macrocode}
\let\nc@old@citex\@citex

\def\@citex[#1]#2{%
  \let\nc@citecomma\@empty%
  \let\nc@citestring\@empty%
  \let\nc@citelast\@empty%
  \edef\nc@citelist{#2}%
%    \end{macrocode}
% Main loop to process the arguments of |\cite|.
% The current label is stored in |\nc@citethis|.
%    \begin{macrocode}
  \@for\nc@citethis:={\nc@citelist}\do{%
    \edef\nc@citethis{\expandafter\@firstofone\nc@citethis\@empty}%
%    \end{macrocode}
% The first entry has no predecessor, terminate the chain.
%    \begin{macrocode}
    \ifx\nc@citelast\@empty%
      \nc@breakbefore{\nc@citethis}%
    \else%
%    \end{macrocode}
% Non-first entry: Fill undefined successor and predecessors entries
% with the current chain sequence.
%    \begin{macrocode}
      \@ifundefined{nc@s@\nc@citelast}%
                   {\nc@setcsname{nc@s@\nc@citelast}{\nc@citethis}}{}%
      \@ifundefined{nc@p@\nc@citethis}%
                   {\nc@setcsname{nc@p@\nc@citethis}{\nc@citelast}}{}%
%    \end{macrocode}
% Get the successor and predecessors for the last and current entry, respectively.
%    \begin{macrocode}
      \edef\nc@citesucc{\nc@getcsname{nc@s@\nc@citelast}}%
      \edef\nc@citepred{\nc@getcsname{nc@p@\nc@citethis}}%
%    \end{macrocode}
% In case of mismatching chains: terminate all links.
%    \begin{macrocode}
      \ifx\nc@citesucc\nc@citethis%
        \ifx\nc@citepred\nc@citelast%
        \else%
          \nc@breakafter{\nc@citelast}%
          \nc@breakbefore{\nc@citethis}%
        \fi%
      \else%
        \nc@breakafter{\nc@citelast}%
        \nc@breakbefore{\nc@citethis}%
      \fi%
    \fi%
%    \end{macrocode}
% Get content of |\b@|\textit{label} entry to find out
% whether the |\bibitem{label}| entry exists.
% We need to take special care of extended label definitions in \textsf{hyperref}.
%    \begin{macrocode}
    {\def\hyper@@link[##1]##2##3##4{##4}%
      \xdef\nc@citelabel{\nc@getcsname{b@\nc@citethis}}}%
%    \end{macrocode}
% Only add those labels which actually exist to the pass-on string.
% This removes collaped references from the citation marks.
%    \begin{macrocode}
    \ifx\nc@citelabel\@empty\else%
      \edef\nc@citestring{\nc@citestring\nc@citecomma\nc@citethis}%
    \fi%
%    \end{macrocode}
% Write |\citation| tag to .aux file in original order.
% Some duplicate |\citation|'s will be written by
% the original |\citex| code, but these will have no impact.
%    \begin{macrocode}
    \if@filesw\immediate\write\@auxout{\string\citation{\nc@citethis}}\fi%
%    \end{macrocode}
% Continue to next label.
%    \begin{macrocode}
    \edef\nc@citelast{\nc@citethis}%
    \def\nc@citecomma{,}%
  }%
%    \end{macrocode}
% The last entry has no successor, terminate the chain.
%    \begin{macrocode}
  \nc@breakafter{\nc@citelast}%
%    \end{macrocode}
% Pass on to original \LaTeX{} code.
%    \begin{macrocode}
  \nc@old@citex[#1]{\nc@citestring}%
}
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Bibliography.}
%
% Enhance the |thebibliography| environment to
% a) set the |\nc@biblast| label to something,
%    and empty |\nc@nextpunct|
%    (no predecessor for the first entry),
% b) convert linebreaks into whitespaces (avoid implicit |\par|'s), and
% c) put the final punctuation for the last entry.
%
%    \begin{macrocode}
\let\nc@old@thebibliography\thebibliography
\let\nc@old@endthebibliography\endthebibliography

\def\thebibliography{%
  \xdef\nc@biblast{asldjfhasklfh}%
  \xdef\nc@nextpunct{}%
  \catcode`\^^M=10%
\nc@old@thebibliography}

\def\endthebibliography{%
  \nc@nextpunct%
\nc@old@endthebibliography}
%    \end{macrocode}

% Overwrite |\bibitem|:
% It is assumed that the native \LaTeXe{} code
% is equivalent but with the \LaTeX{}
% internals |\@lbibitem| and |\@bibitem|.
% Some other packages may also redefine |\bibitem|
% and this will inevitable cause compatibility issues.
% This implementation is safe with current versions of \textsf{hyperref}.
%    \begin{macrocode}
\def\bibitem{\@ifnextchar[\nc@lbibitem\nc@bibitem}
%    \end{macrocode}
%
% |\nc@noitem| is invoked in place of the original |\@bibitem| or |\@lbibitem|
% for collapsed references:
%    \begin{macrocode}
\def\nc@noitem#1{%
  \if@filesw\immediate\write\@auxout{\string\bibcite{#1}{}}\fi%
\ignorespaces}
%    \end{macrocode}

% The hack for |\@bibitem|: It checks whether
% this reference is part of a block.
% If so, put separator and collect by |\nc@noitem|.
% Otherwise put punctuation and pass down to |\@bibitem|.
% Finally let |\nc@biblast| point to current item,
% and fill the punctuation |\nc@nextpunct| for the next entry.
%    \begin{macrocode}
\def\nc@bibitem#1{%
  \edef\nc@bibpred{\@ifundefined{nc@p@#1}{}{\nc@getcsname{nc@p@#1}}}%
  \ifx\nc@biblast\nc@bibpred\nc@sep\nc@noitem{#1}%
    \else\nc@nextpunct\@bibitem{#1}\fi%
  \xdef\nc@biblast{#1}%
  \xdef\nc@nextpunct{\nc@punct}%
\ignorespaces}
%    \end{macrocode}

% Similar hack for |@lbibitem|:
%    \begin{macrocode}
\def\nc@lbibitem[#1]#2{%
  \edef\nc@bibpred{\@ifundefined{nc@p@#2}{}{\nc@getcsname{nc@p@#2}}}%
  \ifx\nc@biblast\nc@bibpred\nc@sep\nc@noitem{#2}%
    \else\nc@nextpunct\@lbibitem[#1]{#2}\fi%
  \xdef\nc@biblast{#2}%
  \xdef\nc@nextpunct{\nc@punct}%
\ignorespaces}
%    \end{macrocode}

%\iffalse
%</package>
%\fi
%
\endinput