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