summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/collref/collref.sty
blob: 72a6cb030779b2e735e84dcc0a6edf8034acfae0 (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
%%
%% This is file `collref.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% collref.dtx  (with options: `package')
%% 
%% Copyright (C) 2003-2014 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.
%% 
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesPackage{collref}[2014/08/31 v2.0b Collect References]

\newcommand{\collectsep}[2][]{\def\nc@punct{#1}\def\nc@sep{#2}}
\newcommand{\nocollect}[1]{\nc@breakbefore{#1}\ignorespaces}

\DeclareOption{nosep}{\collectsep{}}
\DeclareOption{parsep}{\collectsep{\par}}
\DeclareOption{bulletsep}{\collectsep{\textbullet{} }}
\DeclareOption{punctsep}{\collectsep[.]{; }}
\ExecuteOptions{nosep}
\ProcessOptions

\newcommand{\nc@getcsname}[1]{\csname #1\endcsname}
\newcommand{\nc@setcsname}[2]{\expandafter\xdef\csname #1\endcsname{#2}}
\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}{}%
}
\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}{}%
}

\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}%
  \@for\nc@citethis:={\nc@citelist}\do{%
    \edef\nc@citethis{\expandafter\@firstofone\nc@citethis\@empty}%
    \ifx\nc@citelast\@empty%
      \nc@breakbefore{\nc@citethis}%
    \else%
      \@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}}{}%
      \edef\nc@citesucc{\nc@getcsname{nc@s@\nc@citelast}}%
      \edef\nc@citepred{\nc@getcsname{nc@p@\nc@citethis}}%
      \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%
    {\def\hyper@@link[##1]##2##3##4{##4}%
      \xdef\nc@citelabel{\nc@getcsname{b@\nc@citethis}}}%
    \ifx\nc@citelabel\@empty\else%
      \edef\nc@citestring{\nc@citestring\nc@citecomma\nc@citethis}%
    \fi%
    \if@filesw\immediate\write\@auxout{\string\citation{\nc@citethis}}\fi%
    \edef\nc@citelast{\nc@citethis}%
    \def\nc@citecomma{,}%
  }%
  \nc@breakafter{\nc@citelast}%
  \nc@old@citex[#1]{\nc@citestring}%
}

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

\def\bibitem{\@ifnextchar[\nc@lbibitem\nc@bibitem}
\def\nc@noitem#1{%
  \if@filesw\immediate\write\@auxout{\string\bibcite{#1}{}}\fi%
\ignorespaces}

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

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

\endinput
%%
%% End of file `collref.sty'.