publ-ini.mkiv /size: 70 Kb    last modification: 2021-10-28 13:50
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\hpack{\clf_btxcmdstring}}
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\btxcommabreak            {\removeunwantedspaces,\hskip\zeropoint plus .5\emwidth\relax}
421\unexpanded\def\btxcolon                 {\removeunwantedspaces:\space}
422\unexpanded\def\btxsemicolon             {\removeunwantedspaces;\space}
423\unexpanded\def\btxlparent               {\removeunwantedspaces\space(} % obsolete
424\unexpanded\def\btxrparent               {\removeunwantedspaces)\space} % obsolete
425\unexpanded\def\btxleftparenthesis       {\removeunwantedspaces\space(}
426\unexpanded\def\btxrightparenthesis      {\removeunwantedspaces)\space}
427\unexpanded\def\btxrightparenthesisperiod{\removeunwantedspaces).\space}
428\unexpanded\def\btxrightparenthesiscomma {\removeunwantedspaces),\space}
429\unexpanded\def\btxleftbracket           {\removeunwantedspaces\space[}
430\unexpanded\def\btxrightbracket          {\removeunwantedspaces]\space}
431\unexpanded\def\btxrightbracketperiod    {\removeunwantedspaces].\space}
432\unexpanded\def\btxrightbracketcomma     {\removeunwantedspaces],\space}
433
434%D Variables:
435
436\let\currentbtxbacklink     \empty    \unexpanded\def\btxsetbacklink     {\def\currentbtxbacklink}
437\let\currentbtxcategory     \empty    \unexpanded\def\btxsetcategory     {\def\currentbtxcategory}
438\let\currentbtxcombis       \empty    \unexpanded\def\btxsetcombis       {\def\currentbtxcombis}
439\let\currentbtxdataset      \empty    \unexpanded\def\btxsetdataset      {\def\currentbtxdataset}
440\let\currentbtxfirst        \empty    \unexpanded\def\btxsetfirst        {\def\currentbtxfirst}
441\let\currentbtxsecond       \empty    \unexpanded\def\btxsetsecond       {\def\currentbtxsecond}
442\let\currentbtxsuffix       \empty    \unexpanded\def\btxsetsuffix       {\def\currentbtxsuffix}
443\let\currentbtxinternal     \empty    \unexpanded\def\btxsetinternal     {\def\currentbtxinternal}
444\let\currentbtxlefttext     \empty    \unexpanded\def\btxsetlefttext     {\def\currentbtxlefttext}
445\let\currentbtxrighttext    \empty    \unexpanded\def\btxsetrighttext    {\def\currentbtxrighttext}
446\let\currentbtxbefore       \empty    \unexpanded\def\btxsetbefore       {\def\currentbtxbefore}
447\let\currentbtxafter        \empty    \unexpanded\def\btxsetafter        {\def\currentbtxafter}
448\let\currentbtxlanguage     \empty    \unexpanded\def\btxsetlanguage     {\def\currentbtxlanguage}
449\let\currentbtxtag          \empty    \unexpanded\def\btxsettag          {\def\currentbtxtag}
450\let\currentbtxnumber       \empty    \unexpanded\def\btxsetnumber       {\def\currentbtxnumber}
451\let\currentbtxfirstinternal\empty    \unexpanded\def\btxsetfirstinternal{\def\currentbtxfirstinternal}
452\let\currentbtxlastinternal \empty    \unexpanded\def\btxsetlastinternal {\def\currentbtxlastinternal}
453
454\let\currentbtxauthorvariant\v!normal \unexpanded\def\btxsetauthorvariant{\def\currentbtxauthorvariant}
455\let\currentbtxfirstnames   \empty    \unexpanded\def\btxsetfirstnames   {\let\currentbtxfirstnames\currentbtxfirstnames_indeed}
456\let\currentbtxinitials     \empty    \unexpanded\def\btxsetinitials     {\let\currentbtxinitials  \currentbtxinitials_indeed  }
457\let\currentbtxjuniors      \empty    \unexpanded\def\btxsetjuniors      {\let\currentbtxjuniors   \currentbtxjuniors_indeed   }
458\let\currentbtxsurnames     \empty    \unexpanded\def\btxsetsurnames     {\let\currentbtxsurnames  \currentbtxsurnames_indeed  }
459\let\currentbtxvons         \empty    \unexpanded\def\btxsetvons         {\let\currentbtxvons      \currentbtxvons_indeed      }
460
461\newconstant\currentbtxoverflow       \unexpanded\def\btxsetoverflow   #1{\currentbtxoverflow   #1\relax}
462\newconstant\currentbtxconcat         \unexpanded\def\btxsetconcat     #1{\currentbtxconcat     #1\relax}
463\newconstant\currentbtxcount          \unexpanded\def\btxsetcount      #1{\currentbtxcount      #1\relax}
464\newconstant\currentbtxauthorindex    %unexpanded\def\btxsetauthorindex#1{\currentbtxauthorindex#1\relax} % passed directly
465\newconstant\currentbtxauthorcount    %unexpanded\def\btxsetauthorcount#1{\currentbtxauthorcount#1\relax} % passed directly
466\newconstant\currentbtxauthorstate    \unexpanded\def\btxsetauthorstate#1{\currentbtxauthorstate#1\relax}
467
468\unexpanded\def\currentbtxfirstnames_indeed{\clf_btxcurrentfirstnames\numexpr\currentbtxauthorindex\relax}
469\unexpanded\def\currentbtxinitials_indeed  {\clf_btxcurrentinitials  \numexpr\currentbtxauthorindex\relax}
470\unexpanded\def\currentbtxjuniors_indeed   {\clf_btxcurrentjuniors   \numexpr\currentbtxauthorindex\relax}
471\unexpanded\def\currentbtxsurnames_indeed  {\clf_btxcurrentsurnames  \numexpr\currentbtxauthorindex\relax}
472\unexpanded\def\currentbtxvons_indeed      {\clf_btxcurrentvons      \numexpr\currentbtxauthorindex\relax}
473
474\let\currentbtxfirstpage    \empty \unexpanded\def\btxsetfirstpage#1{\def\currentbtxfirstpage{\btx_page_number{#1}}}
475\let\currentbtxlastpage     \empty \unexpanded\def\btxsetlastpage #1{\def\currentbtxlastpage {\btx_page_number{#1}}}
476
477\def\currentbtxauthorvariant{normal}
478
479\unexpanded\def\btx_reset_list % not needed as we're grouped
480  {\let\currentbtxcombis   \empty
481   \let\currentbtxcategory \empty
482   \let\currentbtxinternal \empty
483   \let\currentbtxlefttext \empty
484   \let\currentbtxrighttext\empty
485   \let\currentbtxbefore   \empty
486   \let\currentbtxafter    \empty
487   \let\currentbtxbacklink \empty
488   \let\currentbtxlanguage \empty
489   \let\currentbtxsuffix   \empty
490  %\let\currentbtxdataset  \empty % will always be set
491  %\let\currentbtxtag      \empty % will always be set
492   \let\currentbtxnumber   \empty}
493
494\unexpanded\def\btx_reset_cite % check for less .. not all resets needed when we're grouped (only subcites)
495  {\let        \currentbtxfirst      \empty
496   \let        \currentbtxsecond     \empty
497   \let        \currentbtxsuffix     \empty
498   \let        \currentbtxinternal   \empty
499   \let        \currentbtxlefttext   \empty
500   \let        \currentbtxrighttext  \empty
501   \let        \currentbtxbefore     \empty
502   \let        \currentbtxafter      \empty
503   \let        \currentbtxbacklink   \empty
504   \let        \currentbtxlanguage   \empty
505  %\let        \currentbtxdataset    \empty % will always be set, beware of local reset ~
506  %\let        \currentbtxtag        \empty % will always be set, beware of local reset ~
507   \let        \currentbtxnumber     \empty
508   \setconstant\currentbtxoverflow   \zerocount
509   \setconstant\currentbtxconcat     \zerocount
510   \setconstant\currentbtxcount      \zerocount}
511
512\unexpanded\def\btx_reset_page % probably not needed
513  {\let        \currentbtxfirstpage    \empty
514   \let        \currentbtxlastpage     \empty
515   \let        \currentbtxfirstinternal\empty
516   \let        \currentbtxlastinternal \empty
517   \setconstant\currentbtxoverflow     \zerocount
518   \setconstant\currentbtxconcat       \zerocount
519   \setconstant\currentbtxcount        \zerocount}
520
521\unexpanded\def\btx_reset_numbering  % probably not needed
522  {\let        \currentbtxfirst \empty
523   \let        \currentbtxsecond\empty
524   \let        \currentbtxsuffix\empty
525   \setconstant\currentbtxconcat\zerocount}
526
527%D Pages:
528
529\unexpanded\def\btx_page_number#1%
530  {\def\currentlistindex{#1}%
531   \structurelistpagenumber}
532
533%D Language:
534
535\def\mainbtxlanguage{\currentmainlanguage}
536
537\unexpanded\def\btx_check_language
538  {\let\mainbtxlanguage\currentlanguage
539   \ifx\currentbtxlanguage\empty
540     \let\currentbtxlanguage\currentlanguage
541   \else
542     \btx_check_language_indeed
543   \fi}
544
545\unexpanded\def\btx_check_language_indeed
546  {\edef\currentbtxlanguage{\reallanguagetag\currentbtxlanguage}%
547   \ifx\currentbtxlanguage\empty
548     \let\currentbtxlanguage\currentlanguage
549   \else\ifx\currentbtxlanguage\currentlanguage\else
550     \setcurrentlanguage\currentmainlanguage\currentbtxlanguage
551   \fi\fi}
552
553%D Tracing
554
555\newconditional\c_btx_trace % not used yet
556
557\installtextracker
558  {btxrendering}
559  {\settrue \c_btx_trace}
560  {\setfalse\c_btx_trace}
561
562%D Rendering lists and citations.
563
564\unexpanded\def\btxtodo#1%
565  {[#1]}
566
567%D Lists:
568
569\newdimen\d_publ_number_width
570
571\ifdefined\btxblock       \else \newcount\btxblock       \fi \btxblock\plusone
572\ifdefined\btxcitecounter \else \newcount\btxcitecounter \fi % maybe pass this to lua
573
574\newtoks \everysetupbtxlistplacement % name will change
575\newtoks \everysetupbtxciteplacement % name will change
576
577\definelist % only used for selecting
578  [\s!btx]
579
580\setuplist
581  [\s!btx]
582  [\c!prefixstopper=:,
583   \c!state=\v!start,
584   \c!alternative=a,
585   \c!interaction=\v!none,
586  %\c!alternative=\v!paragraph,
587  %\c!width=\v!auto,
588  %\c!distance=\emwidth,
589   \c!before=\blank,
590   \c!after=\blank]
591
592\unexpanded\def\setupbtxlist
593  {\dodoubleempty\publ_setup_list}
594
595\unexpanded\def\publ_setup_list[#1][#2]%
596  {\ifsecondargument
597     \setuplist[\s!btx:#1][#2]%
598   \else\iffirstargument
599     \setuplist[\s!btx][#1]%
600   \fi\fi}
601
602\appendtoks
603    \ifx\currentbtxrenderingparent\empty
604        \definelist
605          [\s!btx:\currentbtxrendering]%
606          [\s!btx]%
607    \else\ifx\currentbtxrenderingparent\s!btx
608        \definelist
609          [\s!btx:\currentbtxrendering]%
610          [\s!btx]%
611    \else
612        \definelist
613          [\s!btx:\currentbtxrendering]%
614          [\s!btx:\currentbtxrenderingparent]%
615    \fi\fi
616\to \everydefinebtxrendering
617
618\newconditional\c_btx_list_texts
619
620\appendtoks
621    \doifelse{\btxrenderingparameter\c!textstate}\v!start
622      \settrue\setfalse\c_btx_list_texts
623\to \everysetupbtxlistplacement
624
625\newconditional\c_btx_list_pages
626
627\appendtoks
628    \doifelse{\btxrenderingparameter\c!pagestate}\v!start
629      \settrue\setfalse\c_btx_list_pages
630\to \everysetupbtxlistplacement
631
632\unexpanded\def\btx_entry_inject_pages % for the moment only normal
633  {\dontleavehmode
634   \begingroup
635   \setbtxlist % probably already set
636   \btx_reset_page
637   \setbtxparameterset\s!list\s!page
638   \btxparameter\c!command
639     {\usebtxstyleandcolor\c!style\c!color
640      \btxparameter\c!left
641      \clf_btxflushpages{\currentbtxdataset}{\currentbtxtag}%
642      \btxparameter\c!right}%
643   \endgroup}
644
645\unexpanded\def\btxpagesetup#1% there will be no left|right|command|style at this inner level
646  {\begingroup
647   \publ_fast_setup\plusfive\s!list\s!page
648   \endgroup
649   \btx_reset_page} % probably not needed
650
651\unexpanded\def\btxnumberingsetup#1%
652  {\begingroup
653   \dostarttagged\t!listtag\empty
654   \setbtxparameterset{\c!list:\s!numbering}\currentbtxnumbering % brrrr   \setbtxlist
655   \btxparameter\c!left
656 % \btxparameter\c!command{\publ_fast_setup\plusthree{\s!list:\s!numbering}{#1}}%
657   \publ_fast_setup\plusthree{\s!list:\s!numbering}{#1}%
658   \btxparameter\c!right
659   \dostoptagged
660   \endgroup
661   \btx_reset_numbering} % probably not needed
662
663% end of page stuff
664
665\unexpanded\def\btxflushlisttext
666  {\begingroup
667   \usebtxstyleandcolor\c!style\c!color
668   \ignorespaces
669   \publ_fast_setup\plusfour\s!list\currentbtxcategory
670   \removeunwantedspaces
671   \endgroup}
672
673\unexpanded\def\btxflushlistcombis
674  {\begingroup
675   \processcommacommand[\currentbtxcombis]\btx_entry_inject_combi % maybe in lua
676   \endgroup}
677
678\def\btx_entry_inject_list_text
679  {\publ_fast_setup\plusfour\s!list\s!text}
680
681\ifdefined\dotagpublication \else \let\dotagpublication \gobbletwoarguments \fi
682
683\unexpanded\def\btx_entry_inject
684  {\begingroup
685   \dostarttagged\t!publication\empty
686   \dotagpublication\currentbtxdataset\currentbtxtag
687   \redoconvertfont % see (**) in strc-lst, this will become an configuration option
688   \edef\currentbtxcategory{\btxrawfield{category}}%
689   \ignorespaces
690   \ifconditional\c_btx_list_texts
691     \dostarttagged\t!listtext\s!left
692     \currentbtxbefore
693     \dostoptagged
694   \fi
695  %\dostarttagged\t!listcontent\empty
696   \btx_entry_inject_list_text
697  %\dostoptagged
698   \ifconditional\c_btx_list_pages
699     \dostarttagged\t!listpage\empty
700     \btx_entry_inject_pages
701     \dostoptagged
702   \fi
703   \ifconditional\c_btx_list_texts
704     \dostarttagged\t!listtext\s!right
705     \currentbtxafter
706     \dostoptagged
707   \fi
708   \dostoptagged
709   \endgroup}
710
711\unexpanded\def\btxshowentryinline
712  {\dodoubleempty\btx_entry_show_inline}
713
714\unexpanded\def\btx_entry_show_inline[#1][#2]%
715  {\ifsecondargument
716     \ctxcommand{showbtxentry("#1","#2")}
717   \else\iffirstargument
718     \ctxcommand{showbtxentry("\currentbtxdataset","#1")}
719   \else
720     \ctxcommand{showbtxentry("\currentbtxdataset","\currentbtxtag")}
721   \fi\fi}
722
723\unexpanded\def\btxstartcombientry
724  {\begingroup}
725
726\unexpanded\def\btxstopcombientry
727  {\endgroup}
728
729\unexpanded\def\btxhandlecombientry
730  {\btx_reference_indeed}
731
732\def\btx_entry_inject_combi#1%
733  {\begingroup
734   \def\currentbtxtag{#1}%
735   \ignorespaces
736   \publ_fast_setup\plusfour\s!list\currentbtxcategory
737   \removeunwantedspaces
738   \endgroup}
739
740% uses reference when set
741
742% \def\btx_entry_inject_combi#1%
743%   {\begingroup
744%    \def\currentbtxtag{#1}%
745%    \ignorespaces
746%    \btxdoifelsecombiinlist\currentbtxdataset\currentbtxtag
747%      {\clf_btxflushlistcombi{\currentbtxdataset}{\currentbtxtag}}
748%      {\publ_fast_setup\plusfour\s!list\currentbtxcategory}%
749%    \removeunwantedspaces
750%    \endgroup}
751
752\unexpanded\def\placebtxrendering   {\dodoubleempty\publ_place_list_standard}
753\unexpanded\def\completebtxrendering{\dodoubleempty\publ_place_list_complete}
754\unexpanded\def\flushbtxrendering   {\dodoubleempty\publ_place_list_special }
755
756\let\completelistofpublications\completebtxrendering % for old times sake
757\let\placelistofpublications   \placebtxrendering    % for old times sake
758
759\newtoks\everybtxlistrendering
760
761\appendtoks
762    \setbtxlist
763    %
764    \edef\currentbtxcriterium{\btxrenderingparameter\c!criterium}% \v!cite will become \s!cite
765    \ifx\currentbtxcriterium\empty
766        \let\currentbtxcriterium\v!previous
767    \else\ifx\currentbtxcriterium\v!cite
768        \let\currentbtxcriterium\v!here
769    \fi\fi
770    %
771    \iflocation
772        \letinteractionparameter\c!style\empty
773%         \letinteractionparameter\c!color\empty
774%         \letinteractionparameter\c!contrastcolor\empty
775    \fi
776\to \everybtxlistrendering
777
778\def\nofbtxlistentries  {0}
779\def\currentbtxlistentry{0}
780\def\currentbtxlistindex{0} % only for internal use (points back to big list)
781
782\newconditional\c_publ_prefixed
783
784\unexpanded\def\btxsetnoflistentries  #1{\edef\nofbtxlistentries  {#1}}
785\unexpanded\def\btxsetcurrentlistentry#1{\edef\currentbtxlistentry{#1}}
786\unexpanded\def\btxsetcurrentlistindex#1{\edef\currentbtxlistindex{#1}}
787
788\unexpanded\def\btxdoifelsesameaspreviouschecked#1#2% #1 == always | doublesided
789  {\clf_btxdoifelsesameasprevious
790     {\currentbtxdataset}%
791     \currentbtxlistentry%
792     {#2}%
793     \c_btx_list_reference
794     {#1}}
795
796\unexpanded\def\btxdoifelsesameasprevious
797  {\btxdoifelsesameaspreviouschecked\v!doublesided}
798
799\unexpanded\def\btxdoifelsecombiinlist#1#2%
800  {\clf_btxdoifelsecombiinlist{#1}{#2}}
801
802\unexpanded\def\btxdoifelsecitedone#1#2%
803  {\clf_btxdoifelsecitedone{#1}{#2}}
804
805\let\btxdoifsameaspreviouscheckedelse\btxdoifelsesameaspreviouschecked
806\let\btxdoifsameaspreviouselse       \btxdoifelsesameasprevious
807\let\btxdoifcombiinlistelse          \btxdoifelsecombiinlist
808\let\btxdoifcitedoneelse             \btxdoifelsecitedone
809
810\def\publ_place_list_indeed#1#2[#3][#4]%
811  {\begingroup
812   \ifsecondargument
813     % [rendering] [settings]
814     \edef\currentbtxrendering{#3}%
815     \setupcurrentbtxrendering[#4]%
816     \edef\p_specification{\btxrenderingparameter\c!specification}%
817     \ifx\p_specification\empty\else
818       \let\currentbtxspecification\p_specification
819     \fi
820   \else\iffirstargument
821     \doifelseassignment{#3}
822       {% [settings]
823        \let\currentbtxrendering\currentbtxspecification
824        \setupcurrentbtxrendering[#3]%
825        \edef\p_specification{\btxrenderingparameter\c!specification}%
826        \ifx\p_specification\empty\else
827           \let\currentbtxspecification\p_specification
828           \let\currentbtxrendering\currentbtxspecification % tricky
829        \fi}
830       {\edef\currentbtxrendering{#3}%
831        \edef\p_specification{\btxrenderingparameter\c!specification}%
832        \ifx\p_specification\empty\else
833          \let\currentbtxspecification\p_specification
834        \fi}%
835   \else
836     \let\currentbtxrendering\currentbtxspecification
837   \fi\fi
838   \setbtxparameterset\currentbtxspecification\s!list
839   \the\everybtxlistrendering
840   \ifconditional#1\relax
841     \edef\currentbtxrenderingtitle{\btxrenderingparameter\c!title}%
842     \ifx\currentbtxrenderingtitle\empty
843       \normalexpanded{\startnamedsection[\v!chapter][\c!reference=\currentbtxrendering,\c!title={\headtext{\currentbtxrendering}}]}%
844     \else
845       \normalexpanded{\startnamedsection[\v!chapter][\c!reference=\currentbtxrendering,\c!title={\currentbtxrenderingtitle}]}%
846     \fi
847   \fi
848   \ifx\currentbtxrendering\empty
849     \setbtxrendering % hm
850   \fi
851   \edef\currentbtxdataset{\btxrenderingparameter\c!dataset}%
852   \uselanguageparameter\btxdatasetparameter % new
853   \setbtxlist
854   \the\everystructurelist
855   \the\everysetupbtxlistplacement
856   % why not pass this with collect .. todo
857   % here we just collect items
858   \clf_btxcollectlistentries
859       names     {\s!btx}%
860       criterium {\currentbtxcriterium}%
861       reference {\btxrenderingparameter\c!reference}%
862       method    {\btxrenderingparameter\c!method}%
863       dataset   {\currentbtxdataset}%
864       keyword   {\btxrenderingparameter\c!keyword}%
865       sorttype  {\btxrenderingparameter\c!sorttype}%
866       repeated  {\btxrenderingparameter\c!repeat}%
867       ignored   {\btxrenderingparameter\c!ignore}%
868       group     {\btxrenderingparameter\c!group}%
869       filter    {\btxrenderingparameter\c!filter}%
870   \relax
871   \ifnum\nofbtxlistentries>\zerocount
872     \forgetall
873     \btxrenderingparameter\c!before
874     \ifconditional#2\relax
875       \edef\p_command{\btxrenderingparameter\c!command}%
876       \ifx\p_command\empty
877         \edef\p_setups{\btxrenderingparameter\c!setups}%
878         \ifx\p_setups\empty
879         \else
880           \directsetup{\p_setups}%
881         \fi
882       \else
883         \expandafter\p_command\expandafter{\number\nofbtxlistentries}\relax
884       \fi
885     \else
886       \dostarttagged\t!publications\currentbtxrendering
887       \dostarttagged\t!list{btx}%
888       \startpacked[\v!blank]%
889       % sorting and so
890       \clf_btxpreparelistentries{\currentbtxdataset}% could be put in collect
891       % next we analyze the width
892       \ifx\currentbtxnumbering\empty \else
893         \edef\p_width{\listparameter\c!width}%
894         \ifx\p_width\v!auto
895           \setbox\scratchbox\vbox \bgroup
896             \settrialtypesetting
897             \clf_btxfetchlistentries{\currentbtxdataset}%
898           \egroup
899           \d_publ_number_width\wd\scratchbox
900           \letlistparameter\c!width\d_publ_number_width
901         \fi
902       \fi
903       \doifelse{\listparameter\c!prefix}\v!yes\settrue\setfalse\c_publ_prefixed
904       % this actually typesets them, we loop here as otherwise the whole
905       % bunch gets flushed at once
906       \dorecurse\nofbtxlistentries
907          {\let\currentbtxlistentry\recurselevel
908           \clf_btxflushlistentry{\currentbtxdataset}\currentbtxlistentry\relax}%
909       \stoppacked
910       \dostoptagged
911       \dostoptagged
912     \fi
913     \btxrenderingparameter\c!after
914   \fi
915   \ifconditional#1\relax
916     \stopnamedsection
917   \fi
918   \global\advance\btxblock\plusone
919   \endgroup}
920
921\def\publ_place_list_standard{\publ_place_list_indeed\conditionalfalse\conditionalfalse}
922\def\publ_place_list_complete{\publ_place_list_indeed\conditionaltrue \conditionalfalse}
923\def\publ_place_list_special {\publ_place_list_indeed\conditionalfalse\conditionaltrue}
924
925%D This is somewhat special (for Alan of course):
926%D
927%D \starttyping
928%D % #1 is number of entries
929%D
930%D \starttexdefinition mutable protected btx:for:alan:wrapper #1
931%D     \bTABLE
932%D         % we can have a command or setups
933%D         \flushbtxentries[command=\texdefinition{btx:for:alan:content}]
934%D     \eTABLE
935%D \stoptexdefinition
936%D
937%D % #1 is tag
938%D
939%D \starttexdefinition mutable protected btx:for:alan:content #1
940%D     \bTR
941%D         \bTD
942%D             \btxsettag{#1}
943%D             \btxfield{name}
944%D         \eTD
945%D     \eTR
946%D \stoptexdefinition
947%D
948%D % we can have a command or setups
949%D
950%D \flushbtxrendering [method=dataset,command=\texdefinition{btx:for:alan:wrapper}]
951%D \stoptyping
952%D
953%D Because we want to be ungrouped we use a special loop construct.
954
955\unexpanded\def\btxsetlisttag#1%
956  {\clf_btxflushlisttag{\currentbtxdataset}#1\relax}
957
958\newcount\c_btx_list_index
959\let\m_btx_list_action\empty
960
961\def\publ_flush_list_step_command
962  {\btxsetlisttag{\c_btx_list_index}
963   \expandafter\m_btx_list_action\expandafter{\currentbtxtag}%
964   \ifnum\c_btx_list_index<\nofbtxlistentries
965     \advance\c_btx_list_index\plusone
966     \expandafter\publ_flush_list_step_command
967   \else
968     \glet\m_btx_list_action\relax
969   \fi}
970
971\def\publ_flush_list_step_setup
972  {\btxsetlisttag{\c_btx_list_index}
973   \directsetup{\m_btx_list_action}%
974   \ifnum\c_btx_list_index<\nofbtxlistentries
975     \advance\c_btx_list_index\plusone
976     \expandafter\publ_flush_list_step_setup
977   \else
978     \glet\m_btx_list_action\relax
979   \fi}
980
981\unexpanded\def\flushbtxentries[#1]%
982  {\begingroup
983   \getdummyparameters[\c!command=,\c!setups=,#1]%
984   \xdef\m_btx_list_action{\dummyparameter\c!command}%
985   \ifx\m_btx_list_action\empty
986     \xdef\m_btx_list_action{\dummyparameter\c!setups}%
987     \ifx\m_btx_list_action\empty
988       \endgroup
989       \c_btx_list_index\zerocount
990     \else
991       \endgroup
992       \c_btx_list_index\plusone
993       \doubleexpandafter\publ_flush_list_step_command
994     \fi
995   \else
996     \endgroup
997     \c_btx_list_index\plusone
998     \expandafter\publ_flush_list_step_command
999   \fi}
1000
1001%D So far.
1002
1003\def\currentbtxblock{\number\btxblock}
1004
1005% called at the lua end, for determining the width
1006
1007\unexpanded\def\btxchecklistentry
1008  {\begingroup
1009   % todo, switch to font
1010   \hbox{\btx_reference_checked}%
1011   \par
1012   \endgroup}
1013
1014% called at the lua end, the real rendering
1015
1016% we could have a yes and no where o nils the btx_reference_indeed ... saves a check there
1017
1018\installstructurelistprocessor{\s!btx}
1019  {\let\currentlistentrynumber    \btx_reference_indeed
1020   \let\currentlistentrytitle     \btx_entry_indeed
1021   \let\currentlistentrypagenumber\btx_page_indeed
1022   \strc_lists_apply_renderingsetup}
1023
1024\def\btx_entry_indeed
1025  {\dostarttagged\t!listcontent\empty
1026   \btx_list_reference_inject
1027   \btx_entry_inject
1028   \dostoptagged}
1029
1030\def\btx_page_indeed
1031  {}
1032
1033\unexpanded\def\btxhandlelistentry
1034  {\strc_lists_entry_process}
1035
1036\unexpanded\def\btxstartlistentry % maybe pass i
1037  {\begingroup
1038   \global\advance\c_btx_list_reference\plusone}
1039
1040\unexpanded\def\btxstoplistentry
1041  {\iftrialtypesetting
1042     \global\advance\c_btx_list_reference\minusone
1043   \fi
1044   \endgroup}
1045
1046\newtoks\everybtxlistentry
1047
1048\unexpanded\def\btxlistsetup#1% used for the reference in the list
1049  {\the\everybtxlistentry
1050   \everybtxlistentry\emptytoks % so only once per entry to be sure
1051   \publ_fast_setup\plusfour\s!list{#1}}
1052
1053\appendtoks
1054    \btx_check_language
1055\to \everybtxlistentry
1056
1057\unexpanded\def\btx_reference_indeed
1058  {\begingroup
1059   % redundant will go away:
1060   \setbtxparameterset{\c!list:\s!numbering}\currentbtxnumbering
1061   %
1062   \ifx\currentbtxnumbering\empty
1063     % nothing
1064   \else\ifx\currentbtxnumbering\v!no
1065     % nothing
1066   \else
1067     \usebtxstyleandcolor\c!style\c!color % new, needed?
1068     \ifconditional\c_publ_prefixed\btxlistprefixednumber\fi
1069     \clf_btxlistvariant % some can go
1070       {\currentbtxdataset}%
1071       {\currentbtxblock}%
1072       {\currentbtxtag}%
1073       {\currentbtxnumbering}%
1074       {\currentbtxnumber}%
1075     \relax
1076   \fi\fi
1077   \endgroup}
1078
1079\unexpanded\def\btxlistprefixednumber % hack but alan needs it
1080  {\clf_listprefixednumber
1081     {\currentlist}%
1082     \currentbtxlistindex
1083     {%
1084        prefix        {\listparameter\c!prefix}%
1085        separatorset  {\listparameter\c!prefixseparatorset}%
1086        conversionset {\listparameter\c!prefixconversionset}%
1087        starter       {\listparameter\c!prefixstarter}%
1088        stopper       {\listparameter\c!prefixstopper}%
1089        set           {\listparameter\c!prefixset}%
1090        segments      {\listparameter\c!prefixsegments}%
1091        connector     {\listparameter\c!prefixconnector}%
1092     }%
1093   \relax}
1094
1095\unexpanded\def\btx_reference_checked
1096  {\dontleavehmode\hbox\bgroup % \hpack
1097     \btx_reference_indeed
1098   \egroup}
1099
1100\newcount\c_btx_list_reference
1101
1102\unexpanded\def\btx_list_reference_inject
1103  {\dontleavehmode\begingroup % no box
1104     \iftrialtypesetting\else
1105       \btx_list_reference_inject_now
1106     \fi
1107   % \btx_reference_indeed % else double entry in list
1108   \endgroup}
1109
1110\def\btx_list_reference_inject_now
1111  {\strc_references_direct_full_user
1112      {\ifx\currentbtxdataset\v!default\else\s!btxset=\currentbtxdataset,\fi%
1113       \s!btxref=\currentbtxtag,%
1114       \s!btxspc=\currentbtxspecification,%
1115       \s!btxlst=\number\c_btx_list_reference,% check if needed
1116      %\ifx\currentbtxcombis  \empty\else\s!btxcom={\currentbtxcombis},\fi%
1117       \ifx\currentbtxbefore  \empty\else\s!btxbtx={\currentbtxbefore},\fi%
1118       \ifx\currentbtxafter   \empty\else\s!btxatx={\currentbtxafter },\fi%
1119       \ifx\currentbtxbacklink\empty\else\s!btxint=\number\currentbtxbacklink\fi
1120      }%
1121      {\s!btx::\v!list::\number\c_btx_list_reference}%
1122      {\currentbtxnumber}}
1123
1124\newconditional\c_btx_cite_reference_injected
1125
1126\unexpanded\def\btx_cite_reference_inject
1127  {\ifconditional\c_btx_cite_reference_injected
1128   \else
1129     \dontleavehmode
1130     \iftrialtypesetting \else
1131       \ifx\currentbtxbacklink\empty
1132         % can be made empty when combining author / year
1133       \else\ifnum\currentbtxbacklink>\zerocount
1134         \btx_cite_reference_inject_indeed
1135         \settrue\c_btx_cite_reference_injected
1136       \fi\fi
1137     \fi
1138  \fi}
1139
1140\newtoks\t_btx_reference_inject
1141
1142\def\btx_cite_reference_inject_indeed
1143  {\the\t_btx_reference_inject
1144   \strc_lists_inject_direct % todo: make like \btx_list_reference_inject_now with { }
1145      [\s!btx]%
1146      [\c!type=\s!btx]% \c!location=\v!none
1147      [\ifx\currentbtxdataset\v!default\else\s!btxset=\currentbtxdataset,\fi%
1148       \s!btxref=\currentbtxtag,%
1149      %\ifx\currentbtxcombis  \empty\else\s!btxcom={\currentbtxcombis},\fi%
1150       \ifx\currentbtxbefore  \empty\else\s!btxbtx={\currentbtxbefore},\fi%
1151       \ifx\currentbtxafter   \empty\else\s!btxatx={\currentbtxafter },\fi%
1152       \ifx\currentbtxbacklink\empty\else\s!btxint=\number\currentbtxbacklink,\fi
1153       \ifx\currentbtxciteuservariables\empty\else,\currentbtxciteuservariables\fi]}
1154
1155\def\currentbtxuservariable #1{\clf_btxuservariable        {\currentbtxdataset}{#1}}
1156\def\btxdoifelseuservariable#1{\clf_btxdoifelseuservariable{\currentbtxdataset}{#1}}
1157
1158\let\btxdoifuservariableelse\btxdoifelseuservariable
1159
1160\let\btxcitereference\btx_cite_reference_inject
1161
1162\let\currentbtxnumbering       \empty
1163\let\currentbtxcitealternative \empty
1164
1165\appendtoks
1166    \edef\currentbtxnumbering{\btxrenderingparameter\c!numbering}%
1167    \ifx\currentbtxnumbering\v!yes
1168        \def\currentbtxnumbering{num}% convenient alias
1169        \letbtxrenderingparameter\c!numbering\currentbtxnumbering
1170        \letlistparameter\c!headnumber\v!always
1171    \else\ifx\currentbtxnumbering\v!no
1172        \letlistparameter\c!headnumber\v!no
1173        \let\currentbtxnumbering\empty
1174      % \letlistparameter\c!textcommand\outdented % needed? we can use titlealign
1175        \letlistparameter\c!symbol     \v!none
1176        \letlistparameter\c!aligntitle \v!yes
1177        \letlistparameter\c!numbercommand\firstofoneargument % for the moment, no doubling needed
1178    \else
1179        \letlistparameter\c!headnumber\v!always
1180    \fi\fi
1181    \let\currentlistmethod\s!btx
1182\to \everysetupbtxlistplacement
1183
1184\unexpanded\def\btxremapauthor
1185  {\dodoubleargument\btx_remap_author}
1186
1187\def\btx_remap_author[#1][#2]%
1188  {\clf_btxremapauthor{#1}{#2}}
1189
1190\unexpanded\def\btxshowauthorremapping
1191  {\clf_btxshowauthorremapping}
1192
1193\unexpanded\def\btxflushauthor
1194  {\doifelsenextoptionalcs\btx_flush_author_yes\btx_flush_author_nop}
1195
1196\unexpanded\def\btxflushsuffix
1197  {\ifx\currentbtxsuffix\empty
1198     % nothing
1199   \else
1200     \characters{\currentbtxsuffix}% todo : rendering specific converter
1201   \fi}
1202
1203\def\btx_flush_author_yes[#1]{\btx_flush_author{#1}}
1204\def\btx_flush_author_nop    {\btx_flush_author{\btxparameter\c!authorconversion}}
1205
1206\unexpanded\def\btx_flush_author#1#2%
1207  {\begingroup
1208   \edef\currentbtxfield{#2}%
1209   \setbtxparameterset\s!list\currentbtxfield
1210% \let\currentbtxlistvariant\currentbtxfield
1211   \clf_btxauthor
1212        {\currentbtxdataset}%
1213        {\currentbtxtag}%
1214        {\currentbtxfield}%
1215        {%
1216            combiner    {#1}%
1217            kind        {list}%
1218            etallimit   {\btxparameter\c!etallimit}%
1219            etaldisplay {\btxparameter\c!etaldisplay}%
1220            etaloption  {\btxparameter\c!etaloption}%
1221            symbol      {\btxparameter{\c!stopper:initials}}%
1222            connector   {\btxparameter{\c!connector:initials}}%
1223        }%
1224   \relax
1225   \endgroup}
1226
1227% yes or no: maybe just \flushauthor{...}{...}
1228
1229\unexpanded\def\btxflushauthorname         {\btx_flush_author{name}}          % #1
1230\unexpanded\def\btxflushauthornormal       {\btx_flush_author{normal}}        % #1
1231\unexpanded\def\btxflushauthornormalshort  {\btx_flush_author{normalshort}}   % #1
1232\unexpanded\def\btxflushauthorinverted     {\btx_flush_author{inverted}}      % #1
1233\unexpanded\def\btxflushauthorinvertedshort{\btx_flush_author{invertedshort}} % #1
1234
1235\let\currentbtxauthorfield\s!author
1236
1237\unexpanded\def\btxsetauthorfield#1{\edef\currentbtxauthorfield{#1}}
1238
1239\unexpanded\def\currentbtxciteauthorbyfield
1240  {\begingroup
1241   %\setbtxparameterset\s!cite\s!author
1242   % the alternatives inherit from cite:author
1243   % and APA distinguishes authoryears from authoryear ("and" vs. "&")
1244   \setbtxparameterset\s!cite\currentbtxcitealternative
1245   \clf_btxauthor
1246        {\currentbtxdataset}%
1247        {\currentbtxtag}%
1248        {\currentbtxauthorfield}%
1249        {%
1250            combiner    {\btxparameter\c!authorconversion}%
1251            kind        {cite}%
1252            etallimit   {\btxparameter\c!etallimit}%
1253            etaldisplay {\btxparameter\c!etaldisplay}%
1254            etaloption  {\btxparameter\c!etaloption}%
1255            symbol      {\btxparameter{\c!stopper:initials}}%
1256        }%
1257   \relax
1258   \endgroup}
1259
1260\unexpanded\def\currentbtxciteauthor
1261  {\let\currentbtxauthorfield\s!author
1262   \currentbtxciteauthorbyfield} % always author
1263
1264\unexpanded\def\btxstartauthor#1#2#3% a state > 0 signals that some authors can clash
1265  {\begingroup
1266   \currentbtxauthorindex#1\relax
1267   \currentbtxauthorcount#2\relax
1268   \currentbtxauthorstate#3\relax}
1269
1270\unexpanded\def\btxstopauthor
1271  {\endgroup}
1272
1273\unexpanded\def\btxciteauthorsetup#1{\fastsetup{\s!btx:\s!cite:\s!author:#1}}
1274\unexpanded\def\btxlistauthorsetup#1{\fastsetup{\s!btx:\s!list:\s!author:#1}}
1275
1276% \btxflushauthor{author}
1277% \btxflushauthor{editor}
1278%
1279% \btxflushauthor[name]{author}
1280% \btxflushauthor[normal]{author}
1281% \btxflushauthor[normalshort]{author}
1282% \btxflushauthor[inverted]{author}
1283% \btxflushauthor[invertedshort]{author}
1284
1285% \btxflushauthor{author}
1286% \btxflushauthor{editor}
1287
1288% Interaction
1289%
1290% Because we have more complex entries in lists we don't use the normal list
1291% interaction features.
1292
1293\newconditional\btxinteractive
1294\newconditional\btxinteractivenumber
1295\newconditional\btxinteractivetext
1296\newconditional\btxinteractivepage
1297
1298\let\currentbtxinteraction\empty
1299
1300\installcorenamespace{btxinteraction}
1301
1302\setvalue{\??btxinteraction\v!number}{\settrue\btxinteractivenumber}
1303\setvalue{\??btxinteraction\v!text  }{\settrue\btxinteractivetext}
1304\setvalue{\??btxinteraction\v!page  }{\settrue\btxinteractivepage}
1305\setvalue{\??btxinteraction\v!all   }{\settrue\btxinteractivenumber
1306                                      \settrue\btxinteractivetext
1307                                      \settrue\btxinteractivepage}
1308
1309% \setupbtx[interaction=page] % or text or number or all
1310% \setupbtxrendering[pagestate=start]
1311
1312\appendtoks
1313    \iflocation
1314        \edef\currentbtxinteraction{\btxparameter\c!interaction}%
1315        \ifx\currentbtxinteraction\v!stop
1316            \setfalse\btxinteractive
1317        \else
1318            \let\structurelistlocation\empty
1319            \settrue\btxinteractive
1320            \begincsname\??btxinteraction\currentbtxinteraction\endcsname
1321        \fi
1322    \else
1323        \setfalse\btxinteractive
1324    \fi
1325\to \everysetupbtxlistplacement
1326
1327\appendtoks
1328    \iflocation
1329        \edef\currentbtxinteraction{\btxparameter\c!interaction}%
1330        \ifx\currentbtxinteraction\v!stop
1331            \setfalse\btxinteractive
1332        \else
1333            \settrue\btxinteractive
1334        \fi
1335    \else
1336        \setfalse\btxinteractive
1337    \fi
1338\to \everysetupbtxciteplacement
1339
1340%D When a publication is cited, we need to signal that somehow. This is done with the
1341%D following (not user) command. We could tag without injecting a node but this way
1342%D we also store the location, which makes it possible to ask local lists.
1343
1344%D \macros{cite,nocite,citation,nocitation,usecitation}
1345%D
1346%D The inline \type {\cite} command creates a (often) short reference to a publication
1347%D and for historic reasons uses a strict test for brackets. This means, at least
1348%D in the default case that spaces are ignored in the argument scanner. The \type
1349%D {\citation} commands is more liberal but also gobbles following spaces. Both
1350%D commands insert a reference as well as a visual clue.
1351%D
1352%D The \type {no} commands all do the same (they are synonyms): they make sure that
1353%D a reference is injected but show nothing. However, they do create a node so best
1354%D attach them to some text in order to avoid spacing interferences. A slightly
1355%D less efficient alternative is \type {\cite[none][tag]}.
1356
1357% [tags]
1358% [settings|variant][tags]
1359% [base::tags]
1360% [settings|variant][base::tags]
1361
1362% these need to be sort of protected:
1363
1364% methods:
1365%
1366% hidden : mark for list, don't show in text
1367% list   : mark for list, show in text only when in list
1368% text   : not to list, show in text
1369% always : mark for list, show in text
1370
1371\let\p_publ_cite_before   \empty
1372\let\p_publ_cite_after    \empty
1373\let\p_publ_cite_lefttext \empty
1374\let\p_publ_cite_righttext\empty
1375
1376\let\currentbtxciteuservariables\empty
1377\let\currentbtxcitealternative  \empty
1378
1379\unexpanded\def\btxhybridcite % so one can alias the old
1380  {\dontleavehmode
1381   \begingroup
1382   \strictdoifelsenextoptional\publ_cite_tags_options\publ_cite_tags_indeed}
1383
1384\unexpanded\def\publ_cite_tags_options[#1]%
1385  {\strictdoifelsenextoptional{\publ_cite_tags_options_indeed{#1}}{\publ_cite_tags_indeed{#1}}}
1386
1387\unexpanded\def\publ_cite_tags_indeed#1%
1388  {\letinteractionparameter\c!style\empty
1389   \setbtxparametersetroot\s!cite % we need to get the default
1390   \edef\currentbtxcitealternative{\btxparameter\c!alternative}%
1391   \setbtxparameterset\s!cite\currentbtxcitealternative
1392   \edef\currentbtxcitetag{#1}%
1393   \the\everysetupbtxciteplacement
1394   \publ_cite_variant
1395   \endgroup}
1396
1397\unexpanded\def\publ_cite_tags_options_indeed#1%
1398  {\doifelseassignment{#1}\publ_cite_tags_settings_indeed\publ_cite_tags_variants_indeed{#1}}
1399
1400\def\publ_cite_tags_settings_indeed#1[#2]%
1401  {\letinteractionparameter\c!style\empty
1402  %\letinteractionparameter\c!color\empty
1403   \letdummyparameter\c!reference  \empty
1404   \letdummyparameter\c!alternative\empty
1405   \letdummyparameter\c!before     \empty
1406   \letdummyparameter\c!after      \empty
1407   \letdummyparameter\c!lefttext   \empty
1408   \letdummyparameter\c!righttext  \empty
1409   \getdummyparameters[#1]%
1410   \edef\p_reference{\dummyparameter\c!reference}%
1411   \ifx\p_reference\empty
1412      \edef\currentbtxcitetag{#2}%
1413   \else
1414      \let\currentbtxcitetag\p_reference
1415      \edef\currentbtxciteuservariables{#2}%
1416   \fi
1417   \edef\p_specification{\dummyparameter\c!specification}%
1418   \ifx\p_specification\empty
1419   \else
1420     \let\currentbtxspecification\p_specification
1421   \fi
1422   \edef\p_alternative{\dummyparameter\c!alternative}%
1423   \ifx\p_alternative\empty
1424     \setbtxparametersetroot\s!cite
1425     \edef\currentbtxcitealternative{\btxparameter\c!alternative}%
1426   \else
1427     \let\currentbtxcitealternative\p_alternative
1428   \fi
1429   \setbtxparameterset\s!cite\currentbtxcitealternative
1430   \setupcurrentbtx[#1]%
1431   %
1432   \edef\p_publ_cite_before   {\dummyparameter\c!before}%
1433   \edef\p_publ_cite_after    {\dummyparameter\c!after}%
1434   \edef\p_publ_cite_lefttext {\dummyparameter\c!lefttext}%
1435   \edef\p_publ_cite_righttext{\dummyparameter\c!righttext}%
1436   %
1437   \the\everysetupbtxciteplacement
1438   \publ_cite_variant
1439   \endgroup}
1440
1441\def\publ_cite_tags_variants_indeed#1[#2]%
1442  {\letinteractionparameter\c!style\empty
1443   \edef\currentbtxcitealternative{#1}%
1444   \edef\currentbtxcitetag{#2}%
1445   \setbtxparameterset\s!cite\currentbtxcitealternative
1446   \the\everysetupbtxciteplacement
1447   \publ_cite_variant
1448   \endgroup}
1449
1450\newconditional\btxcitecompress
1451
1452\let\currentbtxreference\empty
1453\let\currentbtxcitemethod\v!hidden
1454
1455\def\publ_cite_variant
1456  {\begingroup
1457   \publ_cite_handle_variant_indeed[\currentbtxcitetag]}
1458
1459\unexpanded\def\publ_cite_handle_variant#1%
1460  {\begingroup
1461   \edef\currentbtxcitealternative{#1}%
1462   \setbtxparameterset\s!cite\currentbtxcitealternative
1463   \the\everysetupbtxciteplacement
1464   \dosingleargument\publ_cite_handle_variant_indeed}
1465
1466\unexpanded\def\publ_cite_handle_variant_blob
1467  {\clf_btxhandlecite
1468     dataset          {\currentbtxdataset}%
1469     reference        {\currentbtxreference}%
1470     method           {\currentbtxcitemethod}%
1471     variant          {\currentbtxcitealternative}%
1472     sorttype         {\btxparameter\c!sorttype}%
1473     compress         {\btxparameter\c!compress}%
1474     author           {\btxparameter\c!author}%
1475     authorconversion {\c!authorconversion}%
1476     lefttext         {\p_publ_cite_lefttext}%
1477     righttext        {\p_publ_cite_righttext}%
1478     before           {\p_publ_cite_before}%
1479     after            {\p_publ_cite_after}%
1480   \relax
1481   \iftrialtypesetting\else
1482    %\clf_btxflushmarked
1483   \fi}
1484
1485\let\dobtxcitevariantblob\publ_cite_handle_variant_blob % command can use it via lua
1486
1487\def\publ_cite_handle_variant_indeed[#1]%
1488  {\letbtxparameter\c!alternative\currentbtxcitealternative
1489   \edef\currentbtxreference{#1}%
1490   \saverunningstyleandcolor
1491   \usebtxstyleandcolor\c!style\c!color
1492   \uselanguageparameter\btxdatasetparameter % new
1493   \btxparameter\c!left
1494   \btxparameter\c!command{\dobtxcitevariantblob}% {\publ_cite_handle_variant_blob}%
1495   \btxparameter\c!right
1496   \endgroup}
1497
1498\unexpanded\def\btxlistcitation
1499  {\dontleavehmode
1500   \begingroup
1501   \let\currentbtxcitemethod\v!list
1502   \dodoubleempty\publ_citation}
1503
1504\unexpanded\def\btxtextcitation
1505  {\dontleavehmode
1506   \begingroup
1507   \let\btxcitereference\relax % a bit of a hack but ok
1508   \let\currentbtxcitemethod\v!text
1509   \dodoubleempty\publ_citation}
1510
1511\unexpanded\def\btxalwayscitation
1512  {\dontleavehmode
1513   \begingroup
1514   \let\currentbtxcitemethod\v!always
1515   \dodoubleempty\publ_citation}
1516
1517\def\publ_citation[#1][#2]% could be made more efficient but not now
1518  {\ifsecondargument
1519     \publ_cite_tags_options_indeed{#1}[#2]%
1520   \else
1521     \publ_cite_tags_indeed{#1}%
1522   \fi}
1523
1524\unexpanded\def\btxhiddencitation
1525  {\dosingleempty\publ_cite_hidden}
1526
1527\unexpanded\def\publ_cite_hidden[#1]%
1528  {\iftrialtypesetting \else
1529     \begingroup
1530     \let\currentbtxcitemethod\v!hidden
1531     \edef\currentbtxreference{#1}%
1532     \clf_btxhandlenocite
1533       method    {\currentbtxcitemethod}%
1534       dataset   {\currentbtxdataset}%
1535       reference {\currentbtxreference}%
1536     \relax
1537    %\clf_btxflushmarked
1538     \endgroup
1539   \fi}
1540
1541\unexpanded\def\btxmissing#1%
1542  {\dontleavehmode{\tttf<#1>}}
1543
1544%D Compatibility:
1545
1546\let\hiddencitation\btxhiddencitation  \let\hiddencite\hiddencitation
1547\let\listcitation  \btxlistcitation    \let\listcite  \listcitation
1548\let\textcitation  \btxtextcitation    \let\textcite  \textcitation
1549\let\alwayscitation\btxalwayscitation  \let\alwayscite\alwayscitation
1550
1551\unexpanded\def\citation  {\doifelsenextoptionalcs\btxlistcitation  \btxdirectlistcite}
1552\unexpanded\def\nocitation{\doifelsenextoptionalcs\btxhiddencitation\btxdirecthiddencite}
1553
1554\let\cite       \citation
1555\let\nocite     \nocitation
1556\let\usecitation\nocitation
1557
1558\unexpanded\def\publ_entry_citation  {\doifelsenextoptionalcs\btxlistcitation  \btxdirectlistcite}
1559\unexpanded\def\publ_entry_nocitation{\doifelsenextoptionalcs\btxhiddencitation\btxdirecthiddencite}
1560
1561\appendtoks
1562    \let\cite  \publ_entry_citation
1563    \let\nocite\publ_entry_nocitation
1564\to \everybtxlistrendering
1565
1566\unexpanded\def\btxdirectlistcite  #1{\btxlistcitation  [#1]\relax} % no optional arguments
1567\unexpanded\def\btxdirecthiddencite#1{\btxhiddencitation[#1]\relax} % no optional arguments
1568
1569%D Setup helpers, beware, we need to wrap this .. now we need to know
1570%D how setups are implemented.
1571
1572\setvalue{\??setup:\s!btx:\s!unknown}#1{\inframed{\tttf#1}}
1573
1574\def\publ_fast_setup_yes#1#2%
1575  {\csname\??setup:\s!btx:%
1576     \ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname
1577        \currentbtxspecification:#1:#2%
1578     \else\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:#2\endcsname
1579        \currentbtxspecificationfallback:#1:#2%
1580     \else\ifcsname\??setup:\s!btx:#1:#2\endcsname
1581        #1:#2%
1582     \else\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname
1583        \currentbtxspecification:#1:\s!unknown
1584     \else\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:\s!unknown\endcsname
1585        \currentbtxspecificationfallback:#1:\s!unknown
1586     \else
1587        #1:\s!unknown
1588     \fi\fi\fi\fi\fi
1589   \endcsname{#2}}
1590
1591\def\publ_fast_setup_nop#1#2%
1592  {\csname\??setup:\s!btx:%
1593     \ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname
1594        \currentbtxspecification:#1:#2%
1595     \else\ifcsname\??setup:\s!btx:#1:#2\endcsname
1596        #1:#2%
1597     \else\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname
1598        \currentbtxspecification:#1:\s!unknown
1599     \else
1600        #1:\s!unknown
1601     \fi\fi\fi
1602   \endcsname{#2}}
1603
1604\newconstant\btxsetuptype
1605
1606% 0 = unknown   darkred
1607% 1 = cite      darkblue
1608% 2 = subcite   darkgreen
1609% 3 = numbering darkorange
1610% 4 = list      darkcyan
1611% 5 = page      darkmagenta
1612% 6 = unknown   darkred
1613
1614\unexpanded\def\publ_fast_btx_setup_chain_inbetween
1615  {\allowbreak->\allowbreak}
1616
1617\unexpanded\def\publ_fast_btx_setup_colon_inbetween
1618  {\allowbreak:\allowbreak}
1619
1620\unexpanded\def\publ_fast_btx_setup_chain_yes#1#2%
1621  {\dontleavehmode\begingroup
1622   \let\:\publ_fast_btx_setup_colon_inbetween
1623   \infofont
1624   \ifcase\btxsetuptype\darkred\or\darkblue\or\darkgreen\or\darkcyan\or\darkmagenta\else\darkred\fi
1625   [\prewordbreak
1626   \currentbtxspecification        \:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname\else
1627   \publ_fast_btx_setup_chain_inbetween
1628   \currentbtxspecificationfallback\:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:#2\endcsname\else
1629   \publ_fast_btx_setup_chain_inbetween
1630                                     #1\:#2\ifcsname\??setup:\s!btx:#1:#2\endcsname\else
1631   \publ_fast_btx_setup_chain_inbetween
1632   \currentbtxspecification        \:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname\else
1633   \publ_fast_btx_setup_chain_inbetween
1634   \currentbtxspecificationfallback\:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:\s!unknown\endcsname\else
1635   \publ_fast_btx_setup_chain_inbetween
1636   unset\fi\fi\fi\fi\fi
1637   \space @\space
1638   \currentbtx
1639   \prewordbreak]%
1640   \endgroup}
1641
1642\unexpanded\def\publ_fast_btx_setup_chain_nop#1#2%
1643  {\dontleavehmode\begingroup
1644   \let\:\publ_fast_btx_setup_colon_inbetween
1645   \infofont
1646   \darkred
1647   [\prewordbreak
1648   \currentbtxspecification\:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname\else
1649   \publ_fast_btx_setup_chain_inbetween
1650                             #1\:#2\ifcsname\??setup:\s!btx:#1:#2\endcsname\else
1651   \publ_fast_btx_setup_chain_inbetween
1652   \currentbtxspecification\:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname\else
1653   \publ_fast_btx_setup_chain_inbetween
1654   unset\fi\fi\fi
1655   \space @\space
1656   \currentbtx
1657   \prewordbreak]%
1658   \endgroup}
1659
1660\unexpanded\def\publ_fast_btx_setup_normal#1%
1661  {\btxsetuptype#1\relax
1662   \ifx\currentbtxspecificationfallback\empty
1663     \expandafter\publ_fast_setup_nop
1664   \else
1665     \expandafter\publ_fast_setup_yes
1666   \fi}
1667
1668\unexpanded\def\publ_fast_btx_setup_visual#1#2#3%
1669  {\btxsetuptype#1\relax
1670   \ifx\currentbtxspecificationfallback\empty
1671     \expandafter\publ_fast_btx_setup_chain_nop
1672   \else
1673     \expandafter\publ_fast_btx_setup_chain_yes
1674   \fi{#2}{#3}%
1675   \ifx\currentbtxspecificationfallback\empty
1676     \expandafter\publ_fast_setup_nop
1677   \else
1678     \expandafter\publ_fast_setup_yes
1679   \fi{#2}{#3}}
1680
1681\installtextracker
1682  {publications.setups}
1683  {\let\publ_fast_setup\publ_fast_btx_setup_visual}
1684  {\let\publ_fast_setup\publ_fast_btx_setup_normal}
1685
1686\let\publ_fast_setup\publ_fast_btx_setup_normal
1687
1688%D Cite helpers:
1689
1690\newtoks\everybtxciteentry
1691
1692\prependtoks
1693     \setfalse\c_btx_cite_reference_injected
1694\to \everybtxciteentry
1695
1696\unexpanded\def\btxcitesetup#1%
1697  {\the\everybtxciteentry
1698   \everybtxciteentry\emptytoks % tricky maybe not when subcites
1699   \publ_fast_setup\plusone\s!cite{#1}}    % no \btxcitereset as we loose dataset and such
1700
1701\unexpanded\def\btxsubcitesetup#1%
1702  {\the\everybtxciteentry
1703   \everybtxciteentry\emptytoks % tricky maybe not when subcites
1704   \publ_fast_setup\plustwo\s!cite{#1}}    % no \btxcitereset as we loose dataset and such
1705
1706\appendtoks
1707    \btx_check_language
1708\to \everybtxciteentry
1709
1710\unexpanded\def\btxstartsubcite#1%
1711  {\begingroup
1712   \btx_reset_cite % todo: limited set
1713 % \saverunningstyleandcolor % let's see when Alan needs it
1714   \def\currentbtxcitealternative{#1}%
1715   \setbtxparameterset\s!cite\currentbtxcitealternative
1716   \usebtxstyleandcolor\c!style\c!color
1717   \btxparameter\c!left
1718   \relax}
1719
1720\unexpanded\def\btxstopsubcite
1721  {\relax
1722   \btxparameter\c!right
1723   \endgroup}
1724
1725\unexpanded\def\btxstartciterendering[#1]%
1726  {\begingroup
1727   \edef\currentbtxcitealternative{#1}%
1728   \setbtxparameterset\s!cite\currentbtxcitealternative
1729   \usebtxstyleandcolor\c!style\c!color
1730   \btxparameter\c!left
1731   \relax}
1732
1733\unexpanded\def\btxstopciterendering
1734  {\relax
1735   \btxparameter\c!right
1736   \endgroup}
1737
1738\let\btxstartciteauthor\begingroup
1739\let\btxstopciteauthor \endgroup
1740
1741\unexpanded\def\btxstartcite{\begingroup\btx_reset_cite}
1742           \let\btxstopcite  \endgroup
1743
1744%D Whatever helpers:
1745
1746\unexpanded\def\btxsingularplural#1{\clf_btxsingularorplural{\currentbtxdataset}{\currentbtxtag}{#1}}
1747\unexpanded\def\btxoneorrange    #1{\clf_btxoneorrange      {\currentbtxdataset}{\currentbtxtag}{#1}}
1748\unexpanded\def\btxfirstofrange  #1{\clf_btxfirstofrange    {\currentbtxdataset}{\currentbtxtag}{#1}}
1749
1750\let\btxsingularorplural\btxsingularplural
1751
1752\stopcontextdefinitioncode
1753
1754%D Journals
1755
1756\unexpanded\def\btxloadjournallist [#1]{\clf_btxloadjournallist{#1}}
1757\unexpanded\def\btxsavejournallist [#1]{\clf_btxsavejournallist{#1}}
1758\unexpanded\def\btxaddjournal  [#1][#2]{\clf_btxaddjournal{#1}{#2}}
1759           \def\btxexpandedjournal   #1{\clf_btxexpandedjournal{#1}}    % \unexpanded ?
1760           \def\btxabbreviatedjournal#1{\clf_btxabbreviatedjournal{#1}} % \unexpanded ?
1761
1762% \installcorenamespace{btxjournal}
1763%
1764% \letvalue{\s!btxjournal\v!long  }\btxexpandedjournal
1765% \letvalue{\s!btxjournal\v!short }\btxabbreviatedjournal
1766% \letvalue{\s!btxjournal\v!normal}\firstofoneargument
1767%
1768% \unexpanded\def\btxcheckedjournal
1769%   {\expandnamespaceparameter\s!btxjournal\btxrenderingparameter\c!journalconversion}
1770
1771% \btxloadjournallist[list.txt] % Foo Journal of Bars = FBJ \n ....
1772%
1773% \btxexpandedjournal[fbj]
1774% \btxabbreviatedjournal[foo journal of bars]
1775
1776%D Saving data:
1777
1778\unexpanded\def\savebtxdataset
1779  {\dotripleargument\publ_save_dataset}
1780
1781\unexpanded\def\publ_save_dataset[#1][#2][#3]%
1782  {\ifthirdargument
1783     \publ_save_dataset_indeed[#1][#2][#3]%
1784   \else\ifsecondargument
1785     \doifelseassignment{#2}%
1786       {\publ_save_dataset_indeed[\s!default][#1][#2]}%
1787       {\publ_save_dataset_indeed[#1][#2][]}%
1788   \else\iffirstargument
1789     \doifelseassignment{#1}%
1790       {\publ_save_dataset_indeed[\s!default][\jobname-saved.bib][#1]}%
1791       {\publ_save_dataset_indeed[\s!default][#1][]}%
1792 % \else
1793 %   % bad news
1794   \fi\fi\fi}
1795
1796\unexpanded\def\publ_save_dataset_indeed[#1][#2][#3]%
1797  {\begingroup
1798   \getdummyparameters
1799     [\c!criterium=\v!all,%
1800      \c!type=,%
1801      \c!dataset=#1,%
1802      \c!file=#2,%
1803      #3]% % all or used
1804   \clf_btxsavedataset
1805     dataset   {\dummyparameter\c!dataset}%
1806     filename  {\dummyparameter\c!file}%
1807     filetype  {\dummyparameter\c!type}%
1808     criterium {\dummyparameter\c!criterium}%
1809   \relax
1810   \endgroup}
1811
1812% \savebtxdataset[default][e:/tmp/foo.bib]
1813% \savebtxdataset[default][e:/tmp/foo.lua]
1814% \savebtxdataset[default][e:/tmp/foo.xml]
1815
1816%D In-text entries:
1817
1818\unexpanded\def\placecitation{\citation[entry]} % [#1]
1819
1820\unexpanded\def\btxhandleciteentry
1821  {\dontleavehmode
1822   \begingroup
1823   \def\currentbtxcitealternative{entry}%
1824   \setbtxparameterset\s!cite\currentbtxcitealternative % needs checking
1825   \btxcitereference
1826   \btx_entry_inject
1827   \endgroup}
1828
1829%D Registers
1830
1831% \setupbtxregister
1832%   [\c!state=\v!start,
1833%    \c!dataset=\v!all,
1834%    \c!method=\v!always]
1835
1836\unexpanded\def\publ_registers_set
1837  {\ifx\currentbtxregister\empty \else
1838     \clf_btxsetregister
1839        specification {\currentbtxspecification}%
1840        name          {\currentbtxregister}%
1841        state         {\btxregisterparameter\c!state}%
1842        dataset       {\btxregisterparameter\c!dataset}%
1843        field         {\btxregisterparameter\c!field}%
1844        register      {\btxregisterparameter\c!register}%
1845        method        {\btxregisterparameter\c!method}%
1846        alternative   {\btxregisterparameter\c!alternative}%
1847     \relax
1848  \fi}
1849
1850\appendtoks
1851    \publ_registers_set
1852\to \everydefinebtxregister
1853
1854\appendtoks
1855    \publ_registers_set
1856\to \everysetupbtxregister
1857
1858\appendtoks
1859    \normalexpanded{%
1860      \defineprocessor
1861        [\s!btx:r:\currentbtxregister]%
1862        [\c!style=\noexpand\namedbtxregisterparameter{\currentbtxregister}\noexpand\c!style,
1863         \c!color=\noexpand\namedbtxregisterparameter{\currentbtxregister}\noexpand\c!color]}%
1864\to \everydefinebtxregister
1865
1866\appendtoks
1867    \clf_btxtoregister{\currentbtxdataset}{\currentbtxtag}%
1868\to \t_btx_reference_inject
1869
1870\unexpanded\def\btxindexedauthor#1#2#3#4#5#6% alternative von last initials first junior
1871  {\begingroup
1872   \def\currentbtxcitealternative{#1}%
1873   \ifx\currentbtxcitealternative\empty
1874      \edef\currentbtxcitealternative{invertedshort}% maybe we need some default here too?
1875   \fi
1876   %let\currentbtxlistvariant\currentbtxcitealternative % we inherit
1877   \the\everysetupbtxciteplacement
1878   \def\currentbtxvons       {#2}%
1879   \def\currentbtxsurnames   {#3}%
1880   \def\currentbtxinitials   {#4}%
1881   \def\currentbtxfirstnames {#5}%
1882   \def\currentbtxjuniors    {#6}%
1883   \setbtxparameterset\s!cite\currentbtxcitealternative
1884   \fastsetup{\s!btx:\s!cite:\s!author:\currentbtxcitealternative}%
1885   \endgroup}
1886
1887\unexpanded\def\btxregisterauthor
1888  {\doifelsenextoptionalcs\publ_register_author_yes\publ_register_author_nop}
1889
1890\def\publ_register_author_yes[#1]#2%
1891  {\clf_btxauthortoregister{#1}{#2}\relax}
1892
1893\def\publ_register_author_nop#1%
1894  {\clf_btxauthortoregister{\currentbtxdataset}{#1}\relax}
1895
1896
1897%D We hook some setters in the definition sets:
1898
1899% \installdefinitionsetmember \??btx {btxspecification} \??btxcitevariant {btxcitevariant}
1900% \installdefinitionsetmember \??btx {btxspecification} \??btxlistvariant {btxlistvariant}
1901% \installdefinitionsetmember \??btx {btxspecification} \??btxlist        {btxlist}
1902% \installdefinitionsetmember \??btx {btxspecification} \??btxrendering   {btxrendering}
1903% \installdefinitionsetmember \??btx {btxspecification} \??btx            {btx}
1904
1905%D And more helpers ... a never ending story these publications:
1906
1907% \definebtx
1908%   [btx:apa:list:article:title]
1909%   [style=bolditalic,
1910%    command=\WORD]
1911%
1912% \btxstartstyle[btx:apa:list:article:title]
1913%     \btxusecommand[btx:apa:list:article:title]{foo}
1914% \btxstopstyle
1915
1916\let\savedcurrentbtx\empty
1917
1918\unexpanded\def\btxstartstyle[#1]%
1919  {\begingroup
1920   \let\savedcurrentbtx\currentbtx
1921   \def\currentbtx{#1}%
1922   \usebtxstyle\c!style
1923   \let\currentbtx\savedcurrentbtx}
1924
1925\unexpanded\def\btxstartcolor[#1]%
1926  {\begingroup
1927   \let\savedcurrentbtx\currentbtx
1928   \def\currentbtx{#1}%
1929   \usebtxcolor\c!color
1930   \let\currentbtx\savedcurrentbtx}
1931
1932\unexpanded\def\btxstartstyleandcolor[#1]%
1933  {\begingroup
1934   \let\savedcurrentbtx\currentbtx
1935   \def\currentbtx{#1}%
1936   \usebtxstyleandcolor\c!style\c!color
1937   \let\currentbtx\savedcurrentbtx}
1938
1939\let\btxstopstyle        \endgroup
1940\let\btxstopcolor        \endgroup
1941\let\btxstopstyleandcolor\endgroup
1942
1943\unexpanded\def\btxusecommand[#1]#2% using #2 permits space after []
1944  {\namedbtxparameter{#1}\c!command{#2}}
1945
1946\unexpanded\def\startbtxrunningstyleandcolor
1947  {\dontleavehmode
1948   \begingroup
1949   \restorerunningstyleandcolor}
1950
1951\unexpanded\def\stopbtxrunningstyleandcolor
1952  {\endgroup}
1953
1954%D Maybe handy:
1955
1956\unexpanded\def\btxdoifelsematches#1#2#3%
1957  {\clf_btxdoifelsematches{#1}{#2}{#3}}
1958
1959%D Defaults:
1960
1961\setupbtxrendering
1962  [\c!interaction=\v!start, % \v!all
1963   \c!specification=\btxparameter\c!specification,
1964   \c!dataset=\v!default,
1965   \c!repeat=\v!no,
1966   \c!continue=\v!no,
1967   \c!method=\v!global,
1968 % \c!setups=btx:\btxrenderingparameter\c!alternative:initialize, % not the same usage as cite !
1969   \c!sorttype=\v!default,
1970   \c!criterium=\v!text,
1971   \c!refcommand=authoryears,  % todo
1972   \c!numbering=\v!yes,
1973  %\c!saveinlist=\v!no, % maybe for before/after
1974   \c!pagestate=\v!stop,
1975   \c!textstate=\v!start,
1976   \c!width=\v!auto,
1977   \c!separator={\removepunctuation;\space},
1978   \c!distance=1.5\emwidth]
1979
1980% Quite some interpunction and labels are the same of at least consistent within
1981% a standard when citations and list entries are involved. We assume that each
1982% standard defines its own set but it can fall back on these defaults.
1983
1984\setupbtx
1985  [\c!interaction=\v!start,
1986   \c!alternative=num, % default cite form, normally defined in the cite namespace
1987   \c!inbetween=\btxspace,
1988 % \c!range=\endash,   % separator:range?
1989   \c!range=\directdiscretionary\endash,
1990   \c!compress=\v!yes, % was no?
1991   \c!authorconversion=normal,
1992   \c!sorttype=normal, % normal, reverse or none
1993   \c!etallimit=3,
1994   \c!etaldisplay=\btxparameter\c!etallimit,
1995   \c!otherstext={\btxspace et al.},
1996   \c!separator:firstnames={\btxspace},
1997   \c!separator:juniors={\btxspace},
1998   \c!separator:vons={\btxspace},
1999   \c!separator:initials={\btxspace},
2000   \c!stopper:initials={.},
2001  %\c!surnamesep={\btxcomma}, % is this used anywhere?
2002   \c!separator:invertedinitials={\btxcomma},
2003   \c!separator:invertedfirstnames={\btxcomma},
2004   \c!separator:names:2={\btxcomma}, % separates multiple names
2005   \c!separator:names:3=\btxparameter{\c!separator:2}, % before last name in a list
2006   \c!separator:names:4=\btxparameter{\c!separator:2}, % between only two names
2007   \c!separator:2={\btxsemicolon}, % aka pubsep - separates multiple objects
2008   \c!separator:3=\btxparameter{separator:2}, % before last object in a list
2009   \c!separator:4=\btxparameter{separator:2}] % between only two objects
2010
2011% Do we want these in the format? Loading them delayed is somewhat messy.
2012
2013\loadbtxdefinitionfile[commands]
2014\loadbtxdefinitionfile[definitions]
2015
2016\loadbtxdefinitionfile[cite]
2017\loadbtxdefinitionfile[list]
2018\loadbtxdefinitionfile[page]
2019\loadbtxdefinitionfile[author]
2020
2021% we assume that the users sets up the right specification and if not ... well,
2022% hope for the best that something shows up and consult the manual otherwise
2023
2024\unexpanded\def\usebtxdefinitions[#1]%
2025  {\loadbtxdefinitionfile[#1]%     % for hh
2026   \setupbtx[\c!specification=#1]} % for ab
2027
2028\setupbtx
2029  [\c!specification=\s!default,
2030   \c!dataset=\v!default,
2031   \c!default=\v!default]
2032
2033\loadbtxdefinitionfile
2034  [\s!default]
2035
2036%D Delayed loading:
2037
2038\fetchruntimecommand \showbtxdatasetfields       \f!publ_tra
2039\fetchruntimecommand \showbtxdatasetcompleteness \f!publ_tra
2040\fetchruntimecommand \showbtxdatasetauthors      \f!publ_tra
2041\fetchruntimecommand \showbtxhashedauthors       \f!publ_tra
2042\fetchruntimecommand \showbtxfields              \f!publ_tra
2043\fetchruntimecommand \showbtxtables              \f!publ_tra
2044
2045%D Some potential crap:
2046%D
2047%D Because I consider this bad data management and a weird mix of languages only one
2048%D accessor is provided.
2049
2050\unexpanded\def\btxshortcut
2051  {\dosingleempty\publ_shortcut}
2052
2053\def\publ_shortcut[#1]#2%
2054  {\clf_btxshortcut{\iffirstargument#1\else\s!default\fi}{#2}}
2055
2056\protect
2057