summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/biblatex-chicago/cmsdocs.sty
blob: 08cb5f61db72d6cc9c0be2ae9427d12570775f1a (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
\ProvidesPackage{cmsdocs}

\RequirePackage{refcount}
\RequirePackage{listings}
\RequirePackage[svgnames]{xcolor}
\RequirePackage{hyperref}

%%% This file contains kludges and hacks to enable the bespoke
%%% cross-referencing system found in cms-notes-intro.pdf and
%%% cms-dates-intro.pdf.  It contains code adapted from several
%%% sources, especially from Ulrich Dirr's hyperendnotes.sty, found on
%%% comp.text.tex.  Please don't load it unless you really mean to, as
%%% it messes with the standard biblatex-chicago macros.

%%% These counters are for the slightly more informative endnote marks
%%% used in the notes intro.

\newcounter{Article}\setcounter{Article}{1}
\newcounter{Artwork}\setcounter{Artwork}{2}
\newcounter{Audio}\setcounter{Audio}{3}
\newcounter{Book}\setcounter{Book}{4}
\newcounter{BookInBook}\setcounter{BookInBook}{5}
\newcounter{Booklet}\setcounter{Booklet}{6}
\newcounter{Collection}\setcounter{Collection}{7}
\newcounter{CustomC}\setcounter{CustomC}{8}
\newcounter{Image}\setcounter{Image}{9}
\newcounter{InBook}\setcounter{InBook}{10}
\newcounter{InCollection}\setcounter{InCollection}{11}
\newcounter{InProceedings}\setcounter{InProceedings}{12}
\newcounter{InReference}\setcounter{InReference}{13}
\newcounter{Letter}\setcounter{Letter}{14}
\newcounter{Manual}\setcounter{Manual}{15}
\newcounter{MastersThesis}\setcounter{MastersThesis}{16}
\newcounter{Misc}\setcounter{Misc}{17}
\newcounter{Music}\setcounter{Music}{18}
\newcounter{MVBook}\setcounter{MVBook}{19}
\newcounter{MVCollection}\setcounter{MVCollection}{20}
\newcounter{MVProceedings}\setcounter{MVProceedings}{21}
\newcounter{MVReference}\setcounter{MVReference}{22}
\newcounter{Online}\setcounter{Online}{23}
\newcounter{Patent}\setcounter{Patent}{24}
\newcounter{Periodical}\setcounter{Periodical}{25}
\newcounter{Proceedings}\setcounter{Proceedings}{26}
\newcounter{Reference}\setcounter{Reference}{27}
\newcounter{Report}\setcounter{Report}{28}
\newcounter{Review}\setcounter{Review}{29}
\newcounter{SuppBook}\setcounter{SuppBook}{30}
\newcounter{SuppCollection}\setcounter{SuppCollection}{31}
\newcounter{SuppPeriodical}\setcounter{SuppPeriodical}{32}
\newcounter{TechReport}\setcounter{TechReport}{33}
\newcounter{Thesis}\setcounter{Thesis}{34}
\newcounter{Unpublished}\setcounter{Unpublished}{35}
\newcounter{Video}\setcounter{Video}{36}
\newcounter{Performance}\setcounter{Performance}{37}
\newcounter{Standard}\setcounter{Standard}{38}
\newcounter{Dataset}\setcounter{Dataset}{39}

%%% Here starts the adaptation of hyperendnotes.sty

\newif\ifenotelinks
\newcounter{Hendnote}
% Redefining portions of endnotes-package:
\let\savedhref\href
\let\savedurl\url
\def\endnotemark{%
  \@ifnextchar[\@xendnotemark{%
    \stepcounter{endnote}%
    \protected@xdef\@theenmark{\theendnote}%
    \protected@xdef\@theenvalue{\number\c@refsection\number\c@endnote}%
    \@endnotemark
  }%
}%
\def\@xendnotemark[#1]{%
  \begingroup\c@endnote#1\relax
  \unrestored@protected@xdef\@theenmark{\theendnote}%
  \unrestored@protected@xdef\@theenvalue{\number\c@refsection\number\c@endnote}%
  \endgroup
  \@endnotemark
}%
\def\endnotetext{%
  \@ifnextchar[\@xendnotenext{%
    \protected@xdef\@theenmark{\theendnote}%
    \protected@xdef\@theenvalue{\number\c@refsection\number\c@endnote}%
    \@endnotetext
  }%
}%
\def\@xendnotenext[#1]{%
  \begingroup
  \c@endnote=#1\relax
  \unrestored@protected@xdef\@theenmark{\theendnote}%
  \unrestored@protected@xdef\@theenvalue{\number\c@refsection\number\c@endnote}%
  \endgroup
  \@endnotetext
}%
\def\endnote{%
  \@ifnextchar[\@xendnote{%
    \stepcounter{endnote}%
    \protected@xdef\@theenmark{\theendnote}%
    \protected@xdef\@theenvalue{\number\c@refsection\number\c@endnote}%
    \@endnotemark\@endnotetext
  }%
}%
\def\@xendnote[#1]{%
  \begingroup
  \c@endnote=#1\relax
  \unrestored@protected@xdef\@theenmark{\theendnote}%
  \unrestored@protected@xdef\@theenvalue{\number\c@refsection\number\c@endnote}%
  \show\@theenvalue
  \endgroup
  \@endnotemark\@endnotetext
}%
\def\@endnotemark{%
  \leavevmode
  \ifhmode
  \edef\@x@sf{\the\spacefactor}\nobreak
  \fi
  \ifenotelinks
  \expandafter\@firstofone
  \else
  \expandafter\@gobble
  \fi
  {%
    \Hy@raisedlink{%
      \hyper@@anchor{Hendnotepage.\@theenvalue}{\empty}%
    }%
  }%
  \hyper@linkstart{link}{Hendnote.\@theenvalue}%
  \makeenmark
  \hyper@linkend
  \ifhmode
  \spacefactor\@x@sf
  \fi
  \relax
}%
\long\def\@endnotetext#1{%
  \if@enotesopen
  \else
  \@openenotes
  \fi
  \immediate\write\@enotes{%
    \@doanenote{\@theenmark}{\@theenvalue}%
  }%
  \begingroup
  \def\next{#1}%
  \newlinechar='40
  \immediate\write\@enotes{\meaning\next}%
  \endgroup
  \immediate\write\@enotes{%
    \@endanenote
  }%
}%
\def\theendnotes{%
  \immediate\closeout\@enotes
  \global\@enotesopenfalse
  \begingroup
  \makeatletter
  \edef\@tempa{`\string>}%
  \ifnum\catcode\@tempa=12
  \let\@ResetGT\relax
  \else
  \edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
  \@makeother\>%
  \fi
  \def\@doanenote##1##2##3>{%
    \def\@theenmark{##1}%
    \def\@theenvalue{##2}%
    \par
%    \smallskip %<-small vertical gap between endnotes
    \begingroup
    \def\href{\expandafter\savedhref}%
    \def\url{\expandafter\savedurl}%
    \@ResetGT
    \edef\@currentlabel{\csname p@endnote\endcsname\@theenmark}%
    \enoteformat
  }%
  \def\@endanenote{%
    \par\endgroup
  }%
  % Redefine, how numbers are formatted in the endnotes-section:
  \renewcommand*\@makeenmark{%
    \hbox{\normalfont\@theenmark~}%
  }%
  % header of endnotes-section
  \enoteheading
  % font-size of endnotes
  \enotesize
  \input{\jobname.ent}%
  \endgroup
}%
\def\enoteformat{%
  \renewcommand{\makeenmark}%
  {\color{DarkBlue}{\textsf{\theenmark:\,\,}}}%
  \rightskip\z@
  \leftskip\z@
  \parindent=2.3em
  \leavevmode\llap{%
    \setcounter{Hendnote}{\@theenvalue}%
    \addtocounter{Hendnote}{-1}%
    \refstepcounter{Hendnote}%
    \ifenotelinks
    \expandafter\@secondoftwo
    \else
    \expandafter\@firstoftwo
    \fi
    {\@firstofone}%
    {\hyperlink{Hendnotepage.\@theenvalue}}%
    {\makeenmark}%
  }%
}%
% stop redefining portions of endnotes-package:

% Toggle switch in order to turn on/off back-links in the
% endnote-section:
\enotelinkstrue
% \enotelinksfalse

%%% Here we substitute entry types for the usual numbers for endnote
%%% marks.

\def\cmssymbol#1{\expandafter\@cmssymbol\csname c@#1\endcsname}
 
\def\@cmssymbol#1{\ifcase#1\or Article\or Artwork\or Audio\or Book\or
  BookInBook\or Booklet\or Collection\or CustomC\or Image\or InBook\or
  InCollection\or InProceedings\or InReference\or Letter\or Manual\or
  MastersThesis\or Misc\or Music\or MVBook\or MVCollection\or
  MVProceedings\or MVReference\or Online\or Patent\or Periodical\or
  Proceedings\or Reference\or Report\or Review\or SuppBook\or
  SuppCollection\or SuppPeriodical\or TechReport\or Thesis\or
  Unpublished\or Video\or Perfor\-mance\or Standard\or
  Dataset\else\@ctrerr\fi}

\renewcommand{\theendnote}{\cmssymbol{endnote}}

%%% Now we define parameters and a command for the lstlisting
%%% environments, which print the .bib entries at the end of the .pdf.

\lstset{%
  basicstyle=\footnotesize\ttfamily,
  breaklines=true,
  breakatwhitespace=true,
  breakautoindent=false,
  breakindent=40pt,
  escapechar=*,
  keywordstyle=\color{DarkBlue},
  columns=fullflexible,
}%

\lstdefinelanguage{BibTeX}
{keywords={%
    @string%
  },
  comment=[l][\itshape]{@comment},
  sensitive=false,
}%

\newrobustcmd*{\lnbackref}[2]{%
  \hyperlink{Hendnote.#2\the\value{#1}}{\color{DarkBlue}@#1}}

\newrobustcmd*{\adlnbackref}[2]{%
  \@ifnextchar[%]
  {\adlnbackref@i{#1}{#2}}%
  {\adlnbackref@i{#1}{#2}[{#2}]}}%

\def\adlnbackref@i#1#2[#3]{%
  \hyperlink{cite.0@#3}{\color{DarkBlue}@#1}\{#2}%

%%% Here we renew some macros from chicago-notes.cbx, and add some
%%% field formats to make navigating the intro easier.

\renewbibmacro*{cite:full}{%
  \ifnumequal{\the\value{refsection}}{8}%
  {\printtext[cmsbiblink]{%
      \usedriver
      {\DeclareNameAlias{sortname}{default}\frenchspacing}
      {cite:\thefield{entrytype}}}}
  {\iffieldequalstr{entrykey}{lac:leaders}%
    {\printtext{%
        \usedriver
        {\DeclareNameAlias{sortname}{default}\frenchspacing}
        {cite:\thefield{entrytype}}}}%
    {\printtext[bibhyperref]{%
        \usedriver
        {\DeclareNameAlias{sortname}{default}\frenchspacing}
        {cite:\thefield{entrytype}}}}}}%

\ifdef{\cmshyper}%
{\renewrobustcmd*{\cmshyper}[1]{%
    \ifboolexpr{%
      (
      test {\ifbibliography}%
      or
      test {\ifnumgreater{\the\value{refsection}}{3}}%
      )
      and
      not test {\ifnumequal{\the\value{refsection}}{8}}%
    }%
    {\printtext[bibhyperref]{#1}}%
    {\printtext[cmsbiblink]{#1}}}}%
{}%

\ifdef{\cmsrelhyper}%
{\renewrobustcmd*{\cmsrelhyper}[1]{%
    \ifhyperref%
    {\ifbibliography%
      {\ifentryinbib{\strfield{clonesourcekey}}%
        {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
        {#1}}%
      {\iftoggle{cms@allshort}%
        {\IfSubStr{\thefield{savedoptions}}{skipbib}%
          {\bibhyperref[\strfield{clonesourcekey}]{#1}}%%
          {\bibhyperref[\thefield{savedentrykey}]{#1}}}%
        {\iftoggle{cms@fullnote}%
          {\ifentryseen{\thefield{clonesourcekey}}%
            {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
            {#1}}%
          {\bibhyperref[\thefield{savedentrykey}]{#1}}}}}%
    {#1}}}%
{}%

\renewbibmacro*{cite:journal}{%
  \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
  {\iffieldundef{prenote}%
    {\bibsentence\usebibmacro{cite:ibid}}%
    {\usebibmacro{cite:ibid}}}%
  {\iffieldundef{journaltitle}%
    {\usebibmacro{cite:short}}%
    {\iffieldequalstr{authortype}{anon}%
      {\bibleftbracket\printnames{labelname}%
        \bibrightbracket\newcunit}%
      {\iffieldequalstr{authortype}{anon?}%
        {\bibleftbracket\printnames{labelname}?%
          \bibrightbracket\newcunit}%
        {\printnames{labelname}%
          \isdot\newcunit}}%
      \iftoggle{cms@allshort}%
      {\printtext[cmsbiblink]{%
          \printfield[journaltitle]{journaltitle}}}%
      {\printtext[cmsbiblink]{%
          \printfield[journaltitle]{journaltitle}}}%
      \iffieldundef{volume}%
      {\iffieldundef{number}%
        {\iffieldundef{issue}
          {\newcunit%
            \usebibmacro{number+or+month}}%
          {\newcunit%
            \printfield{issue}%
            \setunit{\addspace}%
            \usebibmacro{cmsyear}}}%
        {\newcunit%
          \printfield[journum]{number}}}%
      {\toggletrue{cms@fullnote}%
        \togglefalse{cms@shortnote}%
        \setunit{\addspace}%
        \printfield[jourvol]{volume}%
        \ifthenelse{\iffieldundef{pagination}\AND%
          \iffieldundef{bookpagination}}%
        {\setunit{\postvolpunct}}%
        {\setunit{\addcolon\addspace}}}}}}

\DeclareFieldFormat{cmsbiblink}{%
  \hyperlink{\getrefbykeydefault{\abx@field@entrykey}{anchor}{}}{#1}}

\def\cmsdocref@entry{%
  \iffieldundef{clonesourcekey}%
  {\printfield{entrykey}}%
  {\printfield{clonesourcekey}}}

\def\cmsdoc@entrykey{%
  \iffieldundef{clonesourcekey}%
  {\abx@field@entrykey}%
  {\abx@field@clonesourcekey}}

\newcommand*{\cmslink}[1]{%
  \hyperlink{\getrefbykeydefault{#1}{anchor}{}}%
  {\texttt{#1}}}

\DeclareFieldFormat{annotation}{\par\nobreak \vskip \bibitemsep%
  \hyperlink{\getrefbykeydefault{\cmsdoc@entrykey}{anchor}{}}%
  {\small{\textbf{[\cmsdocref@entry]\addspace}}}\small#1}

%%% These commands provide the hyperlinks to the external docs in
%%% biblatex-chicago.pdf.

\newrobustcmd*{\cmssecref}[2][]{\marginpar{\href{\@baseurl%
      \getrefbykeydefault{#2}{anchor}{}}{\small §\,\getrefnumber{#2}}%
      \ifblank{#1}{}{\scriptsize,\, s.v.\\[1pt]\enquote{#1}}}}
\newrobustcmd*{\cmspagref}[1]{\marginpar{\href{\@baseurl%
      page.\getpagerefnumber{#1}}{p.~\getpagerefnumber{#1}}}}
\newrobustcmd*{\cmstabref}[2][]{\marginpar{\href{\@baseurl%
      \getrefbykeydefault{#2}{anchor}{}}%
    {\footnotesize Table\,\getrefnumber{#2}}%
      \ifblank{#1}{}{\scriptsize,\, s.v.\\[1pt]\enquote{#1}}}}