publ-ini.mkiv /size: 70 Kb    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=publ-ini,
3%D        version=2013.05.12,
4%D          title=\CONTEXT\ Publication Support,
5%D       subtitle=Initialization,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14% TODO: s! vs v! for default and neutral key/values
15% todo: too many refs in list
16
17% TODO A.-B. Foo (dash as connector, see JMH)
18
19% todo: no need for all these %'s
20
21% todo: tagging
22% todo: we cannot use 'default' as this wipes metadata names (maybe no longer do that)
23% todo: \v!cite => \s!cite
24% todo: interface with (ml)bibtex (export -> call -> import)
25% todo: check if 'all' etc are ok ... either use list or use other criterium
26% todo: \the\everysetupbtxciteplacement probably too often
27
28% \definecolor[btx:field]   [darkred]
29% \definecolor[btx:crossref][darkblue]
30% \definecolor[btx:key]     [darkgreen]
31% \definecolor[btx:todo]    [darkyellow]
32
33%D We operate on several axis:
34%D
35%D \startitemize[packed]
36%D \startitem we can have several databases (or combinations) \stopitem
37%D \startitem we can add entries to them if needed (coded in tex) \stopitem
38%D \startitem we can have several lists each using one of the databases \stopitem
39%D \startitem we can render each list or citation independently \stopitem
40%D \stopitemize
41%D
42%D We assume that the rendering of a list entry is consistent in a document,
43%D although one can redefine properties if needed. Adding more granularity would
44%D complicate the user interface beyond comprehension.
45
46\writestatus{loading}{ConTeXt Publication Support / Initialization}
47
48\registerctxluafile{publ-dat}{}
49\registerctxluafile{publ-ini}{}
50\registerctxluafile{publ-sor}{}
51\registerctxluafile{publ-aut}{}
52\registerctxluafile{publ-usr}{}
53\registerctxluafile{publ-oth}{} % this could become an option
54\registerctxluafile{publ-fnd}{} % new method (for the moment only local)
55\registerctxluafile{publ-jrn}{}
56\registerctxluafile{publ-reg}{}
57
58\unprotect
59
60\startcontextdefinitioncode
61
62%D These are currently not interfaced.
63
64\definesystemconstant    {btx}
65
66\definesystemconstant    {btxset}
67\definesystemconstant    {btxref}
68\definesystemconstant    {btxint}
69\definesystemconstant    {btxltx}
70\definesystemconstant    {btxrtx}
71\definesystemconstant    {btxatx}
72\definesystemconstant    {btxbtx}
73\definesystemconstant    {btxspc}
74\definesystemconstant    {btxlst}
75\definesystemconstant    {btxcom}
76
77\defineinterfacevariable {btxcite}      {btxcite}
78\defineinterfacevariable {btxlist}      {btxlist}
79\defineinterfacevariable {btxrendering} {btxrendering}
80
81\definelabelclass[btxlabel][2]
82
83\clf_definelabels{btxlabel}{btx}\s!false\relax
84
85% It is not that trivial to come up with a proper organization of setup
86% and control commands for publications. This is because we have complex
87% inline as well as extensive list rendering. The rules are partially
88% driven by somewhat archaic bibtex specifications and evolving journal
89% (or field) specific demands. The logic in the standards is often so
90% complex that it looks like manual rendering is assumed. But, we want to
91% automate the process as much as possible.
92%
93% Another complication is that in manuals we want to demonstrate different
94% properties of the implementation and therefore we need a way to handle
95% independent standards, databases, etc. This has resulted in the following
96% organization:
97%
98% - general setup (rather minimal)
99% - list setup (rendering)
100% - cite setup
101% - dataset setup
102%
103% The rendering is mostly driven by setups. In there we can call for fields
104% in the database but also for virtual fields or combinations.
105
106% The main rendering style (standard driven).
107
108%D We assume that a specification is global or used grouped. It doesn't make much sense
109%D to split between cite and list here as it only complicates matters (timing) and is
110%D not clear either.
111
112\let\currentbtxspecification        \empty
113\let\currentbtxspecificationfallback\empty
114
115\installmacrostack\currentbtxspecification
116\installmacrostack\currentbtxspecificationfallback
117
118\unexpanded\def\startbtxrenderingdefinitions[#1]%
119  {\unprotect
120   \push_macro_currentbtxspecification
121   \edef\currentbtxspecification{#1}}
122
123\unexpanded\def\stopbtxrenderingdefinitions
124  {\pop_macro_currentbtxspecification
125   \protect}
126
127\unexpanded\def\loadfoundpublicationfile#1#2% name foundname / not a user command
128  {\input{#2}}
129
130\unexpanded\def\loadbtxdefinitionfile [#1]{\clf_btxloaddefinitionfile {#1}}
131\unexpanded\def\loadbtxreplacementfile[#1]{\clf_btxloadreplacementfile{#1}}
132
133\unexpanded\def\publ_specification_push#1%
134  {\push_macro_currentbtxspecification
135   \push_macro_currentbtxspecificationfallback
136   \edef\currentbtxspecification{#1}%
137   \edef\currentbtxspecificationfallback{\namedbtxparameter\currentbtxspecification\c!default}%
138   \ifx\currentbtxspecificationfallback\currentbtxspecification
139     \let\currentbtxspecificationfallback\empty
140   \fi
141   \clf_btxsetspecification{\currentbtxspecification}}
142
143\unexpanded\def\publ_specification_pop
144  {\pop_macro_currentbtxspecificationfallback
145   \pop_macro_currentbtxspecification
146   \clf_btxsetspecification{\currentbtxspecification}}
147
148\unexpanded\def\publ_specification_set#1% beware: is global
149  {\edef\currentbtxspecification{#1}%
150   \edef\currentbtxspecificationfallback{\namedbtxparameter\currentbtxspecification\c!default}%
151   \ifx\currentbtxspecificationfallback\currentbtxspecification
152     \let\currentbtxspecificationfallback\empty
153   \fi
154  % has to be done explicitly: \loadbtxdefinitionfile[\currentbtxspecification]%
155   \ifx\currentbtxspecification\empty
156     % we set default at the end
157   \else
158     \clf_btxsetspecification{\currentbtxspecification}%
159   \fi}% todo: ,true == also load
160
161\installcorenamespace {btx}
162
163\installswitchcommandhandler \??btx {btx} \??btx
164
165% because we have lots of setups we provide a checker for sloppy users
166
167\unexpanded\def\btx_check_chain#1#2#3%
168  {\doifelsesomething{#3}
169     {\writestatus{btx #1}{defining\space"#2"\space as\space descendant\space of\space"#3"}% we're in definition regime (no space)
170      \definebtx[#2][#3]}
171     {\writestatus{btx #1}{defining\space"#2"}%
172      \definebtx[#2]}}
173
174% \unexpanded\def\btxcheckdefine#1#2{\doifelsecommandhandler\??btx{#1}\donothing{\btx_check_chain{define}{#1}{#2}}}
175% \unexpanded\def\btxchecksetup #1#2{\doifelsecommandhandler\??btx{#1}\donothing{\btx_check_chain {setup}{#1}{#2}}}
176
177\unexpanded\def\btxcheckdefine#1{\doifelsecommandhandler\??btx{#1}\gobbleoneargument{\btx_check_chain{define}{#1}}} % {#2}
178\unexpanded\def\btxchecksetup #1{\doifelsecommandhandler\??btx{#1}\gobbleoneargument{\btx_check_chain {setup}{#1}}} % {#2}
179
180% for the moment experimental:
181
182\unexpanded\def\btxenableautodefine
183  {\prependtoks
184     \clf_checkinterfacechain{\currentbtx}{btxcheckdefine}%
185   \to \everydefinebtx
186   \prependtoks
187     \ifnum\btxsetupmode=\doingrootsetupnamed
188       \clf_checkinterfacechain{\currentbtx}{btxchecksetup}%
189     \fi
190   \to \everysetupbtx
191   \let\btxenableautodefine\relax}
192
193\appendtoks
194    \ifnum\btxsetupmode=\doingrootsetuproot
195        \publ_specification_set{\btxparameter\c!specification}%
196    \else\ifnum\btxsetupmode=\doingrootsetupnamed
197        \doifelsecommandhandler\??btx\currentbtx
198          {\publ_specification_set{\btxparameter\c!specification}}%
199          {}% maybe a warning
200    \fi\fi
201\to \everysetupbtx
202
203\appendtoks
204    \ifnum\btxsetupmode=\doingrootsetuproot
205        \edef\currentbtxdataset{\clf_btxsetdataset{\btxparameter\c!dataset}{\currentbtxdataset}}%
206    \fi
207\to \everysetupbtx
208
209\appendtoks
210    \publ_specification_set{\btxparameter\c!specification}%
211\to \everyjob
212
213\unexpanded\def\startusingbtxspecification[#1]%
214  {\publ_specification_push{#1}}
215
216\let\stopusingbtxspecification\publ_specification_pop
217
218% \setupbtxlist[alternative=paragraph,width=auto,distance=\emwidth]
219% \setupbtxlist[alternative=paragraph,width=auto,distance=\emwidth,margin=2em] % useless
220% \setupbtxlist[alternative=paragraph,width=fit,distance=\emwidth]
221% \setupbtxlist[alternative=paragraph,width=fit,distance=\emwidth,margin=2em]
222
223% here starts the bib stuff
224
225\installcorenamespace {btxdataset}
226\installcorenamespace {btxrendering}
227\installcorenamespace {btxregister}
228\installcorenamespace {btxcommand}
229\installcorenamespace {btxrenderingdefinition}
230
231\installcommandhandler \??btxdataset   {btxdataset}   \??btxdataset
232\installcommandhandler \??btxregister  {btxregister}  \??btxregister
233\installcommandhandler \??btxrendering {btxrendering} \??btxrendering
234
235\unexpanded\def\setbtxparameterset#1#2%
236  {\edef\currentbtx
237     {\ifcsname\??btx\currentbtxspecification:#1:#2:\s!parent\endcsname
238        \currentbtxspecification:%
239      \else\ifx\currentbtxspecificationfallback\empty
240      \else\ifcsname\??btx\currentbtxspecificationfallback:#1:#2:\s!parent\endcsname
241        \currentbtxspecificationfallback:%
242      \fi\fi\fi#1:#2}}
243
244\unexpanded\def\setbtxparametersetroot#1%
245  {\edef\currentbtx
246     {\ifcsname\??btx\currentbtxspecification:#1:\s!parent\endcsname
247        \currentbtxspecification:#1%
248      \else\ifx\currentbtxspecificationfallback\empty
249      \else\ifcsname\??btx\currentbtxspecificationfallback:#1:\s!parent\endcsname
250        \currentbtxspecificationfallback:#1%
251      \fi\fi\fi}}
252
253\unexpanded\def\setbtxrendering
254  {\edef\currentbtxrendering
255     {\ifcsname\??btx\currentbtxspecification:\s!parent\endcsname
256        \currentbtxspecification
257      \else\ifx\currentbtxspecificationfallback\empty
258      \else\ifcsname\??btx\currentbtxspecificationfallback:\s!parent\endcsname
259        \currentbtxspecificationfallback
260      \fi\fi\fi}}
261
262\unexpanded\def\setbtxlist % maybe simplify this one, always list=rendering?
263  {\edef\currentbtxlist
264     {\ifcsname\??btx\currentbtxrendering:\s!parent\endcsname
265        \currentbtxrendering
266      \else\ifcsname\??btx\currentbtxspecification:\s!parent\endcsname
267        \currentbtxspecification
268      \else\ifx\currentbtxspecificationfallback\empty
269      \else\ifcsname\??btx\currentbtxspecificationfallback:\s!parent\endcsname
270        \currentbtxspecificationfallback
271      \fi\fi\fi\fi}%
272   \edef\currentlist{\s!btx:\currentbtxlist}}
273
274\unexpanded\def\usebtxdataset
275  {\begingroup
276   \dotripleempty\publ_use_dataset}
277
278\def\publ_use_dataset[#1][#2][#3]%
279  {\getdummyparameters[\c!specification=\currentbtxspecification,#3]%
280   \ifsecondargument
281     \clf_btxusedataset
282        specification {\dummyparameter\c!specification}%
283        dataset       {#1}%
284        filename      {#2}%
285     \relax
286   \else\iffirstargument
287     \clf_btxusedataset
288        specification {\dummyparameter\c!specification}%
289        dataset       {\v!default}%
290        filename      {#1}%
291     \relax
292   \fi\fi
293   \endgroup}
294
295\definebtxdataset
296  [\v!default]
297% [\c!language=] % nothing set so use current
298
299% \usebtxdataset
300%   [default]
301%   [mybibs.bib]
302
303\let\startpublication\relax
304\let\stoppublication \relax
305
306\unexpanded\def\startpublication
307  {\dodoubleempty\publ_set_publication}
308
309\def\publ_set_publication[#1][#2]%
310  {\begingroup
311   \catcode\commentasciicode\othercatcode
312   \ifsecondargument
313     \expandafter\publ_set_publication_indeed
314   \else\iffirstargument
315     \doubleexpandafter\publ_set_publication_checked
316   \else
317     \doubleexpandafter\publ_set_publication_default
318   \fi\fi{#1}{#2}}
319
320\def\publ_set_publication_default#1#2%
321  {\publ_set_publication_indeed\v!default{#1}}
322
323\def\publ_set_publication_checked#1#2%
324  {\doifelseassignment{#1}
325     {\publ_set_publication_indeed\v!default{#1}}
326     {\publ_set_publication_indeed{#1}{}}}
327
328\def\publ_set_publication_indeed#1#2#3\stoppublication
329  {\clf_btxaddentry{#1}{#2}{\detokenize{#3}}%
330   \endgroup
331   \ignorespaces}
332
333% commands
334
335\unexpanded\def\btxcommand#1%
336  {\ifcsname\??btxcommand#1\endcsname
337     \expandafter\publ_command_yes
338   \else
339     \expandafter\publ_command_nop
340   \fi{#1}}
341
342\newtoks\t_btx_cmd
343\newbox \b_btx_cmd
344
345\t_btx_cmd{\global\setbox\b_btx_cmd\hbox{\clf_btxcmdstring}} % no \hpack, otherwise prerolling --- doesn't work
346
347\let\btxcmd\btxcommand
348
349\def\publ_command_yes#1%
350  {\csname\??btxcommand#1\endcsname}
351
352\def\publ_command_nop#1%
353  {\ifcsname#1\endcsname
354     \showmessage\m!publications{10}{#1,#1}%
355     \expandafter\glet\csname\??btxcommand#1\expandafter\endcsname\csname#1\endcsname
356   \else\ifcsname\utfupper{#1}\endcsname
357     \showmessage\m!publications{10}{#1}{\utfupper{#1}}%
358     \expandafter\glet\csname\??btxcommand#1\expandafter\endcsname\csname\utfupper{#1}\endcsname
359   \else
360     \showmessage\m!publications{11}{#1}%
361     \setugvalue{\??btxcommand#1}{\underbar{\tttf#1}}%
362   \fi\fi
363   \publ_command_yes{#1}}
364
365\unexpanded\def\definebtxcommand#1% {body} #1..#n{body}
366  {\setuvalue{\??btxcommand\csstring#1}}%
367
368% access
369
370\let\currentbtxtag    \empty
371\let\currentbtxdataset\v!default
372
373\unexpanded\def\setbtxentry[#1]% or maybe btxsetentry
374  {\edef\currentbtxtag{\clf_btxsetentry{\currentbtxdataset}{#1}}}
375
376% \let\btxsetdataset\setbtxdataset
377% \let\btxsetentry  \setbtxentry
378
379% todo: no need for the currents as we can keep them at the lua end so we will have
380%
381% \btxfield         : current
382% \btxspecificfield : dataset,tag,key
383
384\def\btxfield      #1{\clf_btxfield      {\currentbtxdataset}{\currentbtxtag}{#1}}
385\def\btxdetail     #1{\clf_btxdetail     {\currentbtxdataset}{\currentbtxtag}{#1}}
386\def\btxflush      #1{\clf_btxflush      {\currentbtxdataset}{\currentbtxtag}{#1}}
387\def\btxdirect     #1{\clf_btxdirect     {\currentbtxdataset}{\currentbtxtag}{#1}}
388\def\btxfieldname  #1{\clf_btxfieldname  {\currentbtxdataset}{\currentbtxtag}{#1}}
389\def\btxfieldtype  #1{\clf_btxfieldtype  {\currentbtxdataset}{\currentbtxtag}{#1}}
390\def\btxfoundname  #1{\clf_btxfoundname  {\currentbtxdataset}{\currentbtxtag}{#1}}
391\def\btxfoundtype  #1{\clf_btxfoundtype  {\currentbtxdataset}{\currentbtxtag}{#1}}
392\def\btxauthorfield#1{\clf_btxauthorfield              \currentbtxauthorindex{#1}}
393\def\btxdoifelse   #1{\clf_btxdoifelse   {\currentbtxdataset}{\currentbtxtag}{#1}}
394\def\btxdoif       #1{\clf_btxdoif       {\currentbtxdataset}{\currentbtxtag}{#1}}
395\def\btxdoifnot    #1{\clf_btxdoifnot    {\currentbtxdataset}{\currentbtxtag}{#1}}
396
397\let\btxsetup\fastsetup
398
399% This fails when we check field values:
400
401\let\btxrawfield\btxfield
402
403\def\btxfield      #1{\dostarttagged\t!pubfld{#1}\clf_btxfield {\currentbtxdataset}{\currentbtxtag}{#1}\dostoptagged}
404\def\btxdetail     #1{\dostarttagged\t!pubfld{#1}\clf_btxdetail{\currentbtxdataset}{\currentbtxtag}{#1}\dostoptagged}
405\def\btxflush      #1{\dostarttagged\t!pubfld{#1}\clf_btxflush {\currentbtxdataset}{\currentbtxtag}{#1}\dostoptagged}
406\def\btxdirect     #1{\dostarttagged\t!pubfld{#1}\clf_btxdirect{\currentbtxdataset}{\currentbtxtag}{#1}\dostoptagged}
407%def\btxauthorfield#1{\dostarttagged\t!pubfld{#1}\clf_btxauthorfield         \currentbtxauthorindex{#1}\dostoptagged}
408
409%D How complex will we go? Can we assume that e.g. an apa style will not be mixed
410%D with another one? I think this assumption is okay. For manuals we might want to
411%D mix but we can work around it.
412
413%D Rendering.
414
415\unexpanded\def\btxspace                 {\removeunwantedspaces\space}
416\unexpanded\def\btxnobreakspace          {\removeunwantedspaces\nobreakspace} % these two are
417\unexpanded\def\btxnbsp                  {\removeunwantedspaces\nbsp}         % the same anyway
418\unexpanded\def\btxperiod                {\removeunwantedspaces.\space}
419\unexpanded\def\btxcomma                 {\removeunwantedspaces,\space}
420\unexpanded\def\btxserialcomma           {\removeunwantedspaces,\space} % (aka Oxford comma) redefine to disable
421\unexpanded\def\btxellipsis              {\removeunwantedspaces\nobreakspace\textellipsis\space}
422\unexpanded\def\btxcommabreak            {\removeunwantedspaces,\hskip\zeropoint plus .5\emwidth\relax}
423\unexpanded\def\btxcolon                 {\removeunwantedspaces:\space}
424\unexpanded\def\btxsemicolon             {\removeunwantedspaces;\space}
425\unexpanded\def\btxhyphen                {\removeunwantedspaces-}
426\unexpanded\def\btxlparent               {\removeunwantedspaces\space(} % obsolete
427\unexpanded\def\btxrparent               {\removeunwantedspaces)\space} % obsolete
428\unexpanded\def\btxleftparenthesis       {\removeunwantedspaces\space(}
429\unexpanded\def\btxrightparenthesis      {\removeunwantedspaces)\space}
430\unexpanded\def\btxrightparenthesisperiod{\removeunwantedspaces).\space}
431\unexpanded\def\btxrightparenthesiscomma {\removeunwantedspaces),\space}
432\unexpanded\def\btxleftbracket           {\removeunwantedspaces\space[}
433\unexpanded\def\btxrightbracket          {\removeunwantedspaces]\space}
434\unexpanded\def\btxrightbracketperiod    {\removeunwantedspaces].\space}
435\unexpanded\def\btxrightbracketcomma     {\removeunwantedspaces],\space}
436
437%D Variables:
438
439\let\currentbtxbacklink     \empty    \unexpanded\def\btxsetbacklink     {\def\currentbtxbacklink}
440\let\currentbtxcategory     \empty    \unexpanded\def\btxsetcategory     {\def\currentbtxcategory}
441\let\currentbtxcombis       \empty    \unexpanded\def\btxsetcombis       {\def\currentbtxcombis}
442\let\currentbtxdataset      \empty    \unexpanded\def\btxsetdataset      {\def\currentbtxdataset}
443\let\currentbtxfirst        \empty    \unexpanded\def\btxsetfirst        {\def\currentbtxfirst}
444\let\currentbtxsecond       \empty    \unexpanded\def\btxsetsecond       {\def\currentbtxsecond}
445\let\currentbtxsuffix       \empty    \unexpanded\def\btxsetsuffix       {\def\currentbtxsuffix}
446\let\currentbtxinternal     \empty    \unexpanded\def\btxsetinternal     {\def\currentbtxinternal}
447\let\currentbtxlefttext     \empty    \unexpanded\def\btxsetlefttext     {\def\currentbtxlefttext}
448\let\currentbtxrighttext    \empty    \unexpanded\def\btxsetrighttext    {\def\currentbtxrighttext}
449\let\currentbtxbefore       \empty    \unexpanded\def\btxsetbefore       {\def\currentbtxbefore}
450\let\currentbtxafter        \empty    \unexpanded\def\btxsetafter        {\def\currentbtxafter}
451\let\currentbtxlanguage     \empty    \unexpanded\def\btxsetlanguage     {\def\currentbtxlanguage}
452\let\currentbtxtag          \empty    \unexpanded\def\btxsettag          {\def\currentbtxtag}
453\let\currentbtxnumber       \empty    \unexpanded\def\btxsetnumber       {\def\currentbtxnumber}
454\let\currentbtxfirstinternal\empty    \unexpanded\def\btxsetfirstinternal{\def\currentbtxfirstinternal}
455\let\currentbtxlastinternal \empty    \unexpanded\def\btxsetlastinternal {\def\currentbtxlastinternal}
456
457\let\currentbtxauthorvariant\v!normal \unexpanded\def\btxsetauthorvariant{\def\currentbtxauthorvariant}
458\let\currentbtxfirstnames   \empty    \unexpanded\def\btxsetfirstnames   {\let\currentbtxfirstnames\currentbtxfirstnames_indeed}
459\let\currentbtxinitials     \empty    \unexpanded\def\btxsetinitials     {\let\currentbtxinitials  \currentbtxinitials_indeed  }
460\let\currentbtxjuniors      \empty    \unexpanded\def\btxsetjuniors      {\let\currentbtxjuniors   \currentbtxjuniors_indeed   }
461\let\currentbtxsurnames     \empty    \unexpanded\def\btxsetsurnames     {\let\currentbtxsurnames  \currentbtxsurnames_indeed  }
462\let\currentbtxvons         \empty    \unexpanded\def\btxsetvons         {\let\currentbtxvons      \currentbtxvons_indeed      }
463
464\newconstant\currentbtxoverflow       \unexpanded\def\btxsetoverflow   #1{\currentbtxoverflow   #1\relax}
465\newconstant\currentbtxconcat         \unexpanded\def\btxsetconcat     #1{\currentbtxconcat     #1\relax}
466\newconstant\currentbtxcount          \unexpanded\def\btxsetcount      #1{\currentbtxcount      #1\relax}
467\newconstant\currentbtxauthorindex    %unexpanded\def\btxsetauthorindex#1{\currentbtxauthorindex#1\relax} % passed directly
468\newconstant\currentbtxauthorcount    %unexpanded\def\btxsetauthorcount#1{\currentbtxauthorcount#1\relax} % passed directly
469\newconstant\currentbtxauthorstate    \unexpanded\def\btxsetauthorstate#1{\currentbtxauthorstate#1\relax}
470
471\unexpanded\def\currentbtxfirstnames_indeed{\clf_btxcurrentfirstnames\numexpr\currentbtxauthorindex\relax}
472\unexpanded\def\currentbtxinitials_indeed  {\clf_btxcurrentinitials  \numexpr\currentbtxauthorindex\relax}
473\unexpanded\def\currentbtxjuniors_indeed   {\clf_btxcurrentjuniors   \numexpr\currentbtxauthorindex\relax}
474\unexpanded\def\currentbtxsurnames_indeed  {\clf_btxcurrentsurnames  \numexpr\currentbtxauthorindex\relax}
475\unexpanded\def\currentbtxvons_indeed      {\clf_btxcurrentvons      \numexpr\currentbtxauthorindex\relax}
476
477\let\currentbtxfirstpage    \empty \unexpanded\def\btxsetfirstpage#1{\def\currentbtxfirstpage{\btx_page_number{#1}}}
478\let\currentbtxlastpage     \empty \unexpanded\def\btxsetlastpage #1{\def\currentbtxlastpage {\btx_page_number{#1}}}
479
480\def\currentbtxauthorvariant{normal}
481
482\unexpanded\def\btx_reset_list % not needed as we're grouped
483  {\let\currentbtxcombis   \empty
484   \let\currentbtxcategory \empty
485   \let\currentbtxinternal \empty
486   \let\currentbtxlefttext \empty
487   \let\currentbtxrighttext\empty
488   \let\currentbtxbefore   \empty
489   \let\currentbtxafter    \empty
490   \let\currentbtxbacklink \empty
491   \let\currentbtxlanguage \empty
492   \let\currentbtxsuffix   \empty
493  %\let\currentbtxdataset  \empty % will always be set
494  %\let\currentbtxtag      \empty % will always be set
495   \let\currentbtxnumber   \empty}
496
497\unexpanded\def\btx_reset_cite % check for less .. not all resets needed when we're grouped (only subcites)
498  {\let        \currentbtxfirst      \empty
499   \let        \currentbtxsecond     \empty
500   \let        \currentbtxsuffix     \empty
501   \let        \currentbtxinternal   \empty
502   \let        \currentbtxlefttext   \empty
503   \let        \currentbtxrighttext  \empty
504   \let        \currentbtxbefore     \empty
505   \let        \currentbtxafter      \empty
506   \let        \currentbtxbacklink   \empty
507   \let        \currentbtxlanguage   \empty
508  %\let        \currentbtxdataset    \empty % will always be set, beware of local reset ~
509  %\let        \currentbtxtag        \empty % will always be set, beware of local reset ~
510   \let        \currentbtxnumber     \empty
511   \setconstant\currentbtxoverflow   \zerocount
512   \setconstant\currentbtxconcat     \zerocount
513   \setconstant\currentbtxcount      \zerocount}
514
515\unexpanded\def\btx_reset_page % probably not needed
516  {\let        \currentbtxfirstpage    \empty
517   \let        \currentbtxlastpage     \empty
518   \let        \currentbtxfirstinternal\empty
519   \let        \currentbtxlastinternal \empty
520   \setconstant\currentbtxoverflow     \zerocount
521   \setconstant\currentbtxconcat       \zerocount
522   \setconstant\currentbtxcount        \zerocount}
523
524\unexpanded\def\btx_reset_numbering  % probably not needed
525  {\let        \currentbtxfirst \empty
526   \let        \currentbtxsecond\empty
527   \let        \currentbtxsuffix\empty
528   \setconstant\currentbtxconcat\zerocount}
529
530%D Pages:
531
532\unexpanded\def\btx_page_number#1%
533  {\def\currentlistindex{#1}%
534   \structurelistpagenumber}
535
536%D Language:
537
538\def\mainbtxlanguage{\currentmainlanguage}
539
540\unexpanded\def\btx_check_language
541  {\let\mainbtxlanguage\currentlanguage
542   \ifx\currentbtxlanguage\empty
543     \let\currentbtxlanguage\currentlanguage
544   \else
545     \btx_check_language_indeed
546   \fi}
547
548\unexpanded\def\btx_check_language_indeed
549  {\edef\currentbtxlanguage{\reallanguagetag\currentbtxlanguage}%
550   \ifx\currentbtxlanguage\empty
551     \let\currentbtxlanguage\currentlanguage
552   \else\ifx\currentbtxlanguage\currentlanguage\else
553     \setcurrentlanguage\currentmainlanguage\currentbtxlanguage
554   \fi\fi}
555
556%D Tracing
557
558\newconditional\c_btx_trace % not used yet
559
560\installtextracker
561  {btxrendering}
562  {\settrue \c_btx_trace}
563  {\setfalse\c_btx_trace}
564
565%D Rendering lists and citations.
566
567\unexpanded\def\btxtodo#1%
568  {[#1]}
569
570%D Lists:
571
572\newdimen\d_publ_number_width
573
574\ifdefined\btxblock       \else \newcount\btxblock       \fi \btxblock\plusone
575\ifdefined\btxcitecounter \else \newcount\btxcitecounter \fi % maybe pass this to lua
576
577\newtoks \everysetupbtxlistplacement % name will change
578\newtoks \everysetupbtxciteplacement % name will change
579
580\definelist % only used for selecting
581  [\s!btx]
582
583\setuplist
584  [\s!btx]
585  [\c!prefixstopper=:,
586   \c!state=\v!start,
587   \c!alternative=a,
588   \c!interaction=\v!none,
589  %\c!alternative=\v!paragraph,
590  %\c!width=\v!auto,
591  %\c!distance=\emwidth,
592   \c!before=\blank,
593   \c!after=\blank]
594
595\unexpanded\def\setupbtxlist
596  {\dodoubleempty\publ_setup_list}
597
598\unexpanded\def\publ_setup_list[#1][#2]%
599  {\ifsecondargument
600     \setuplist[\s!btx:#1][#2]%
601   \else\iffirstargument
602     \setuplist[\s!btx][#1]%
603   \fi\fi}
604
605\appendtoks
606    \ifx\currentbtxrenderingparent\empty
607        \definelist
608          [\s!btx:\currentbtxrendering]%
609          [\s!btx]%
610    \else\ifx\currentbtxrenderingparent\s!btx
611        \definelist
612          [\s!btx:\currentbtxrendering]%
613          [\s!btx]%
614    \else
615        \definelist
616          [\s!btx:\currentbtxrendering]%
617          [\s!btx:\currentbtxrenderingparent]%
618    \fi\fi
619\to \everydefinebtxrendering
620
621\newconditional\c_btx_list_texts
622
623\appendtoks
624    \doifelse{\btxrenderingparameter\c!textstate}\v!start
625      \settrue\setfalse\c_btx_list_texts
626\to \everysetupbtxlistplacement
627
628\newconditional\c_btx_list_pages
629
630\appendtoks
631    \doifelse{\btxrenderingparameter\c!pagestate}\v!start
632      \settrue\setfalse\c_btx_list_pages
633\to \everysetupbtxlistplacement
634
635\unexpanded\def\btx_entry_inject_pages % for the moment only normal
636  {\dontleavehmode
637   \begingroup
638   \setbtxlist % probably already set
639   \btx_reset_page
640   \setbtxparameterset\s!list\s!page
641   \btxparameter\c!command
642     {\usebtxstyleandcolor\c!style\c!color
643      \btxparameter\c!left
644      \clf_btxflushpages{\currentbtxdataset}{\currentbtxtag}%
645      \btxparameter\c!right}%
646   \endgroup}
647
648\unexpanded\def\btxpagesetup#1% there will be no left|right|command|style at this inner level
649  {\begingroup
650   \publ_fast_setup\plusfive\s!list\s!page
651   \endgroup
652   \btx_reset_page} % probably not needed
653
654\unexpanded\def\btxnumberingsetup#1%
655  {\begingroup
656   \dostarttagged\t!listtag\empty
657   \setbtxparameterset{\c!list:\s!numbering}\currentbtxnumbering % brrrr   \setbtxlist
658   \btxparameter\c!left
659 % \btxparameter\c!command{\publ_fast_setup\plusthree{\s!list:\s!numbering}{#1}}%
660   \publ_fast_setup\plusthree{\s!list:\s!numbering}{#1}%
661   \btxparameter\c!right
662   \dostoptagged
663   \endgroup
664   \btx_reset_numbering} % probably not needed
665
666% end of page stuff
667
668\unexpanded\def\btxflushlisttext
669  {\begingroup
670   \usebtxstyleandcolor\c!style\c!color
671   \ignorespaces
672   \publ_fast_setup\plusfour\s!list\currentbtxcategory
673   \removeunwantedspaces
674   \endgroup}
675
676\unexpanded\def\btxflushlistcombis
677  {\begingroup
678   \processcommacommand[\currentbtxcombis]\btx_entry_inject_combi % maybe in lua
679   \endgroup}
680
681\def\btx_entry_inject_list_text
682  {\publ_fast_setup\plusfour\s!list\s!text}
683
684\ifdefined\dotagpublication \else \let\dotagpublication \gobbletwoarguments \fi
685
686\unexpanded\def\btx_entry_inject
687  {\begingroup
688   \dostarttagged\t!publication\empty
689   \dotagpublication\currentbtxdataset\currentbtxtag
690   \redoconvertfont % see (**) in strc-lst, this will become an configuration option
691   \edef\currentbtxcategory{\btxrawfield{category}}%
692   \ignorespaces
693   \ifconditional\c_btx_list_texts
694     \dostarttagged\t!listtext\s!left
695     \currentbtxbefore
696     \dostoptagged
697   \fi
698  %\dostarttagged\t!listcontent\empty
699   \btx_entry_inject_list_text
700  %\dostoptagged
701   \ifconditional\c_btx_list_pages
702     \dostarttagged\t!listpage\empty
703     \btx_entry_inject_pages
704     \dostoptagged
705   \fi
706   \ifconditional\c_btx_list_texts
707     \dostarttagged\t!listtext\s!right
708     \currentbtxafter
709     \dostoptagged
710   \fi
711   \dostoptagged
712   \endgroup}
713
714\unexpanded\def\btxshowentryinline
715  {\dodoubleempty\btx_entry_show_inline}
716
717\unexpanded\def\btx_entry_show_inline[#1][#2]%
718  {\ifsecondargument
719     \ctxcommand{showbtxentry("#1","#2")}
720   \else\iffirstargument
721     \ctxcommand{showbtxentry("\currentbtxdataset","#1")}
722   \else
723     \ctxcommand{showbtxentry("\currentbtxdataset","\currentbtxtag")}
724   \fi\fi}
725
726\unexpanded\def\btxstartcombientry
727  {\begingroup}
728
729\unexpanded\def\btxstopcombientry
730  {\endgroup}
731
732\unexpanded\def\btxhandlecombientry
733  {\btx_reference_indeed}
734
735\def\btx_entry_inject_combi#1%
736  {\begingroup
737   \def\currentbtxtag{#1}%
738   \ignorespaces
739   \publ_fast_setup\plusfour\s!list\currentbtxcategory
740   \removeunwantedspaces
741   \endgroup}
742
743% uses reference when set
744
745% \def\btx_entry_inject_combi#1%
746%   {\begingroup
747%    \def\currentbtxtag{#1}%
748%    \ignorespaces
749%    \btxdoifelsecombiinlist\currentbtxdataset\currentbtxtag
750%      {\clf_btxflushlistcombi{\currentbtxdataset}{\currentbtxtag}}
751%      {\publ_fast_setup\plusfour\s!list\currentbtxcategory}%
752%    \removeunwantedspaces
753%    \endgroup}
754
755\unexpanded\def\placebtxrendering   {\dodoubleempty\publ_place_list_standard}
756\unexpanded\def\completebtxrendering{\dodoubleempty\publ_place_list_complete}
757\unexpanded\def\flushbtxrendering   {\dodoubleempty\publ_place_list_special }
758
759\let\completelistofpublications\completebtxrendering % for old times sake
760\let\placelistofpublications   \placebtxrendering    % for old times sake
761
762\newtoks\everybtxlistrendering
763
764\appendtoks
765    \setbtxlist
766    %
767    \edef\currentbtxcriterium{\btxrenderingparameter\c!criterium}% \v!cite will become \s!cite
768    \ifx\currentbtxcriterium\empty
769        \let\currentbtxcriterium\v!previous
770    \else\ifx\currentbtxcriterium\v!cite
771        \let\currentbtxcriterium\v!here
772    \fi\fi
773    %
774    \iflocation
775        \letinteractionparameter\c!style\empty
776%         \letinteractionparameter\c!color\empty
777%         \letinteractionparameter\c!contrastcolor\empty
778    \fi
779\to \everybtxlistrendering
780
781\def\nofbtxlistentries  {0}
782\def\currentbtxlistentry{0}
783\def\currentbtxlistindex{0} % only for internal use (points back to big list)
784
785\newconditional\c_publ_prefixed
786
787\unexpanded\def\btxsetnoflistentries  #1{\edef\nofbtxlistentries  {#1}}
788\unexpanded\def\btxsetcurrentlistentry#1{\edef\currentbtxlistentry{#1}}
789\unexpanded\def\btxsetcurrentlistindex#1{\edef\currentbtxlistindex{#1}}
790
791\unexpanded\def\btxdoifelsesameaspreviouschecked#1#2% #1 == always | doublesided
792  {\clf_btxdoifelsesameasprevious
793     {\currentbtxdataset}%
794     \currentbtxlistentry%
795     {#2}%
796     \c_btx_list_reference
797     {#1}}
798
799\unexpanded\def\btxdoifelsesameasprevious
800  {\btxdoifelsesameaspreviouschecked\v!doublesided}
801
802\unexpanded\def\btxdoifelsecombiinlist#1#2%
803  {\clf_btxdoifelsecombiinlist{#1}{#2}}
804
805\unexpanded\def\btxdoifelsecitedone#1#2%
806  {\clf_btxdoifelsecitedone{#1}{#2}}
807
808\let\btxdoifsameaspreviouscheckedelse\btxdoifelsesameaspreviouschecked
809\let\btxdoifsameaspreviouselse       \btxdoifelsesameasprevious
810\let\btxdoifcombiinlistelse          \btxdoifelsecombiinlist
811\let\btxdoifcitedoneelse             \btxdoifelsecitedone
812
813\def\publ_place_list_indeed#1#2[#3][#4]%
814  {\begingroup
815   \ifsecondargument
816     % [rendering] [settings]
817     \edef\currentbtxrendering{#3}%
818     \setupcurrentbtxrendering[#4]%
819     \edef\p_specification{\btxrenderingparameter\c!specification}%
820     \ifx\p_specification\empty\else
821       \let\currentbtxspecification\p_specification
822     \fi
823   \else\iffirstargument
824     \doifelseassignment{#3}
825       {% [settings]
826        \let\currentbtxrendering\currentbtxspecification
827        \setupcurrentbtxrendering[#3]%
828        \edef\p_specification{\btxrenderingparameter\c!specification}%
829        \ifx\p_specification\empty\else
830           \let\currentbtxspecification\p_specification
831           \let\currentbtxrendering\currentbtxspecification % tricky
832        \fi}
833       {\edef\currentbtxrendering{#3}%
834        \edef\p_specification{\btxrenderingparameter\c!specification}%
835        \ifx\p_specification\empty\else
836          \let\currentbtxspecification\p_specification
837        \fi}%
838   \else
839     \let\currentbtxrendering\currentbtxspecification
840   \fi\fi
841   \setbtxparameterset\currentbtxspecification\s!list
842   \the\everybtxlistrendering
843   \ifconditional#1\relax
844     \edef\currentbtxrenderingtitle{\btxrenderingparameter\c!title}%
845     \ifx\currentbtxrenderingtitle\empty
846       \normalexpanded{\startnamedsection[\v!chapter][\c!reference=\currentbtxrendering,\c!title={\headtext{\currentbtxrendering}}]}%
847     \else
848       \normalexpanded{\startnamedsection[\v!chapter][\c!reference=\currentbtxrendering,\c!title={\currentbtxrenderingtitle}]}%
849     \fi
850   \fi
851   \ifx\currentbtxrendering\empty
852     \setbtxrendering % hm
853   \fi
854   \edef\currentbtxdataset{\btxrenderingparameter\c!dataset}%
855   \uselanguageparameter\btxdatasetparameter % new
856   \setbtxlist
857   \the\everystructurelist
858   \the\everysetupbtxlistplacement
859   % why not pass this with collect .. todo
860   % here we just collect items
861   \clf_btxcollectlistentries
862       names     {\s!btx}%
863       criterium {\currentbtxcriterium}%
864       reference {\btxrenderingparameter\c!reference}%
865       method    {\btxrenderingparameter\c!method}%
866       dataset   {\currentbtxdataset}%
867       keyword   {\btxrenderingparameter\c!keyword}%
868       sorttype  {\btxrenderingparameter\c!sorttype}%
869       repeated  {\btxrenderingparameter\c!repeat}%
870       ignored   {\btxrenderingparameter\c!ignore}%
871       group     {\btxrenderingparameter\c!group}%
872       filter    {\btxrenderingparameter\c!filter}%
873   \relax
874   \ifnum\nofbtxlistentries>\zerocount
875     \forgetall
876     \btxrenderingparameter\c!before
877     \ifconditional#2\relax
878       \edef\p_command{\btxrenderingparameter\c!command}%
879       \ifx\p_command\empty
880         \edef\p_setups{\btxrenderingparameter\c!setups}%
881         \ifx\p_setups\empty
882         \else
883           \directsetup{\p_setups}%
884         \fi
885       \else
886         \expandafter\p_command\expandafter{\number\nofbtxlistentries}\relax
887       \fi
888     \else
889       \dostarttagged\t!publications\currentbtxrendering
890       \dostarttagged\t!list{btx}%
891       \startpacked[\v!blank]%
892       % sorting and so
893       \clf_btxpreparelistentries{\currentbtxdataset}% could be put in collect
894       % next we analyze the width
895       \ifx\currentbtxnumbering\empty \else
896         \edef\p_width{\listparameter\c!width}%
897         \ifx\p_width\v!auto
898           \setbox\scratchbox\vbox \bgroup
899             \settrialtypesetting
900             \clf_btxfetchlistentries{\currentbtxdataset}%
901           \egroup
902           \d_publ_number_width\wd\scratchbox
903           \letlistparameter\c!width\d_publ_number_width
904         \fi
905       \fi
906       \doifelse{\listparameter\c!prefix}\v!yes\settrue\setfalse\c_publ_prefixed
907       % this actually typesets them, we loop here as otherwise the whole
908       % bunch gets flushed at once
909       \dorecurse\nofbtxlistentries
910          {\let\currentbtxlistentry\recurselevel
911           \clf_btxflushlistentry{\currentbtxdataset}\currentbtxlistentry\relax}%
912       \stoppacked
913       \dostoptagged
914       \dostoptagged
915     \fi
916     \btxrenderingparameter\c!after
917   \fi
918   \ifconditional#1\relax
919     \stopnamedsection
920   \fi
921   \global\advance\btxblock\plusone
922   \endgroup}
923
924\def\publ_place_list_standard{\publ_place_list_indeed\conditionalfalse\conditionalfalse}
925\def\publ_place_list_complete{\publ_place_list_indeed\conditionaltrue \conditionalfalse}
926\def\publ_place_list_special {\publ_place_list_indeed\conditionalfalse\conditionaltrue}
927
928%D This is somewhat special (for Alan of course):
929%D
930%D \starttyping
931%D % #1 is number of entries
932%D
933%D \starttexdefinition mutable protected btx:for:alan:wrapper #1
934%D     \bTABLE
935%D         % we can have a command or setups
936%D         \flushbtxentries[command=\texdefinition{btx:for:alan:content}]
937%D     \eTABLE
938%D \stoptexdefinition
939%D
940%D % #1 is tag
941%D
942%D \starttexdefinition mutable protected btx:for:alan:content #1
943%D     \bTR
944%D         \bTD
945%D             \btxsettag{#1}
946%D             \btxfield{name}
947%D         \eTD
948%D     \eTR
949%D \stoptexdefinition
950%D
951%D % we can have a command or setups
952%D
953%D \flushbtxrendering [method=dataset,command=\texdefinition{btx:for:alan:wrapper}]
954%D \stoptyping
955%D
956%D Because we want to be ungrouped we use a special loop construct.
957
958\unexpanded\def\btxsetlisttag#1%
959  {\clf_btxflushlisttag{\currentbtxdataset}#1\relax}
960
961\newcount\c_btx_list_index
962\let\m_btx_list_action\empty
963
964\def\publ_flush_list_step_command
965  {\btxsetlisttag{\c_btx_list_index}
966   \expandafter\m_btx_list_action\expandafter{\currentbtxtag}%
967   \ifnum\c_btx_list_index<\nofbtxlistentries
968     \advance\c_btx_list_index\plusone
969     \expandafter\publ_flush_list_step_command
970   \else
971     \glet\m_btx_list_action\relax
972   \fi}
973
974\def\publ_flush_list_step_setup
975  {\btxsetlisttag{\c_btx_list_index}
976   \directsetup{\m_btx_list_action}%
977   \ifnum\c_btx_list_index<\nofbtxlistentries
978     \advance\c_btx_list_index\plusone
979     \expandafter\publ_flush_list_step_setup
980   \else
981     \glet\m_btx_list_action\relax
982   \fi}
983
984\unexpanded\def\flushbtxentries[#1]%
985  {\begingroup
986   \getdummyparameters[\c!command=,\c!setups=,#1]%
987   \xdef\m_btx_list_action{\dummyparameter\c!command}%
988   \ifx\m_btx_list_action\empty
989     \xdef\m_btx_list_action{\dummyparameter\c!setups}%
990     \ifx\m_btx_list_action\empty
991       \endgroup
992       \c_btx_list_index\zerocount
993     \else
994       \endgroup
995       \c_btx_list_index\plusone
996       \doubleexpandafter\publ_flush_list_step_command
997     \fi
998   \else
999     \endgroup
1000     \c_btx_list_index\plusone
1001     \expandafter\publ_flush_list_step_command
1002   \fi}
1003
1004%D So far.
1005
1006\def\currentbtxblock{\number\btxblock}
1007
1008% called at the lua end, for determining the width
1009
1010\unexpanded\def\btxchecklistentry
1011  {\begingroup
1012   % todo, switch to font
1013   \hbox{\btx_reference_checked}%
1014   \par
1015   \endgroup}
1016
1017% called at the lua end, the real rendering
1018
1019% we could have a yes and no where o nils the btx_reference_indeed ... saves a check there
1020
1021\installstructurelistprocessor{\s!btx}
1022  {\let\currentlistentrynumber    \btx_reference_indeed
1023   \let\currentlistentrytitle     \btx_entry_indeed
1024   \let\currentlistentrypagenumber\btx_page_indeed
1025   \strc_lists_apply_renderingsetup}
1026
1027\def\btx_entry_indeed
1028  {\dostarttagged\t!listcontent\empty
1029   \btx_list_reference_inject
1030   \btx_entry_inject
1031   \dostoptagged}
1032
1033\def\btx_page_indeed
1034  {}
1035
1036\unexpanded\def\btxhandlelistentry
1037  {\strc_lists_entry_process}
1038
1039\unexpanded\def\btxstartlistentry % maybe pass i
1040  {\begingroup
1041   \global\advance\c_btx_list_reference\plusone}
1042
1043\unexpanded\def\btxstoplistentry
1044  {\iftrialtypesetting
1045     \global\advance\c_btx_list_reference\minusone
1046   \fi
1047   \endgroup}
1048
1049\newtoks\everybtxlistentry
1050
1051\unexpanded\def\btxlistsetup#1% used for the reference in the list
1052  {\the\everybtxlistentry
1053   \everybtxlistentry\emptytoks % so only once per entry to be sure
1054   \publ_fast_setup\plusfour\s!list{#1}}
1055
1056\appendtoks
1057    \btx_check_language
1058\to \everybtxlistentry
1059
1060\unexpanded\def\btx_reference_indeed
1061  {\begingroup
1062   % redundant will go away:
1063   \setbtxparameterset{\c!list:\s!numbering}\currentbtxnumbering
1064   %
1065   \ifx\currentbtxnumbering\empty
1066     % nothing
1067   \else\ifx\currentbtxnumbering\v!no
1068     % nothing
1069   \else
1070     \usebtxstyleandcolor\c!style\c!color % new, needed?
1071     \ifconditional\c_publ_prefixed\btxlistprefixednumber\fi
1072     \clf_btxlistvariant % some can go
1073       {\currentbtxdataset}%
1074       {\currentbtxblock}%
1075       {\currentbtxtag}%
1076       {\currentbtxnumbering}%
1077       {\currentbtxnumber}%
1078     \relax
1079   \fi\fi
1080   \endgroup}
1081
1082\unexpanded\def\btxlistprefixednumber % hack but alan needs it
1083  {\clf_listprefixednumber
1084     {\currentlist}%
1085     \currentbtxlistindex
1086     {%
1087        prefix        {\listparameter\c!prefix}%
1088        separatorset  {\listparameter\c!prefixseparatorset}%
1089        conversionset {\listparameter\c!prefixconversionset}%
1090        starter       {\listparameter\c!prefixstarter}%
1091        stopper       {\listparameter\c!prefixstopper}%
1092        set           {\listparameter\c!prefixset}%
1093        segments      {\listparameter\c!prefixsegments}%
1094        connector     {\listparameter\c!prefixconnector}%
1095     }%
1096   \relax}
1097
1098\unexpanded\def\btx_reference_checked
1099  {\dontleavehmode\hbox\bgroup % \hpack
1100     \btx_reference_indeed
1101   \egroup}
1102
1103\newcount\c_btx_list_reference
1104
1105\unexpanded\def\btx_list_reference_inject
1106  {\dontleavehmode\begingroup % no box
1107     \iftrialtypesetting\else
1108       \btx_list_reference_inject_now
1109     \fi
1110   % \btx_reference_indeed % else double entry in list
1111   \endgroup}
1112
1113\def\btx_list_reference_inject_now
1114  {\strc_references_direct_full_user
1115      {\ifx\currentbtxdataset\v!default\else\s!btxset=\currentbtxdataset,\fi%
1116       \s!btxref=\currentbtxtag,%
1117       \s!btxspc=\currentbtxspecification,%
1118       \s!btxlst=\number\c_btx_list_reference,% check if needed
1119      %\ifx\currentbtxcombis  \empty\else\s!btxcom={\currentbtxcombis},\fi%
1120       \ifx\currentbtxbefore  \empty\else\s!btxbtx={\currentbtxbefore},\fi%
1121       \ifx\currentbtxafter   \empty\else\s!btxatx={\currentbtxafter },\fi%
1122       \ifx\currentbtxbacklink\empty\else\s!btxint=\number\currentbtxbacklink\fi
1123      }%
1124      {\s!btx::\v!list::\number\c_btx_list_reference}%
1125      {\currentbtxnumber}}
1126
1127\newconditional\c_btx_cite_reference_injected
1128
1129\unexpanded\def\btx_cite_reference_inject
1130  {\ifconditional\c_btx_cite_reference_injected
1131   \else
1132     \dontleavehmode
1133     \iftrialtypesetting \else
1134       \ifx\currentbtxbacklink\empty
1135         % can be made empty when combining author / year
1136       \else\ifnum\currentbtxbacklink>\zerocount
1137         \btx_cite_reference_inject_indeed
1138         \settrue\c_btx_cite_reference_injected
1139       \fi\fi
1140     \fi
1141  \fi}
1142
1143\newtoks\t_btx_reference_inject
1144
1145\def\btx_cite_reference_inject_indeed
1146  {\the\t_btx_reference_inject
1147   \strc_lists_inject_direct % todo: make like \btx_list_reference_inject_now with { }
1148      [\s!btx]%
1149      [\c!type=\s!btx]% \c!location=\v!none
1150      [\ifx\currentbtxdataset\v!default\else\s!btxset=\currentbtxdataset,\fi%
1151       \s!btxref=\currentbtxtag,%
1152      %\ifx\currentbtxcombis  \empty\else\s!btxcom={\currentbtxcombis},\fi%
1153       \ifx\currentbtxbefore  \empty\else\s!btxbtx={\currentbtxbefore},\fi%
1154       \ifx\currentbtxafter   \empty\else\s!btxatx={\currentbtxafter },\fi%
1155       \ifx\currentbtxbacklink\empty\else\s!btxint=\number\currentbtxbacklink,\fi
1156       \ifx\currentbtxciteuservariables\empty\else,\currentbtxciteuservariables\fi]}
1157
1158\def\currentbtxuservariable #1{\clf_btxuservariable        {\currentbtxdataset}{#1}}
1159\def\btxdoifelseuservariable#1{\clf_btxdoifelseuservariable{\currentbtxdataset}{#1}}
1160
1161\let\btxdoifuservariableelse\btxdoifelseuservariable
1162
1163\let\btxcitereference\btx_cite_reference_inject
1164
1165\let\currentbtxnumbering       \empty
1166\let\currentbtxcitealternative \empty
1167
1168\appendtoks
1169    \edef\currentbtxnumbering{\btxrenderingparameter\c!numbering}%
1170    \ifx\currentbtxnumbering\v!yes
1171        \def\currentbtxnumbering{num}% convenient alias
1172        \letbtxrenderingparameter\c!numbering\currentbtxnumbering
1173        \letlistparameter\c!headnumber\v!always
1174    \else\ifx\currentbtxnumbering\v!no
1175        \letlistparameter\c!headnumber\v!no
1176        \let\currentbtxnumbering\empty
1177      % \letlistparameter\c!textcommand\outdented % needed? we can use titlealign
1178        \letlistparameter\c!symbol     \v!none
1179        \letlistparameter\c!aligntitle \v!yes
1180        \letlistparameter\c!numbercommand\firstofoneargument % for the moment, no doubling needed
1181    \else
1182        \letlistparameter\c!headnumber\v!always
1183    \fi\fi
1184    \let\currentlistmethod\s!btx
1185\to \everysetupbtxlistplacement
1186
1187\unexpanded\def\btxremapauthor
1188  {\dodoubleargument\btx_remap_author}
1189
1190\def\btx_remap_author[#1][#2]%
1191  {\clf_btxremapauthor{#1}{#2}}
1192
1193\unexpanded\def\btxshowauthorremapping
1194  {\clf_btxshowauthorremapping}
1195
1196\unexpanded\def\btxflushauthor
1197  {\doifelsenextoptionalcs\btx_flush_author_yes\btx_flush_author_nop}
1198
1199\unexpanded\def\btxflushsuffix
1200  {\ifx\currentbtxsuffix\empty
1201     % nothing
1202   \else
1203     \characters{\currentbtxsuffix}% todo : rendering specific converter
1204   \fi}
1205
1206\def\btx_flush_author_yes[#1]{\btx_flush_author{#1}}
1207\def\btx_flush_author_nop    {\btx_flush_author{\btxparameter\c!authorconversion}}
1208
1209\unexpanded\def\btx_flush_author#1#2%
1210  {\begingroup
1211   \edef\currentbtxfield{#2}%
1212   \setbtxparameterset\s!list\currentbtxfield
1213% \let\currentbtxlistvariant\currentbtxfield
1214   \clf_btxauthor
1215        {\currentbtxdataset}%
1216        {\currentbtxtag}%
1217        {\currentbtxfield}%
1218        {%
1219            combiner    {#1}%
1220            kind        {list}%
1221            etallimit   {\btxparameter\c!etallimit}%
1222            etaldisplay {\btxparameter\c!etaldisplay}%
1223            etaloption  {\btxparameter\c!etaloption}%
1224            symbol      {\btxparameter{\c!stopper:initials}}%
1225            connector   {\btxparameter{\c!connector:initials}}%
1226        }%
1227   \relax
1228   \endgroup}
1229
1230% yes or no: maybe just \flushauthor{...}{...}
1231
1232\unexpanded\def\btxflushauthorname         {\btx_flush_author{name}}          % #1
1233\unexpanded\def\btxflushauthornormal       {\btx_flush_author{normal}}        % #1
1234\unexpanded\def\btxflushauthornormalshort  {\btx_flush_author{normalshort}}   % #1
1235\unexpanded\def\btxflushauthorinverted     {\btx_flush_author{inverted}}      % #1
1236\unexpanded\def\btxflushauthorinvertedshort{\btx_flush_author{invertedshort}} % #1
1237
1238\let\currentbtxauthorfield\s!author
1239
1240\unexpanded\def\btxsetauthorfield#1{\edef\currentbtxauthorfield{#1}}
1241
1242\unexpanded\def\currentbtxciteauthorbyfield
1243  {\begingroup
1244   %\setbtxparameterset\s!cite\s!author
1245   % the alternatives inherit from cite:author
1246   % and APA distinguishes authoryears from authoryear ("and" vs. "&")
1247   \setbtxparameterset\s!cite\currentbtxcitealternative
1248   \clf_btxauthor
1249        {\currentbtxdataset}%
1250        {\currentbtxtag}%
1251        {\currentbtxauthorfield}%
1252        {%
1253            combiner    {\btxparameter\c!authorconversion}%
1254            kind        {cite}%
1255            etallimit   {\btxparameter\c!etallimit}%
1256            etaldisplay {\btxparameter\c!etaldisplay}%
1257            etaloption  {\btxparameter\c!etaloption}%
1258            symbol      {\btxparameter{\c!stopper:initials}}%
1259        }%
1260   \relax
1261   \endgroup}
1262
1263\unexpanded\def\currentbtxciteauthor
1264  {\let\currentbtxauthorfield\s!author
1265   \currentbtxciteauthorbyfield} % always author
1266
1267\unexpanded\def\btxstartauthor#1#2#3% a state > 0 signals that some authors can clash
1268  {\begingroup
1269   \currentbtxauthorindex#1\relax
1270   \currentbtxauthorcount#2\relax
1271   \currentbtxauthorstate#3\relax}
1272
1273\unexpanded\def\btxstopauthor
1274  {\endgroup}
1275
1276\unexpanded\def\btxciteauthorsetup#1{\fastsetup{\s!btx:\s!cite:\s!author:#1}}
1277\unexpanded\def\btxlistauthorsetup#1{\fastsetup{\s!btx:\s!list:\s!author:#1}}
1278
1279% \btxflushauthor{author}
1280% \btxflushauthor{editor}
1281%
1282% \btxflushauthor[name]{author}
1283% \btxflushauthor[normal]{author}
1284% \btxflushauthor[normalshort]{author}
1285% \btxflushauthor[inverted]{author}
1286% \btxflushauthor[invertedshort]{author}
1287
1288% \btxflushauthor{author}
1289% \btxflushauthor{editor}
1290
1291% Interaction
1292%
1293% Because we have more complex entries in lists we don't use the normal list
1294% interaction features.
1295
1296\newconditional\btxinteractive
1297\newconditional\btxinteractivenumber
1298\newconditional\btxinteractivetext
1299\newconditional\btxinteractivepage
1300
1301\let\currentbtxinteraction\empty
1302
1303\installcorenamespace{btxinteraction}
1304
1305\setvalue{\??btxinteraction\v!number}{\settrue\btxinteractivenumber}
1306\setvalue{\??btxinteraction\v!text  }{\settrue\btxinteractivetext}
1307\setvalue{\??btxinteraction\v!page  }{\settrue\btxinteractivepage}
1308\setvalue{\??btxinteraction\v!all   }{\settrue\btxinteractivenumber
1309                                      \settrue\btxinteractivetext
1310                                      \settrue\btxinteractivepage}
1311
1312% \setupbtx[interaction=page] % or text or number or all
1313% \setupbtxrendering[pagestate=start]
1314
1315\appendtoks
1316    \iflocation
1317        \edef\currentbtxinteraction{\btxparameter\c!interaction}%
1318        \ifx\currentbtxinteraction\v!stop
1319            \setfalse\btxinteractive
1320        \else
1321            \let\structurelistlocation\empty
1322            \settrue\btxinteractive
1323            \begincsname\??btxinteraction\currentbtxinteraction\endcsname
1324        \fi
1325    \else
1326        \setfalse\btxinteractive
1327    \fi
1328\to \everysetupbtxlistplacement
1329
1330\appendtoks
1331    \iflocation
1332        \edef\currentbtxinteraction{\btxparameter\c!interaction}%
1333        \ifx\currentbtxinteraction\v!stop
1334            \setfalse\btxinteractive
1335        \else
1336            \settrue\btxinteractive
1337        \fi
1338    \else
1339        \setfalse\btxinteractive
1340    \fi
1341\to \everysetupbtxciteplacement
1342
1343%D When a publication is cited, we need to signal that somehow. This is done with the
1344%D following (not user) command. We could tag without injecting a node but this way
1345%D we also store the location, which makes it possible to ask local lists.
1346
1347%D \macros{cite,nocite,citation,nocitation,usecitation}
1348%D
1349%D The inline \type {\cite} command creates a (often) short reference to a publication
1350%D and for historic reasons uses a strict test for brackets. This means, at least
1351%D in the default case that spaces are ignored in the argument scanner. The \type
1352%D {\citation} commands is more liberal but also gobbles following spaces. Both
1353%D commands insert a reference as well as a visual clue.
1354%D
1355%D The \type {no} commands all do the same (they are synonyms): they make sure that
1356%D a reference is injected but show nothing. However, they do create a node so best
1357%D attach them to some text in order to avoid spacing interferences. A slightly
1358%D less efficient alternative is \type {\cite[none][tag]}.
1359
1360% [tags]
1361% [settings|variant][tags]
1362% [base::tags]
1363% [settings|variant][base::tags]
1364
1365% these need to be sort of protected:
1366
1367% methods:
1368%
1369% hidden : mark for list, don't show in text
1370% list   : mark for list, show in text only when in list
1371% text   : not to list, show in text
1372% always : mark for list, show in text
1373
1374\let\p_publ_cite_before   \empty
1375\let\p_publ_cite_after    \empty
1376\let\p_publ_cite_lefttext \empty
1377\let\p_publ_cite_righttext\empty
1378
1379\let\currentbtxciteuservariables\empty
1380\let\currentbtxcitealternative  \empty
1381
1382\unexpanded\def\btxhybridcite % so one can alias the old
1383  {\dontleavehmode
1384   \begingroup
1385   \strictdoifelsenextoptional\publ_cite_tags_options\publ_cite_tags_indeed}
1386
1387\unexpanded\def\publ_cite_tags_options[#1]%
1388  {\strictdoifelsenextoptional{\publ_cite_tags_options_indeed{#1}}{\publ_cite_tags_indeed{#1}}}
1389
1390\unexpanded\def\publ_cite_tags_indeed#1%
1391  {\letinteractionparameter\c!style\empty
1392   \setbtxparametersetroot\s!cite % we need to get the default
1393   \edef\currentbtxcitealternative{\btxparameter\c!alternative}%
1394   \setbtxparameterset\s!cite\currentbtxcitealternative
1395   \edef\currentbtxcitetag{#1}%
1396   \the\everysetupbtxciteplacement
1397   \publ_cite_variant
1398   \endgroup}
1399
1400\unexpanded\def\publ_cite_tags_options_indeed#1%
1401  {\doifelseassignment{#1}\publ_cite_tags_settings_indeed\publ_cite_tags_variants_indeed{#1}}
1402
1403\def\publ_cite_tags_settings_indeed#1[#2]%
1404  {\letinteractionparameter\c!style\empty
1405  %\letinteractionparameter\c!color\empty
1406   \letdummyparameter\c!reference  \empty
1407   \letdummyparameter\c!alternative\empty
1408   \letdummyparameter\c!before     \empty
1409   \letdummyparameter\c!after      \empty
1410   \letdummyparameter\c!lefttext   \empty
1411   \letdummyparameter\c!righttext  \empty
1412   \getdummyparameters[#1]%
1413   \edef\p_reference{\dummyparameter\c!reference}%
1414   \ifx\p_reference\empty
1415      \edef\currentbtxcitetag{#2}%
1416   \else
1417      \let\currentbtxcitetag\p_reference
1418      \edef\currentbtxciteuservariables{#2}%
1419   \fi
1420   \edef\p_specification{\dummyparameter\c!specification}%
1421   \ifx\p_specification\empty
1422   \else
1423     \let\currentbtxspecification\p_specification
1424   \fi
1425   \edef\p_alternative{\dummyparameter\c!alternative}%
1426   \ifx\p_alternative\empty
1427     \setbtxparametersetroot\s!cite
1428     \edef\currentbtxcitealternative{\btxparameter\c!alternative}%
1429   \else
1430     \let\currentbtxcitealternative\p_alternative
1431   \fi
1432   \setbtxparameterset\s!cite\currentbtxcitealternative
1433   \setupcurrentbtx[#1]%
1434   %
1435   \edef\p_publ_cite_before   {\dummyparameter\c!before}%
1436   \edef\p_publ_cite_after    {\dummyparameter\c!after}%
1437   \edef\p_publ_cite_lefttext {\dummyparameter\c!lefttext}%
1438   \edef\p_publ_cite_righttext{\dummyparameter\c!righttext}%
1439   %
1440   \the\everysetupbtxciteplacement
1441   \publ_cite_variant
1442   \endgroup}
1443
1444\def\publ_cite_tags_variants_indeed#1[#2]%
1445  {\letinteractionparameter\c!style\empty
1446   \edef\currentbtxcitealternative{#1}%
1447   \edef\currentbtxcitetag{#2}%
1448   \setbtxparameterset\s!cite\currentbtxcitealternative
1449   \the\everysetupbtxciteplacement
1450   \publ_cite_variant
1451   \endgroup}
1452
1453\newconditional\btxcitecompress
1454
1455\let\currentbtxreference\empty
1456\let\currentbtxcitemethod\v!hidden
1457
1458\def\publ_cite_variant
1459  {\begingroup
1460   \publ_cite_handle_variant_indeed[\currentbtxcitetag]}
1461
1462\unexpanded\def\publ_cite_handle_variant#1%
1463  {\begingroup
1464   \edef\currentbtxcitealternative{#1}%
1465   \setbtxparameterset\s!cite\currentbtxcitealternative
1466   \the\everysetupbtxciteplacement
1467   \dosingleargument\publ_cite_handle_variant_indeed}
1468
1469\unexpanded\def\publ_cite_handle_variant_blob
1470  {\clf_btxhandlecite
1471     dataset          {\currentbtxdataset}%
1472     reference        {\currentbtxreference}%
1473     method           {\currentbtxcitemethod}%
1474     variant          {\currentbtxcitealternative}%
1475     sorttype         {\btxparameter\c!sorttype}%
1476     compress         {\btxparameter\c!compress}%
1477     author           {\btxparameter\c!author}%
1478     authorconversion {\c!authorconversion}%
1479     lefttext         {\p_publ_cite_lefttext}%
1480     righttext        {\p_publ_cite_righttext}%
1481     before           {\p_publ_cite_before}%
1482     after            {\p_publ_cite_after}%
1483   \relax
1484   \iftrialtypesetting\else
1485    %\clf_btxflushmarked
1486   \fi}
1487
1488\let\dobtxcitevariantblob\publ_cite_handle_variant_blob % command can use it via lua
1489
1490\def\publ_cite_handle_variant_indeed[#1]%
1491  {\letbtxparameter\c!alternative\currentbtxcitealternative
1492   \edef\currentbtxreference{#1}%
1493   \saverunningstyleandcolor
1494   \usebtxstyleandcolor\c!style\c!color
1495   \uselanguageparameter\btxdatasetparameter % new
1496   \btxparameter\c!left
1497   \btxparameter\c!command{\dobtxcitevariantblob}% {\publ_cite_handle_variant_blob}%
1498   \btxparameter\c!right
1499   \endgroup}
1500
1501\unexpanded\def\btxlistcitation
1502  {\dontleavehmode
1503   \begingroup
1504   \let\currentbtxcitemethod\v!list
1505   \dodoubleempty\publ_citation}
1506
1507\unexpanded\def\btxtextcitation
1508  {\dontleavehmode
1509   \begingroup
1510   \let\btxcitereference\relax % a bit of a hack but ok
1511   \let\currentbtxcitemethod\v!text
1512   \dodoubleempty\publ_citation}
1513
1514\unexpanded\def\btxalwayscitation
1515  {\dontleavehmode
1516   \begingroup
1517   \let\currentbtxcitemethod\v!always
1518   \dodoubleempty\publ_citation}
1519
1520\def\publ_citation[#1][#2]% could be made more efficient but not now
1521  {\ifsecondargument
1522     \publ_cite_tags_options_indeed{#1}[#2]%
1523   \else
1524     \publ_cite_tags_indeed{#1}%
1525   \fi}
1526
1527\unexpanded\def\btxhiddencitation
1528  {\dosingleempty\publ_cite_hidden}
1529
1530\unexpanded\def\publ_cite_hidden[#1]%
1531  {\iftrialtypesetting \else
1532     \begingroup
1533     \let\currentbtxcitemethod\v!hidden
1534     \edef\currentbtxreference{#1}%
1535     \clf_btxhandlenocite
1536       method    {\currentbtxcitemethod}%
1537       dataset   {\currentbtxdataset}%
1538       reference {\currentbtxreference}%
1539     \relax
1540    %\clf_btxflushmarked
1541     \endgroup
1542   \fi}
1543
1544\unexpanded\def\btxmissing#1%
1545  {\dontleavehmode{\tttf<#1>}}
1546
1547%D Compatibility:
1548
1549\let\hiddencitation\btxhiddencitation  \let\hiddencite\hiddencitation
1550\let\listcitation  \btxlistcitation    \let\listcite  \listcitation
1551\let\textcitation  \btxtextcitation    \let\textcite  \textcitation
1552\let\alwayscitation\btxalwayscitation  \let\alwayscite\alwayscitation
1553
1554\unexpanded\def\citation  {\doifelsenextoptionalcs\btxlistcitation  \btxdirectlistcite}
1555\unexpanded\def\nocitation{\doifelsenextoptionalcs\btxhiddencitation\btxdirecthiddencite}
1556
1557\let\cite       \citation
1558\let\nocite     \nocitation
1559\let\usecitation\nocitation
1560
1561\unexpanded\def\publ_entry_citation  {\doifelsenextoptionalcs\btxlistcitation  \btxdirectlistcite}
1562\unexpanded\def\publ_entry_nocitation{\doifelsenextoptionalcs\btxhiddencitation\btxdirecthiddencite}
1563
1564\appendtoks
1565    \let\cite  \publ_entry_citation
1566    \let\nocite\publ_entry_nocitation
1567\to \everybtxlistrendering
1568
1569\unexpanded\def\btxdirectlistcite  #1{\btxlistcitation  [#1]\relax} % no optional arguments
1570\unexpanded\def\btxdirecthiddencite#1{\btxhiddencitation[#1]\relax} % no optional arguments
1571
1572%D Setup helpers, beware, we need to wrap this .. now we need to know
1573%D how setups are implemented.
1574
1575\setvalue{\??setup:\s!btx:\s!unknown}#1{\inframed{\tttf#1}}
1576
1577\def\publ_fast_setup_yes#1#2%
1578  {\csname\??setup:\s!btx:%
1579     \ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname
1580        \currentbtxspecification:#1:#2%
1581     \else\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:#2\endcsname
1582        \currentbtxspecificationfallback:#1:#2%
1583     \else\ifcsname\??setup:\s!btx:#1:#2\endcsname
1584        #1:#2%
1585     \else\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname
1586        \currentbtxspecification:#1:\s!unknown
1587     \else\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:\s!unknown\endcsname
1588        \currentbtxspecificationfallback:#1:\s!unknown
1589     \else
1590        #1:\s!unknown
1591     \fi\fi\fi\fi\fi
1592   \endcsname{#2}}
1593
1594\def\publ_fast_setup_nop#1#2%
1595  {\csname\??setup:\s!btx:%
1596     \ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname
1597        \currentbtxspecification:#1:#2%
1598     \else\ifcsname\??setup:\s!btx:#1:#2\endcsname
1599        #1:#2%
1600     \else\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname
1601        \currentbtxspecification:#1:\s!unknown
1602     \else
1603        #1:\s!unknown
1604     \fi\fi\fi
1605   \endcsname{#2}}
1606
1607\newconstant\btxsetuptype
1608
1609% 0 = unknown   darkred
1610% 1 = cite      darkblue
1611% 2 = subcite   darkgreen
1612% 3 = numbering darkorange
1613% 4 = list      darkcyan
1614% 5 = page      darkmagenta
1615% 6 = unknown   darkred
1616
1617\unexpanded\def\publ_fast_btx_setup_chain_inbetween
1618  {\allowbreak->\allowbreak}
1619
1620\unexpanded\def\publ_fast_btx_setup_colon_inbetween
1621  {\allowbreak:\allowbreak}
1622
1623\unexpanded\def\publ_fast_btx_setup_chain_yes#1#2%
1624  {\dontleavehmode\begingroup
1625   \let\:\publ_fast_btx_setup_colon_inbetween
1626   \infofont
1627   \ifcase\btxsetuptype\darkred\or\darkblue\or\darkgreen\or\darkcyan\or\darkmagenta\else\darkred\fi
1628   [\prewordbreak
1629   \currentbtxspecification        \:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname\else
1630   \publ_fast_btx_setup_chain_inbetween
1631   \currentbtxspecificationfallback\:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:#2\endcsname\else
1632   \publ_fast_btx_setup_chain_inbetween
1633                                     #1\:#2\ifcsname\??setup:\s!btx:#1:#2\endcsname\else
1634   \publ_fast_btx_setup_chain_inbetween
1635   \currentbtxspecification        \:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname\else
1636   \publ_fast_btx_setup_chain_inbetween
1637   \currentbtxspecificationfallback\:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:\s!unknown\endcsname\else
1638   \publ_fast_btx_setup_chain_inbetween
1639   unset\fi\fi\fi\fi\fi
1640   \space @\space
1641   \currentbtx
1642   \prewordbreak]%
1643   \endgroup}
1644
1645\unexpanded\def\publ_fast_btx_setup_chain_nop#1#2%
1646  {\dontleavehmode\begingroup
1647   \let\:\publ_fast_btx_setup_colon_inbetween
1648   \infofont
1649   \darkred
1650   [\prewordbreak
1651   \currentbtxspecification\:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname\else
1652   \publ_fast_btx_setup_chain_inbetween
1653                             #1\:#2\ifcsname\??setup:\s!btx:#1:#2\endcsname\else
1654   \publ_fast_btx_setup_chain_inbetween
1655   \currentbtxspecification\:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname\else
1656   \publ_fast_btx_setup_chain_inbetween
1657   unset\fi\fi\fi
1658   \space @\space
1659   \currentbtx
1660   \prewordbreak]%
1661   \endgroup}
1662
1663\unexpanded\def\publ_fast_btx_setup_normal#1%
1664  {\btxsetuptype#1\relax
1665   \ifx\currentbtxspecificationfallback\empty
1666     \expandafter\publ_fast_setup_nop
1667   \else
1668     \expandafter\publ_fast_setup_yes
1669   \fi}
1670
1671\unexpanded\def\publ_fast_btx_setup_visual#1#2#3%
1672  {\btxsetuptype#1\relax
1673   \ifx\currentbtxspecificationfallback\empty
1674     \expandafter\publ_fast_btx_setup_chain_nop
1675   \else
1676     \expandafter\publ_fast_btx_setup_chain_yes
1677   \fi{#2}{#3}%
1678   \ifx\currentbtxspecificationfallback\empty
1679     \expandafter\publ_fast_setup_nop
1680   \else
1681     \expandafter\publ_fast_setup_yes
1682   \fi{#2}{#3}}
1683
1684\installtextracker
1685  {publications.setups}
1686  {\let\publ_fast_setup\publ_fast_btx_setup_visual}
1687  {\let\publ_fast_setup\publ_fast_btx_setup_normal}
1688
1689\let\publ_fast_setup\publ_fast_btx_setup_normal
1690
1691%D Cite helpers:
1692
1693\newtoks\everybtxciteentry
1694
1695\prependtoks
1696     \setfalse\c_btx_cite_reference_injected
1697\to \everybtxciteentry
1698
1699\unexpanded\def\btxcitesetup#1%
1700  {\the\everybtxciteentry
1701   \everybtxciteentry\emptytoks % tricky maybe not when subcites
1702   \publ_fast_setup\plusone\s!cite{#1}}    % no \btxcitereset as we loose dataset and such
1703
1704\unexpanded\def\btxsubcitesetup#1%
1705  {\the\everybtxciteentry
1706   \everybtxciteentry\emptytoks % tricky maybe not when subcites
1707   \publ_fast_setup\plustwo\s!cite{#1}}    % no \btxcitereset as we loose dataset and such
1708
1709\appendtoks
1710    \btx_check_language
1711\to \everybtxciteentry
1712
1713\unexpanded\def\btxstartsubcite#1%
1714  {\begingroup
1715   \btx_reset_cite % todo: limited set
1716 % \saverunningstyleandcolor % let's see when Alan needs it
1717   \def\currentbtxcitealternative{#1}%
1718   \setbtxparameterset\s!cite\currentbtxcitealternative
1719   \usebtxstyleandcolor\c!style\c!color
1720   \btxparameter\c!left
1721   \relax}
1722
1723\unexpanded\def\btxstopsubcite
1724  {\relax
1725   \btxparameter\c!right
1726   \endgroup}
1727
1728\unexpanded\def\btxstartciterendering[#1]%
1729  {\begingroup
1730   \edef\currentbtxcitealternative{#1}%
1731   \setbtxparameterset\s!cite\currentbtxcitealternative
1732   \usebtxstyleandcolor\c!style\c!color
1733   \btxparameter\c!left
1734   \relax}
1735
1736\unexpanded\def\btxstopciterendering
1737  {\relax
1738   \btxparameter\c!right
1739   \endgroup}
1740
1741\let\btxstartciteauthor\begingroup
1742\let\btxstopciteauthor \endgroup
1743
1744\unexpanded\def\btxstartcite{\begingroup\btx_reset_cite}
1745           \let\btxstopcite  \endgroup
1746
1747%D Whatever helpers:
1748
1749\unexpanded\def\btxsingularplural#1{\clf_btxsingularorplural{\currentbtxdataset}{\currentbtxtag}{#1}}
1750\unexpanded\def\btxoneorrange    #1{\clf_btxoneorrange      {\currentbtxdataset}{\currentbtxtag}{#1}}
1751\unexpanded\def\btxfirstofrange  #1{\clf_btxfirstofrange    {\currentbtxdataset}{\currentbtxtag}{#1}}
1752
1753\let\btxsingularorplural\btxsingularplural
1754
1755\stopcontextdefinitioncode
1756
1757%D Journals
1758
1759\unexpanded\def\btxloadjournallist [#1]{\clf_btxloadjournallist{#1}}
1760\unexpanded\def\btxsavejournallist [#1]{\clf_btxsavejournallist{#1}}
1761\unexpanded\def\btxaddjournal  [#1][#2]{\clf_btxaddjournal{#1}{#2}}
1762           \def\btxexpandedjournal   #1{\clf_btxexpandedjournal{#1}}    % \unexpanded ?
1763           \def\btxabbreviatedjournal#1{\clf_btxabbreviatedjournal{#1}} % \unexpanded ?
1764
1765% \installcorenamespace{btxjournal}
1766%
1767% \letvalue{\s!btxjournal\v!long  }\btxexpandedjournal
1768% \letvalue{\s!btxjournal\v!short }\btxabbreviatedjournal
1769% \letvalue{\s!btxjournal\v!normal}\firstofoneargument
1770%
1771% \unexpanded\def\btxcheckedjournal
1772%   {\expandnamespaceparameter\s!btxjournal\btxrenderingparameter\c!journalconversion}
1773
1774% \btxloadjournallist[list.txt] % Foo Journal of Bars = FBJ \n ....
1775%
1776% \btxexpandedjournal[fbj]
1777% \btxabbreviatedjournal[foo journal of bars]
1778
1779%D Saving data:
1780
1781\unexpanded\def\savebtxdataset
1782  {\dotripleargument\publ_save_dataset}
1783
1784\unexpanded\def\publ_save_dataset[#1][#2][#3]%
1785  {\ifthirdargument
1786     \publ_save_dataset_indeed[#1][#2][#3]%
1787   \else\ifsecondargument
1788     \doifelseassignment{#2}%
1789       {\publ_save_dataset_indeed[\s!default][#1][#2]}%
1790       {\publ_save_dataset_indeed[#1][#2][]}%
1791   \else\iffirstargument
1792     \doifelseassignment{#1}%
1793       {\publ_save_dataset_indeed[\s!default][\jobname-saved.bib][#1]}%
1794       {\publ_save_dataset_indeed[\s!default][#1][]}%
1795 % \else
1796 %   % bad news
1797   \fi\fi\fi}
1798
1799\unexpanded\def\publ_save_dataset_indeed[#1][#2][#3]%
1800  {\begingroup
1801   \getdummyparameters
1802     [\c!criterium=\v!all,%
1803      \c!type=,%
1804      \c!dataset=#1,%
1805      \c!file=#2,%
1806      #3]% % all or used
1807   \clf_btxsavedataset
1808     dataset   {\dummyparameter\c!dataset}%
1809     filename  {\dummyparameter\c!file}%
1810     filetype  {\dummyparameter\c!type}%
1811     criterium {\dummyparameter\c!criterium}%
1812   \relax
1813   \endgroup}
1814
1815% \savebtxdataset[default][e:/tmp/foo.bib]
1816% \savebtxdataset[default][e:/tmp/foo.lua]
1817% \savebtxdataset[default][e:/tmp/foo.xml]
1818
1819%D In-text entries:
1820
1821\unexpanded\def\placecitation{\citation[entry]} % [#1]
1822
1823\unexpanded\def\btxhandleciteentry
1824  {\dontleavehmode
1825   \begingroup
1826   \def\currentbtxcitealternative{entry}%
1827   \setbtxparameterset\s!cite\currentbtxcitealternative % needs checking
1828   \btxcitereference
1829   \btx_entry_inject
1830   \endgroup}
1831
1832%D Registers
1833
1834% \setupbtxregister
1835%   [\c!state=\v!start,
1836%    \c!dataset=\v!all,
1837%    \c!method=\v!always]
1838
1839\unexpanded\def\publ_registers_set
1840  {\ifx\currentbtxregister\empty \else
1841     \clf_btxsetregister
1842        specification {\currentbtxspecification}%
1843        name          {\currentbtxregister}%
1844        state         {\btxregisterparameter\c!state}%
1845        dataset       {\btxregisterparameter\c!dataset}%
1846        field         {\btxregisterparameter\c!field}%
1847        register      {\btxregisterparameter\c!register}%
1848        method        {\btxregisterparameter\c!method}%
1849        alternative   {\btxregisterparameter\c!alternative}%
1850     \relax
1851  \fi}
1852
1853\appendtoks
1854    \publ_registers_set
1855\to \everydefinebtxregister
1856
1857\appendtoks
1858    \publ_registers_set
1859\to \everysetupbtxregister
1860
1861\appendtoks
1862    \normalexpanded{%
1863      \defineprocessor
1864        [\s!btx:r:\currentbtxregister]%
1865        [\c!style=\noexpand\namedbtxregisterparameter{\currentbtxregister}\noexpand\c!style,
1866         \c!color=\noexpand\namedbtxregisterparameter{\currentbtxregister}\noexpand\c!color]}%
1867\to \everydefinebtxregister
1868
1869\appendtoks
1870    \clf_btxtoregister{\currentbtxdataset}{\currentbtxtag}%
1871\to \t_btx_reference_inject
1872
1873\unexpanded\def\btxindexedauthor#1#2#3#4#5#6% alternative von last initials first junior
1874  {\begingroup
1875   \def\currentbtxcitealternative{#1}%
1876   \ifx\currentbtxcitealternative\empty
1877      \edef\currentbtxcitealternative{invertedshort}% maybe we need some default here too?
1878   \fi
1879   %let\currentbtxlistvariant\currentbtxcitealternative % we inherit
1880   \the\everysetupbtxciteplacement
1881   \def\currentbtxvons       {#2}%
1882   \def\currentbtxsurnames   {#3}%
1883   \def\currentbtxinitials   {#4}%
1884   \def\currentbtxfirstnames {#5}%
1885   \def\currentbtxjuniors    {#6}%
1886   \setbtxparameterset\s!cite\currentbtxcitealternative
1887   \fastsetup{\s!btx:\s!cite:\s!author:\currentbtxcitealternative}%
1888   \endgroup}
1889
1890\unexpanded\def\btxregisterauthor
1891  {\doifelsenextoptionalcs\publ_register_author_yes\publ_register_author_nop}
1892
1893\def\publ_register_author_yes[#1]#2%
1894  {\clf_btxauthortoregister{#1}{#2}\relax}
1895
1896\def\publ_register_author_nop#1%
1897  {\clf_btxauthortoregister{\currentbtxdataset}{#1}\relax}
1898
1899
1900%D We hook some setters in the definition sets:
1901
1902% \installdefinitionsetmember \??btx {btxspecification} \??btxcitevariant {btxcitevariant}
1903% \installdefinitionsetmember \??btx {btxspecification} \??btxlistvariant {btxlistvariant}
1904% \installdefinitionsetmember \??btx {btxspecification} \??btxlist        {btxlist}
1905% \installdefinitionsetmember \??btx {btxspecification} \??btxrendering   {btxrendering}
1906% \installdefinitionsetmember \??btx {btxspecification} \??btx            {btx}
1907
1908%D And more helpers ... a never ending story these publications:
1909
1910% \definebtx
1911%   [btx:apa:list:article:title]
1912%   [style=bolditalic,
1913%    command=\WORD]
1914%
1915% \btxstartstyle[btx:apa:list:article:title]
1916%     \btxusecommand[btx:apa:list:article:title]{foo}
1917% \btxstopstyle
1918
1919\let\savedcurrentbtx\empty
1920
1921\unexpanded\def\btxstartstyle[#1]%
1922  {\begingroup
1923   \let\savedcurrentbtx\currentbtx
1924   \def\currentbtx{#1}%
1925   \usebtxstyle\c!style
1926   \let\currentbtx\savedcurrentbtx}
1927
1928\unexpanded\def\btxstartcolor[#1]%
1929  {\begingroup
1930   \let\savedcurrentbtx\currentbtx
1931   \def\currentbtx{#1}%
1932   \usebtxcolor\c!color
1933   \let\currentbtx\savedcurrentbtx}
1934
1935\unexpanded\def\btxstartstyleandcolor[#1]%
1936  {\begingroup
1937   \let\savedcurrentbtx\currentbtx
1938   \def\currentbtx{#1}%
1939   \usebtxstyleandcolor\c!style\c!color
1940   \let\currentbtx\savedcurrentbtx}
1941
1942\let\btxstopstyle        \endgroup
1943\let\btxstopcolor        \endgroup
1944\let\btxstopstyleandcolor\endgroup
1945
1946\unexpanded\def\btxusecommand[#1]#2% using #2 permits space after []
1947  {\namedbtxparameter{#1}\c!command{#2}}
1948
1949\unexpanded\def\startbtxrunningstyleandcolor
1950  {\dontleavehmode
1951   \begingroup
1952   \restorerunningstyleandcolor}
1953
1954\unexpanded\def\stopbtxrunningstyleandcolor
1955  {\endgroup}
1956
1957%D Maybe handy:
1958
1959\unexpanded\def\btxdoifelsematches#1#2#3%
1960  {\clf_btxdoifelsematches{#1}{#2}{#3}}
1961
1962%D Defaults:
1963
1964\setupbtxrendering
1965  [\c!interaction=\v!start, % \v!all
1966   \c!specification=\btxparameter\c!specification,
1967   \c!dataset=\v!default,
1968   \c!repeat=\v!no,
1969   \c!continue=\v!no,
1970   \c!method=\v!global,
1971 % \c!setups=btx:\btxrenderingparameter\c!alternative:initialize, % not the same usage as cite !
1972   \c!sorttype=\v!default,
1973   \c!criterium=\v!text,
1974   \c!refcommand=authoryears,  % todo
1975   \c!numbering=\v!yes,
1976  %\c!saveinlist=\v!no, % maybe for before/after
1977   \c!pagestate=\v!stop,
1978   \c!textstate=\v!start,
1979   \c!width=\v!auto,
1980   \c!separator={\removepunctuation;\space},
1981   \c!distance=1.5\emwidth]
1982
1983% Quite some interpunction and labels are the same of at least consistent within
1984% a standard when citations and list entries are involved. We assume that each
1985% standard defines its own set but it can fall back on these defaults.
1986
1987\setupbtx
1988  [\c!interaction=\v!start,
1989   \c!alternative=num, % default cite form, normally defined in the cite namespace
1990   \c!inbetween=\btxspace,
1991 % \c!range=\endash,   % separator:range?
1992   \c!range=\directdiscretionary\endash,
1993   \c!compress=\v!yes, % was no?
1994   \c!authorconversion=normal,
1995   \c!sorttype=normal, % normal, reverse or none
1996   \c!etallimit=3,
1997   \c!etaldisplay=\btxparameter\c!etallimit,
1998   \c!otherstext={\btxspace et al.},
1999   \c!separator:firstnames={\btxspace},
2000   \c!separator:juniors={\btxspace},
2001   \c!separator:vons={\btxnobreakspace},
2002   \c!separator:initials={\btxspace},
2003   \c!connector:initials={\btxhyphen},
2004   \c!stopper:initials={.},
2005  %\c!surnamesep={\btxcomma}, % is this used anywhere?
2006   \c!separator:invertedinitials={\btxcomma},
2007   \c!separator:invertedfirstnames={\btxcomma},
2008   \c!separator:names:2={\btxcomma}, % separates multiple names
2009   \c!separator:names:3=\btxparameter{\c!separator:2}, % before last name in a list
2010   \c!separator:names:4=\btxparameter{\c!separator:2}, % between only two names
2011   \c!separator:2={\btxsemicolon}, % aka pubsep - separates multiple objects
2012   \c!separator:3=\btxparameter{separator:2}, % before last object in a list
2013   \c!separator:4=\btxparameter{separator:2}] % between only two objects
2014
2015% Do we want these in the format? Loading them delayed is somewhat messy.
2016
2017\loadbtxdefinitionfile[commands]
2018\loadbtxdefinitionfile[definitions]
2019
2020\loadbtxdefinitionfile[cite]
2021\loadbtxdefinitionfile[list]
2022\loadbtxdefinitionfile[page]
2023\loadbtxdefinitionfile[author]
2024
2025% we assume that the users sets up the right specification and if not ... well,
2026% hope for the best that something shows up and consult the manual otherwise
2027
2028\unexpanded\def\usebtxdefinitions[#1]%
2029  {\loadbtxdefinitionfile[#1]%     % for hh
2030   \setupbtx[\c!specification=#1]} % for ab
2031
2032\setupbtx
2033  [\c!specification=\s!default,
2034   \c!dataset=\v!default,
2035   \c!default=\v!default]
2036
2037\loadbtxdefinitionfile
2038  [\s!default]
2039
2040%D Delayed loading:
2041
2042\fetchruntimecommand \showbtxdatasetfields       \f!publ_tra
2043\fetchruntimecommand \showbtxdatasetcompleteness \f!publ_tra
2044\fetchruntimecommand \showbtxdatasetauthors      \f!publ_tra
2045\fetchruntimecommand \showbtxhashedauthors       \f!publ_tra
2046\fetchruntimecommand \showbtxfields              \f!publ_tra
2047\fetchruntimecommand \showbtxtables              \f!publ_tra
2048
2049%D Some potential crap:
2050%D
2051%D Because I consider this bad data management and a weird mix of languages only one
2052%D accessor is provided.
2053
2054\unexpanded\def\btxshortcut
2055  {\dosingleempty\publ_shortcut}
2056
2057\def\publ_shortcut[#1]#2%
2058  {\clf_btxshortcut{\iffirstargument#1\else\s!default\fi}{#2}}
2059
2060\protect
2061