Debian Codegraph @

texmf-dist/source/latex/collref/collref.dtx

raw
1 %
2 % \iffalse meta-comment
3 %
4 % collref.dtx Copyright (C) 2003-2025 Niklas Beisert
5 %
6 % This work may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in
10 % https://www.latex-project.org/lppl.txt
11 % and version 1.3c or later is part of all distributions of LaTeX
12 % version 2008 or later.
13 %
14 % This work has the LPPL maintenance status `maintained'.
15 %
16 % The Current Maintainer of this work is Niklas Beisert.
17 %
18 % This work consists of the files collref.dtx and collref.ins
19 % and the derived files collref.sty and collsamp.tex
20 %
21 %<package|sample>\NeedsTeXFormat{LaTeX2e}[1996/12/01]
22 %<package>\ProvidesPackage{collref}[2025/03/25 v2.0.4 Collect References]
23 %<sample>\ProvidesFile{collsamp.tex}[2025/03/25 v2.0.4 Sample for Collect References]
24 %<*driver>
25 \def\thedate#1{2025/03/25}\def\theversion#1{v2.0.4}
26 \ProvidesFile{collref.dtx}[\thedate{} \theversion{} collref reference manual file]
27 \PassOptionsToClass{10pt,a4paper}{article}
28 \documentclass{ltxdoc}
29
30 \usepackage[margin=35mm]{geometry}
31 \usepackage[hyperindex=false]{hyperref}
32 \usepackage{hyperxmp}
33 \usepackage[usenames]{color}
34
35 \AddToHook{begindocument/before}{\hypersetup{colorlinks=false}}
36 \hypersetup{urlbordercolor={.5 1 1}}
37 \hypersetup{linkbordercolor={1 .7 .7}}
38 \AddToHook{begindocument/before}{\hypersetup{pdfstartview=FitH}}
39 \hypersetup{keeppdfinfo=true}
40 \hypersetup{pdfsource={}}
41 \hypersetup{pdflang={en-UK}}
42 \hypersetup{pdfurl={https://ctan.org/pkg/collref}}
43 \hypersetup{pdfcopyright={Copyright 2003-2025 Niklas Beisert.
44 This work may be distributed and/or modified under the
45 conditions of the LaTeX Project Public License, either version 1.3
46 of this license or (at your option) any later version.}}
47 \hypersetup{pdflicenseurl={https://www.latex-project.org/lppl.txt}}
48 \hypersetup{pdfcontactaddress={ETH Zurich, ITP, HIT K,
49 Wolfgang-Pauli-Strasse 27}}
50 \hypersetup{pdfcontactpostcode={8093}}
51 \hypersetup{pdfcontactcity={Zurich}}
52 \hypersetup{pdfcontactcountry={Switzerland}}
53 \hypersetup{pdfcontactemail={[email protected]}}
54 \hypersetup{pdfcontacturl={https://people.phys.ethz.ch/\xmptilde nbeisert/}}
55
56 \newcommand{\markpkg}[1]{\textsf{#1}}
57 \newcommand{\secref}[1]{\hyperref[#1]{section \ref*{#1}}}
58 \newcommand{\ctanref}[2]{\href{https://ctan.org/#1}{#2}}
59 \newcommand{\ctanpkg}[1]{\ctanref{pkg/#1}{\markpkg{#1}}}
60
61 \def\textvert{\texttt{\char"7C}}
62
63 \parskip1ex
64 \parindent0pt
65 \let\olditemize\itemize
66 \def\itemize{\olditemize\parskip0pt}
67
68 \newenvironment{thebib}
69 {\list{[\theenumi]}{\parsep0pt\usecounter{enumi}}}
70 {\endlist}
71
72 \begin{document}
73
74 \title{The \markpkg{collref} Package\thanks{%
75 Earlier versions developed at: Max-Planck-Institut f\"ur Gravitationsphysik
76 (Albert-Einstein-Institut), Potsdam, Germany;
77 \texttt{AEI-2009-054}}}
78 \hypersetup{pdftitle={The collref Package}}
79 \author{Niklas Beisert\\[2ex]
80 Institut f\"ur Theoretische Physik\\
81 Eidgen\"ossische Technische Hochschule Z\"urich\\
82 Wolfgang-Pauli-Strasse 27, 8093 Z\"urich, Switzerland\\[1ex]
83 \href{mailto:[email protected]}
84 {\texttt{[email protected]}}}
85 \hypersetup{pdfauthor={Niklas Beisert}}
86 \hypersetup{pdfsubject={Manual for the LaTeX2e Package collref}}
87 \date{\thedate{}, \theversion{}\\[1ex]
88 \url{https://ctan.org/pkg/collref}}
89 \maketitle
90
91 \begin{abstract}\noindent
92 \markpkg{collref} is a \LaTeXe{} package to automatically collect
93 multiple |\bibitem| references which always appear in the same sequence
94 in |\cite| into a single |\bibitem| block.
95 \end{abstract}
96
97 \begingroup
98 \parskip0ex
99 \tableofcontents
100 \endgroup
101
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 \section{Introduction}
105
106 Suppose a manuscript uses the following set of four references:
107 %
108 \begin{thebib}
109 \item Reference A
110 \item Reference B
111 \item Reference C
112 \item Reference D
113 \end{thebib}
114 %
115 Now if references B and C cover similar or related material,
116 they might always be cited together as in ``[\ldots, 2, 3, \ldots]''
117 throughout the manuscript.
118 In some (physics) journals it is then customary to collect the two
119 references into a single reference
120 %
121 \begin{thebib}
122 \item Reference A
123 \item Reference B
124 \par Reference C
125 \item Reference D
126 \end{thebib}
127 %
128 and cite it by ``[\ldots, 2, \ldots]''.
129 The package \ctanpkg{collref} automates this process
130 by analysing the |\cite| commands
131 and identifying blocks of references
132 which always appear in conjunction.
133 These blocks are collapsed to a single item
134 in the bibliography.
135 Please note that \ctanpkg{collref} requires the sequence
136 of |\bibitem| entries to match with
137 the sequence of |\cite| blocks.
138 This is most easily achieved through the use of \BibTeX{}
139 with any \emph{unsorted} style.
140
141
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 \section{Usage}
145
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 \paragraph{Inclusion.}
148
149 To use \ctanpkg{collref} simply add the command
150 \begin{center}|\usepackage{collref}|\end{center}
151 to the preamble of your \LaTeX{} document.
152 No further interaction is required.
153
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 \paragraph{Punctuation.}
156
157 \ctanpkg{collref} provide basic punctuation between collected references.
158 This is specified through the package options
159 |\usepackage[|\textit{opt}|]{collref}|
160 where \textit{opt} is one of the following
161 \par\vspace{2ex}\noindent%
162 \begin{minipage}[t]{0.24\linewidth}
163 \centerline{\texttt{nosep} (default)}\par\vspace{1ex}
164 no separator:
165 \begin{thebib}
166 \item A
167 \item B C
168 \item D
169 \end{thebib}
170 \end{minipage}%
171 \begin{minipage}[t]{0.24\linewidth}
172 \centerline{\texttt{parsep}}\par\vspace{1ex}
173 separated by |\par|:
174 \begin{thebib}
175 \item A
176 \item B
177 \par C
178 \item D
179 \end{thebib}
180 \end{minipage}%
181 \begin{minipage}[t]{0.24\linewidth}
182 \centerline{\texttt{bulletsep}}\par\vspace{1ex}
183 separated by `\textbullet':
184 \begin{thebib}
185 \item A
186 \item B \textbullet{} C
187 \item D
188 \end{thebib}
189 \end{minipage}%
190 \begin{minipage}[t]{0.28\linewidth}
191 \centerline{\texttt{punctsep}}\par\vspace{1ex}
192 punctuated by `;' and '.':
193 \begin{thebib}
194 \item A .
195 \item B ; C .
196 \item D .
197 \end{thebib}
198 cf.\ note on spacing below.
199 \end{minipage}%
200 \par\vspace{2ex}\noindent
201 %
202 Alternative separators can be specified in the preamble through the
203 command:
204 \begin{center}
205 |\collectsep[|\textit{punctuation}|]{|\textit{separator}|}|
206 \end{center}
207 The \textit{separator} appears between references in a block and
208 the \textit{punctuation} at the end of a block of references.
209
210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 \paragraph{Bibliography Preparation.}
212
213 Please note that only such blocks of references can be collapsed
214 which appear in the same order for
215 |\cite| commands as for |thebibliography|.
216 It is recommended to prepare the bibliography through \BibTeX{}
217 which does this automatically.
218 You must use a style which does not sort the references
219 but preserves the order in which they were |\cite|'d,
220 e.g.\ \texttt{unsrt.bst}.
221
222 Also note that \ctanpkg{collref} suppresses
223 new paragraphs invoked by empty lines in the bibliography.
224 This allows to use standard \BibTeX{} styles
225 which commonly separate reference entries by empty lines.
226 If these empty lines would be expanded to new paragraphs,
227 \ctanpkg{collref} would not be able to join two references properly.
228 Therefore new paragraphs have to be invoked by the
229 command |\par|.
230
231 If you wish to use the style \texttt{punctsep}, please
232 refer to the following note on spacing and punctuation.
233
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 \paragraph{Spacing and Punctuation.}
236
237 References are usually punctuated in some way.
238 Three of the predefined styles --
239 \texttt{nosep}, \texttt{parsep} and \texttt{bulletsep} --
240 preserve the punctuation from the bibliography.
241
242 The fourth predefined style -- \texttt{punctsep} --
243 automatically performs the punctuation.
244 This however requires care in the preparation
245 of the bibliography:
246 The entries have to be provided \emph{without} punctuation.
247 Furthermore, there must not be \emph{whitespaces} at the
248 end of an entry.
249 They can be suppressed with `|%|'
250 or |\ignorespaces|
251 directly following the last word of the entry.
252 See Appendix \ref{sec:sample} for an example.
253 The standard \BibTeX{} styles, e.g.\ \texttt{unsrt.bst},
254 have to be adjusted to remove the punctuation and whitespaces.
255
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 \paragraph{Control.}
258
259
260 The package \ctanpkg{collref} provides one command to control
261 which references (not) to collect:
262 %
263 \begin{center}
264 |\nocollect{|\textit{label}|}|
265 \end{center}
266 %
267 It ensures that the label \textit{label} starts
268 a new block of references.
269 It is not collapsed with earlier references.
270 Later references, however, can still be collapsed
271 to the end of \textit{label}.
272
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 \paragraph{Labels for Blocks of References.}
275
276 While \ctanpkg{collref} aims to automatically
277 collect similar references into a single block, it is often
278 convenient for the author to refer to such blocks
279 with a single citation label.
280 Standard \TeX/\LaTeX{} commands can be used to define such a block:
281 \begin{center}
282 |\newcommand{|\textit{$\backslash$blocklabel}|}{|\textit{label1, label2, \ldots}|}|
283 \end{center}
284 Subsequently this block can be referenced with
285 |\cite{|\textit{\ldots, $\backslash$blocklabel, \ldots}|}|.
286
287
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 \section{Information}
291
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 \subsection{Copyright}
294
295 Copyright \copyright{} 2003--2025 Niklas Beisert
296
297 This work may be distributed and/or modified under the
298 conditions of the \LaTeX{} Project Public License, either version 1.3
299 of this license or (at your option) any later version.
300 The latest version of this license is in
301 \url{https://www.latex-project.org/lppl.txt}
302 and version 1.3c or later is part of all distributions of \LaTeX{}
303 version 2008 or later.
304
305 This work has the LPPL maintenance status `maintained'.
306
307 The Current Maintainer of this work is Niklas Beisert.
308
309 This work consists of the files |README.txt|, |collref.ins| and |collref.dtx|
310 as well as the derived files |collref.sty|, |collsamp.tex| and |collref.pdf|.
311
312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 \subsection{Files and Installation}
314
315 The package consists of the files
316 %
317 \begin{center}
318 \begin{tabular}{ll}
319 |README.txt| & readme file \\
320 |collref.ins| & installation file \\
321 |collref.dtx| & source file \\
322 |collref.sty| & package file \\
323 |collsamp.tex| & sample file \\
324 |collref.pdf| & manual
325 \end{tabular}
326 \end{center}
327 %
328 The distribution consists of the files
329 |README.txt|, |collref.ins| and |collref.dtx|.
330 %
331 \begin{itemize}
332 \item
333 Run (pdf)\LaTeX{} on |collref.dtx|
334 to compile the manual |collref.pdf| (this file).
335 \item
336 Run \LaTeX{} on |collref.ins| to create the package |collref.sty|
337 and the sample |collsamp.tex|.
338 Copy the file |collref.sty| to an appropriate directory of your \LaTeX{}
339 distribution, e.g.\ \textit{texmf-root}|/tex/latex/collref|.
340 \end{itemize}
341
342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 \subsection{Related CTAN Packages}
344
345 The objective and some of the implementation
346 of the \ctanpkg{collref} package is similar to the CTAN packages
347 \ctanpkg{mcite} by Thorsten Ohl
348 and \ctanpkg{mciteplus} by Michael Shell,
349 but the functionality is different is several respects:
350 %
351 \begin{itemize}
352 \item
353 \ctanpkg{collref} is intended to work transparently:
354 \LaTeX{} documents which compile with \ctanpkg{collref}
355 should also compile fine without invoking \ctanpkg{collref}
356 (obviously without collected references).
357 The package decides automatically which references
358 can be collapsed,
359 no further interaction of the author is required.
360
361 \ctanpkg{mcite} and \ctanpkg{mciteplus} leave the
362 decision/duty to collapse certain references
363 using the modified syntax |\cite{A,*B,*C}|.
364
365 \item
366 \ctanpkg{mcite} and \ctanpkg{mciteplus} are intended to handle punctuations
367 in collapsed references correctly.
368 This requires a specialised \BibTeX{} style.
369
370 No effort is made in \ctanpkg{collref} in this regard.
371 Some minor modification in |collref.sty|
372 together with a modified \BibTeX{} style
373 might achieve basic punctuation features similar to \ctanpkg{mcite}.
374 \end{itemize}
375 %
376 The package \ctanpkg{collref} has been tested with other
377 CTAN packages concerned with citations and the bibliography:
378 %
379 \begin{itemize}
380 \item
381 \ctanpkg{collref} works in conjunction with
382 \ctanpkg{cite}.
383 Note that you must load \ctanpkg{cite} \emph{before} \ctanpkg{collref}
384 so that the latter can pass the correctly reduced list of
385 references down to \ctanpkg{cite}.
386 Tested with v5.1 and v5.3 (2010/09/10).
387
388 \item
389 \ctanpkg{collref} works in conjunction with
390 \ctanpkg{hyperref}.
391 The two packages can be loaded in any sequence.
392 Tested with v6.78s and v6.83m (2012/11/06).
393
394 \end{itemize}
395
396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397 %\subsection{Feature Suggestions}
398
399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
400 \subsection{Revision History}
401
402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403 \iffalse
404 \paragraph{vN.N.N+:} 20YY/MM/NN
405
406 \begin{itemize}
407 \item
408 \ldots
409 \end{itemize}
410 \fi
411
412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 \paragraph{v2.0.4:} 2025/03/25
414
415 \begin{itemize}
416 \item
417 maintenance and manual update
418 \end{itemize}
419
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 \paragraph{v2.0c:} 2018/01/17
422
423 \begin{itemize}
424 \item
425 manual rearranged
426 \end{itemize}
427
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 \paragraph{v2.0b:} 2014/08/31
430
431 \begin{itemize}
432 \item
433 updated author addresses
434 \item
435 minor internal changes
436 \end{itemize}
437
438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
439 \paragraph{v2.0:} 2009/09/07
440
441 \begin{itemize}
442 \item
443 proper punctuation added
444 (thanks to Oleg Zhirov for suggestion)
445 \item
446 blocks of references enabled
447 (thanks to Oleg Zhirov for suggestion)
448 \item
449 manual extended
450 \end{itemize}
451
452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
453 \paragraph{v1.0:} 2009/06/09
454
455 \begin{itemize}
456 \item
457 streamlined detection of chains
458 \item
459 manual and installation package added
460 \item
461 renamed package to \ctanpkg{collref} due to name clash on CTAN
462 \item
463 first version published on CTAN
464 \end{itemize}
465
466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
467 \paragraph{v0.9:}
468
469 \begin{itemize}
470 \item
471 package named \markpkg{collect}; unpublished
472 \end{itemize}
473
474
475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 \appendix
479
480 \settowidth\MacroIndent{\rmfamily\scriptsize 000\ }
481
482 \DocInput{collref.dtx}
483
484 \end{document}
485 %</driver>
486 % \fi
487 %
488 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490 % \section{Sample File}\label{sec:sample}
491 %\iffalse
492 %<*sample>
493 %\fi
494 %
495 % In this section we provide a sample file.
496 %
497 % \begin{macrocode}
498 \documentclass{article}
499
500 %%\usepackage{cite}
501 \usepackage[punctsep]{collref}
502 %%\usepackage{hyperref}
503
504 \begin{document}
505
506 \def\tworef{c8,c9}
507
508 \cite{c1,c2,c3,c4}
509 \nocollect{c3}
510 \cite{c5,c6,c7,\tworef}
511 \cite{c5,c6,c7}
512 \cite{c7,\tworef}
513
514 \begin{thebibliography}{11}
515 \bibitem{c1} reference 1%
516 \bibitem{c2} reference 2%
517 \bibitem{c3} reference 3%
518 \bibitem{c4} reference 4%
519 \bibitem{c5} reference 5
520 \bibitem{c6} reference 6
521 \bibitem{c7} reference 7 %
522 \bibitem{c8} reference 8\ignorespaces
523 \bibitem{c9} reference 9\ignorespaces
524 \end{thebibliography}
525
526 \end{document}
527 % \end{macrocode}
528 %\iffalse
529 %</sample>
530 %\fi
531 % It produces the output:
532 % \vspace{2ex}
533 %
534 % [1, 2] [3, 4, 5] [3, 4] [4, 5]
535 %
536 % \begin{thebib}
537 % \item reference 1; reference 2.
538 % \item reference 3; reference 4.
539 % \item reference 5 ; reference 6 .
540 % \item reference 7 .
541 % \item reference 8; reference 9.
542 % \end{thebib}
543 % Note the different behaviour for references 5, 6 and 7
544 % for which trailing whitespaces were not removed.
545 %
546 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 % \section{Implementation}
549 %\iffalse
550 %<*package>
551 %\fi
552 %
553 % In this section we describe the package |collref.sty|.
554
555 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
556 % \paragraph{Internal Lists.}
557 %
558 % For each bibliography label \textit{label} the package
559 % maintains a predecessor |\nc@p@|\textit{label}
560 % and a successor |\nc@s@|\textit{label}.
561 % These are initially undefined.
562 % When a label \textit{label} is first cited these labels
563 % are set to the \textit{predecessor} and \textit{successor} labels, respectively,
564 % in |\cite{|\textit{\ldots, predecessor, label, successor, \ldots}|}|.
565 % An empty |\nc@p@|\textit{label} or |\nc@s@|\textit{label}
566 % refers to the beginning and end of a block, respectively.
567 % Whenever |\cite| finds conflicting blocks
568 % (non-matching predecessors or successors in two |\cite|'s),
569 % it terminates the blocks to the maximum common overlap.
570 %
571 %
572 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573 % \paragraph{Interface.}
574 %
575 % The package provides two public commands, described above:
576 % \begin{macrocode}
577 \newcommand{\collectsep}[2][]{\def\nc@punct{#1}\def\nc@sep{#2}}
578 \newcommand{\nocollect}[1]{\nc@breakbefore{#1}\ignorespaces}
579 % \end{macrocode}
580
581 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582 % \paragraph{Package Options.}
583 %
584 % The package provides four predefined separators described above:
585 % \begin{macrocode}
586 \DeclareOption{nosep}{\collectsep{}}
587 \DeclareOption{parsep}{\collectsep{\par}}
588 \DeclareOption{bulletsep}{\collectsep{\textbullet{} }}
589 \DeclareOption{punctsep}{\collectsep[.]{; }}
590 \ExecuteOptions{nosep}
591 \ProcessOptions
592 % \end{macrocode}
593
594 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
595 % \paragraph{Internal Commands.}
596 %
597 % Some internal commands for abbreviation:
598 % \begin{macrocode}
599 \newcommand{\nc@getcsname}[1]{\csname #1\endcsname}
600 \newcommand{\nc@setcsname}[2]{\expandafter\xdef\csname #1\endcsname{#2}}
601 % \end{macrocode}
602 % Command to terminate the chain before a label:
603 % The predecessor of the label is terminated.
604 % If the predecessor was active, its successor is also terminated.
605 % \begin{macrocode}
606 \newcommand{\nc@breakbefore}[1]{%
607 \edef\nc@citepred{\@ifundefined{nc@p@#1}{}{\nc@getcsname{nc@p@#1}}}%
608 \ifx\nc@citepred\@empty\else\nc@setcsname{nc@s@\nc@citepred}{}\fi%
609 \nc@setcsname{nc@p@#1}{}%
610 }
611 % \end{macrocode}
612 % Command to terminate the chain after a label. Similar to the above command.
613 % \begin{macrocode}
614 \newcommand{\nc@breakafter}[1]{%
615 \edef\nc@citesucc{\@ifundefined{nc@s@#1}{}{\nc@getcsname{nc@s@#1}}}%
616 \ifx\nc@citesucc\@empty\else\nc@setcsname{nc@p@\nc@citesucc}{}\fi%
617 \nc@setcsname{nc@s@#1}{}%
618 }
619 % \end{macrocode}
620
621 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 % \paragraph{Citations.}
623 %
624 % Hack for |\@citex|:
625 % It is assumed that (as in \LaTeXe) |\cite| eventually
626 % passes down to |\@citex|.
627 % \begin{macrocode}
628 \let\nc@old@citex\@citex
629
630 \def\@citex[#1]#2{%
631 \let\nc@citecomma\@empty%
632 \let\nc@citestring\@empty%
633 \let\nc@citelast\@empty%
634 \edef\nc@citelist{#2}%
635 % \end{macrocode}
636 % Main loop to process the arguments of |\cite|.
637 % The current label is stored in |\nc@citethis|.
638 % \begin{macrocode}
639 \@for\nc@citethis:={\nc@citelist}\do{%
640 \edef\nc@citethis{\expandafter\@firstofone\nc@citethis\@empty}%
641 % \end{macrocode}
642 % The first entry has no predecessor, terminate the chain.
643 % \begin{macrocode}
644 \ifx\nc@citelast\@empty%
645 \nc@breakbefore{\nc@citethis}%
646 \else%
647 % \end{macrocode}
648 % Non-first entry: Fill undefined successor and predecessors entries
649 % with the current chain sequence.
650 % \begin{macrocode}
651 \@ifundefined{nc@s@\nc@citelast}%
652 {\nc@setcsname{nc@s@\nc@citelast}{\nc@citethis}}{}%
653 \@ifundefined{nc@p@\nc@citethis}%
654 {\nc@setcsname{nc@p@\nc@citethis}{\nc@citelast}}{}%
655 % \end{macrocode}
656 % Get the successor and predecessors for the last and current entry, respectively.
657 % \begin{macrocode}
658 \edef\nc@citesucc{\nc@getcsname{nc@s@\nc@citelast}}%
659 \edef\nc@citepred{\nc@getcsname{nc@p@\nc@citethis}}%
660 % \end{macrocode}
661 % In case of mismatching chains: terminate all links.
662 % \begin{macrocode}
663 \ifx\nc@citesucc\nc@citethis%
664 \ifx\nc@citepred\nc@citelast%
665 \else%
666 \nc@breakafter{\nc@citelast}%
667 \nc@breakbefore{\nc@citethis}%
668 \fi%
669 \else%
670 \nc@breakafter{\nc@citelast}%
671 \nc@breakbefore{\nc@citethis}%
672 \fi%
673 \fi%
674 % \end{macrocode}
675 % Get content of |\b@|\textit{label} entry to find out
676 % whether the |\bibitem{label}| entry exists.
677 % We need to take special care of extended label definitions in \ctanpkg{hyperref}.
678 % \begin{macrocode}
679 {\def\hyper@@link[##1]##2##3##4{##4}%
680 \xdef\nc@citelabel{\nc@getcsname{b@\nc@citethis}}}%
681 % \end{macrocode}
682 % Only add those labels which actually exist to the pass-on string.
683 % This removes collaped references from the citation marks.
684 % \begin{macrocode}
685 \ifx\nc@citelabel\@empty\else%
686 \edef\nc@citestring{\nc@citestring\nc@citecomma\nc@citethis}%
687 \fi%
688 % \end{macrocode}
689 % Write |\citation| tag to .aux file in original order.
690 % Some duplicate |\citation|'s will be written by
691 % the original |\citex| code, but these will have no impact.
692 % \begin{macrocode}
693 \if@filesw\immediate\write\@auxout{\string\citation{\nc@citethis}}\fi%
694 % \end{macrocode}
695 % Continue to next label.
696 % \begin{macrocode}
697 \edef\nc@citelast{\nc@citethis}%
698 \def\nc@citecomma{,}%
699 }%
700 % \end{macrocode}
701 % The last entry has no successor, terminate the chain.
702 % \begin{macrocode}
703 \nc@breakafter{\nc@citelast}%
704 % \end{macrocode}
705 % Pass on to original \LaTeX{} code.
706 % \begin{macrocode}
707 \nc@old@citex[#1]{\nc@citestring}%
708 }
709 % \end{macrocode}
710
711 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
712 % \paragraph{Bibliography.}
713 %
714 % Enhance the |thebibliography| environment to
715 % a) set the |\nc@biblast| label to something,
716 % and empty |\nc@nextpunct|
717 % (no predecessor for the first entry),
718 % b) convert linebreaks into whitespaces (avoid implicit |\par|'s), and
719 % c) put the final punctuation for the last entry.
720 %
721 % \begin{macrocode}
722 \let\nc@old@thebibliography\thebibliography
723 \let\nc@old@endthebibliography\endthebibliography
724
725 \def\thebibliography{%
726 \xdef\nc@biblast{asldjfhasklfh}%
727 \xdef\nc@nextpunct{}%
728 \catcode`\^^M=10%
729 \nc@old@thebibliography}
730
731 \def\endthebibliography{%
732 \nc@nextpunct%
733 \nc@old@endthebibliography}
734 % \end{macrocode}
735
736 % Overwrite |\bibitem|:
737 % It is assumed that the native \LaTeXe{} code
738 % is equivalent but with the \LaTeX{}
739 % internals |\@lbibitem| and |\@bibitem|.
740 % Some other packages may also redefine |\bibitem|
741 % and this will inevitable cause compatibility issues.
742 % This implementation is safe with current versions of \ctanpkg{hyperref}.
743 % \begin{macrocode}
744 \def\bibitem{\@ifnextchar[\nc@lbibitem\nc@bibitem}
745 % \end{macrocode}
746 %
747 % |\nc@noitem| is invoked in place of the original |\@bibitem| or |\@lbibitem|
748 % for collapsed references:
749 % \begin{macrocode}
750 \def\nc@noitem#1{%
751 \if@filesw\immediate\write\@auxout{\string\bibcite{#1}{}}\fi%
752 \ignorespaces}
753 % \end{macrocode}
754
755 % The hack for |\@bibitem|: It checks whether
756 % this reference is part of a block.
757 % If so, put separator and collect by |\nc@noitem|.
758 % Otherwise put punctuation and pass down to |\@bibitem|.
759 % Finally let |\nc@biblast| point to current item,
760 % and fill the punctuation |\nc@nextpunct| for the next entry.
761 % \begin{macrocode}
762 \def\nc@bibitem#1{%
763 \edef\nc@bibpred{\@ifundefined{nc@p@#1}{}{\nc@getcsname{nc@p@#1}}}%
764 \ifx\nc@biblast\nc@bibpred\nc@sep\nc@noitem{#1}%
765 \else\nc@nextpunct\@bibitem{#1}\fi%
766 \xdef\nc@biblast{#1}%
767 \xdef\nc@nextpunct{\nc@punct}%
768 \ignorespaces}
769 % \end{macrocode}
770
771 % Similar hack for |@lbibitem|:
772 % \begin{macrocode}
773 \def\nc@lbibitem[#1]#2{%
774 \edef\nc@bibpred{\@ifundefined{nc@p@#2}{}{\nc@getcsname{nc@p@#2}}}%
775 \ifx\nc@biblast\nc@bibpred\nc@sep\nc@noitem{#2}%
776 \else\nc@nextpunct\@lbibitem[#1]{#2}\fi%
777 \xdef\nc@biblast{#2}%
778 \xdef\nc@nextpunct{\nc@punct}%
779 \ignorespaces}
780 % \end{macrocode}
781
782 %\iffalse
783 %</package>
784 %\fi
785 %
786 \endinput