publ-ini.mkxl /size: 73 Kb    last modification: 2025-02-21 11:03
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{\currentbtxauthorindex}}
481\protected\def\currentbtxinitials_indeed  {\clf_btxcurrentinitials  {\currentbtxauthorindex}}
482\protected\def\currentbtxjuniors_indeed   {\clf_btxcurrentjuniors   {\currentbtxauthorindex}}
483\protected\def\currentbtxsurnames_indeed  {\clf_btxcurrentsurnames  {\currentbtxauthorindex}}
484\protected\def\currentbtxvons_indeed      {\clf_btxcurrentvons      {\currentbtxauthorindex}}
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   \dostarttaggednodetail\t!listtag
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   \dostarttaggednodetail\t!publication
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  %\dostarttaggednodetail\t!listcontent
722   \btx_entry_inject_list_text
723  %\dostoptagged
724   \ifconditional\c_btx_list_pages
725     \dostarttaggednodetail\t!listpage
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        \resetinteractionstyle
789       %\resetinteractioncolor
790    \fi
791\to \everybtxlistrendering
792
793\mutable\let\nofbtxlistentries  \!!zerocount
794\mutable\let\currentbtxlistentry\!!zerocount
795\mutable\let\currentbtxlistindex\!!zerocount % only for internal use (points back to big list)
796
797\newconditional\c_publ_prefixed
798
799\permanent\protected\def\btxsetnoflistentries  #1{\edef\nofbtxlistentries  {#1}}
800\permanent\protected\def\btxsetcurrentlistentry#1{\edef\currentbtxlistentry{#1}}
801\permanent\protected\def\btxsetcurrentlistindex#1{\edef\currentbtxlistindex{#1}}
802
803\permanent\protected\def\btxdoifelsesameaspreviouschecked#1#2% #1 == always | doublesided
804  {\clf_btxdoifelsesameasprevious
805     {\currentbtxdataset}%
806     \currentbtxlistentry%
807     {#2}%
808     \c_btx_list_reference
809     {#1}}
810
811\permanent\protected\def\btxdoifelsesameasprevious
812  {\btxdoifelsesameaspreviouschecked\v!doublesided}
813
814\permanent\protected\def\btxdoifelsecombiinlist#1#2%
815  {\clf_btxdoifelsecombiinlist{#1}{#2}}
816
817\permanent\protected\def\btxdoifelsecitedone#1#2%
818  {\clf_btxdoifelsecitedone{#1}{#2}}
819
820\aliased\let\btxdoifsameaspreviouscheckedelse\btxdoifelsesameaspreviouschecked
821\aliased\let\btxdoifsameaspreviouselse       \btxdoifelsesameasprevious
822\aliased\let\btxdoifcombiinlistelse          \btxdoifelsecombiinlist
823\aliased\let\btxdoifcitedoneelse             \btxdoifelsecitedone
824
825\tolerant\def\publ_place_list_indeed#1#2#*[#3]#*[#4]%
826  {\begingroup
827   \ifparameters\or\or
828     \let\currentbtxrendering\currentbtxspecification
829   \or
830     \ifhastok={#3}%
831       % [settings]
832       \let\currentbtxrendering\currentbtxspecification
833       \setupcurrentbtxrendering[#3]%
834       \edef\p_specification{\btxrenderingparameter\c!specification}%
835       \ifempty\p_specification\else
836         \let\currentbtxspecification\p_specification
837         \let\currentbtxrendering\currentbtxspecification % tricky
838       \fi
839     \else
840       \edef\currentbtxrendering{#3}%
841       \edef\p_specification{\btxrenderingparameter\c!specification}%
842       \ifempty\p_specification\else
843         \let\currentbtxspecification\p_specification
844       \fi
845     \fi
846   \or
847     % [rendering] [settings]
848     \edef\currentbtxrendering{#3}%
849     \setupcurrentbtxrendering[#4]%
850     \edef\p_specification{\btxrenderingparameter\c!specification}%
851     \ifempty\p_specification\else
852       \let\currentbtxspecification\p_specification
853     \fi
854   \fi
855   \setbtxparameterset\currentbtxspecification\s!list
856   \expand\everybtxlistrendering
857   \ifconditional#1\relax
858     \edef\currentbtxrenderingtitle{\btxrenderingparameter\c!title}%
859     \ifempty\currentbtxrenderingtitle
860       \normalexpanded{\startnamedsection[\v!chapter][\c!reference=\currentbtxrendering,\c!title={\headtext{\currentbtxrendering}}]}%
861     \else
862       \normalexpanded{\startnamedsection[\v!chapter][\c!reference=\currentbtxrendering,\c!title={\currentbtxrenderingtitle}]}%
863     \fi
864   \fi
865   \ifempty\currentbtxrendering
866     \setbtxrendering % hm
867   \fi
868   \edef\currentbtxdataset{\btxrenderingparameter\c!dataset}%
869   \uselanguageparameter\btxdatasetparameter % new
870   \setbtxlist
871   \expand\everystructurelist
872   \expand\everysetupbtxlistplacement
873   % why not pass this with collect .. todo
874   % here we just collect items
875   \clf_btxcollectlistentries
876       names     {\s!btx}%
877       criterium {\currentbtxcriterium}%
878       reference {\btxrenderingparameter\c!reference}%
879       method    {\btxrenderingparameter\c!method}%
880       dataset   {\currentbtxdataset}%
881       keyword   {\btxrenderingparameter\c!keyword}%
882       sorttype  {\btxrenderingparameter\c!sorttype}%
883       repeated  {\btxrenderingparameter\c!repeat}%
884       ignored   {\btxrenderingparameter\c!ignore}%
885       group     {\btxrenderingparameter\c!group}%
886       filter    {\btxrenderingparameter\c!filter}%
887       filename  {\btxrenderingparameter\c!file}% for now
888   \relax
889   \ifnum\nofbtxlistentries>\zerocount
890     \clf_btxpreparelistentries{\currentbtxdataset}% could be put in collect
891     \forgetall
892     \btxrenderingparameter\c!before
893     \ifconditional#2\relax
894       \edef\p_command{\btxrenderingparameter\c!command}%
895       \ifempty\p_command
896         \edef\p_setups{\btxrenderingparameter\c!setups}%
897         \ifempty\p_setups
898         \else
899           \directsetup{\p_setups}%
900         \fi
901       \else
902         \expandafter\p_command\expandafter{\number\nofbtxlistentries}\relax
903       \fi
904     \else
905       \dostarttagged\t!publications\currentbtxrendering
906       \dostarttagged\t!list{btx}%
907       \startpacked[\v!blank]%
908       % sorting and so
909       % next we analyze the width
910       \ifempty\currentbtxnumbering \else
911         \edef\p_width{\listparameter\c!width}%
912         \ifx\p_width\v!auto
913           \setbox\scratchbox\vbox \bgroup
914             \settrialtypesetting
915             \clf_btxfetchlistentries{\currentbtxdataset}%
916           \egroup
917           \d_publ_number_width\wd\scratchbox
918           \letlistparameter\c!width\d_publ_number_width % no need for _reference here, frozen
919         \fi
920       \fi
921       \ifcstok{\listparameter\c!prefix}\v!yes
922         \c_publ_prefixed\conditionaltrue
923       \else
924         \c_publ_prefixed\conditionalfalse
925       \fi
926       % this actually typesets them, we loop here as otherwise the whole
927       % bunch gets flushed at once
928       \dorecurse\nofbtxlistentries
929          {\let\currentbtxlistentry\recurselevel
930           \clf_btxflushlistentry{\currentbtxdataset}\currentbtxlistentry\relax}%
931       \stoppacked
932       \dostoptagged
933       \dostoptagged
934     \fi
935     \btxrenderingparameter\c!after
936   \fi
937   \ifconditional#1\relax
938     \stopnamedsection
939   \fi
940   \global\advanceby\btxblock\plusone
941   \endgroup}
942
943\permanent\protected\def\placebtxrendering      {\publ_place_list_indeed\conditionalfalse\conditionalfalse}
944\permanent\protected\def\completebtxrendering   {\publ_place_list_indeed\conditionaltrue \conditionalfalse}
945\permanent\protected\def\flushbtxrendering      {\publ_place_list_indeed\conditionalfalse\conditionaltrue }
946
947\aliased\let\completelistofpublications\completebtxrendering % for old times sake
948\aliased\let\placelistofpublications   \placebtxrendering    % for old times sake
949
950%D This is somewhat special (for Alan of course):
951%D
952%D \starttyping
953%D % #1 is number of entries
954%D
955%D \starttexdefinition mutable protected btx:for:alan:wrapper #1
956%D     \bTABLE
957%D         % we can have a command or setups
958%D         \flushbtxentries[command=\texdefinition{btx:for:alan:content}]
959%D     \eTABLE
960%D \stoptexdefinition
961%D
962%D % #1 is tag
963%D
964%D \starttexdefinition mutable protected btx:for:alan:content #1
965%D     \bTR
966%D         \bTD
967%D             \btxsettag{#1}
968%D             \btxfield{name}
969%D         \eTD
970%D     \eTR
971%D \stoptexdefinition
972%D
973%D % we can have a command or setups
974%D
975%D \flushbtxrendering [method=dataset,command=\texdefinition{btx:for:alan:wrapper}]
976%D \stoptyping
977%D
978%D Because we want to be ungrouped we use a special loop construct.
979
980\permanent\protected\def\btxsetlisttag#1%
981  {\clf_btxflushlisttag{\currentbtxdataset}#1\relax}
982
983\newinteger\c_btx_list_index
984
985\lettonothing\m_btx_list_action
986
987\def\publ_flush_list_step_command
988  {\btxsetlisttag{\c_btx_list_index}
989   \expandafter\m_btx_list_action\expandafter{\currentbtxtag}%
990   \ifnum\c_btx_list_index<\nofbtxlistentries
991     \advanceby\c_btx_list_index\plusone
992     \expandafter\publ_flush_list_step_command
993   \else
994     \glet\m_btx_list_action\relax
995   \fi}
996
997\def\publ_flush_list_step_setup
998  {\btxsetlisttag{\c_btx_list_index}
999   \directsetup{\m_btx_list_action}%
1000   \ifnum\c_btx_list_index<\nofbtxlistentries
1001     \advanceby\c_btx_list_index\plusone
1002     \expandafter\publ_flush_list_step_setup
1003   \else
1004     \glet\m_btx_list_action\relax
1005   \fi}
1006
1007\permanent\protected\def\flushbtxentries[#1]%
1008  {\begingroup
1009   \getdummyparameters[\c!command=,\c!setups=,#1]%
1010   \xdef\m_btx_list_action{\dummyparameter\c!command}%
1011   \ifempty\m_btx_list_action
1012     \xdef\m_btx_list_action{\dummyparameter\c!setups}%
1013     \ifempty\m_btx_list_action
1014       \endgroup
1015       \c_btx_list_index\zerocount
1016     \else
1017       \endgroup
1018       \c_btx_list_index\plusone
1019       \doubleexpandafter\publ_flush_list_step_command
1020     \fi
1021   \else
1022     \endgroup
1023     \c_btx_list_index\plusone
1024     \expandafter\publ_flush_list_step_command
1025   \fi}
1026
1027%D So far.
1028
1029\permanent\def\currentbtxblock{\number\btxblock}
1030
1031% called at the lua end, for determining the width
1032
1033\permanent\protected\def\btxchecklistentry
1034  {\begingroup
1035   % todo, switch to font
1036   \hbox{\btx_reference_checked}%
1037   \par
1038   \endgroup}
1039
1040% called at the lua end, the real rendering
1041
1042% we could have a yes and no where no nils the btx_reference_indeed ... saves a check there
1043
1044\installstructurelistprocessor{\s!btx}
1045  {\let\currentlistentrynumber    \btx_reference_indeed
1046   \let\currentlistentrytitle     \btx_entry_indeed
1047   \let\currentlistentrypagenumber\btx_page_indeed
1048   \strc_lists_apply_renderingsetup}
1049
1050\def\btx_entry_indeed
1051  {\dostarttaggednodetail\t!listcontent
1052   \btx_list_reference_inject
1053   \btx_entry_inject
1054   \dostoptagged}
1055
1056\def\btx_page_indeed
1057  {}
1058
1059\permanent\protected\def\btxhandlelistentry
1060  {\strc_lists_entry_process}
1061
1062\permanent\protected\def\btxstartlistentry % maybe pass i
1063  {\begingroup
1064   \global\advanceby\c_btx_list_reference\plusone}
1065
1066\permanent\protected\def\btxstoplistentry
1067  {\iftrialtypesetting
1068     \global\advanceby\c_btx_list_reference\minusone
1069   \fi
1070   \endgroup}
1071
1072\newtoks\everybtxlistentry
1073
1074\permanent\protected\def\btxlistsetup#1% used for the reference in the list
1075  {\expand\everybtxlistentry
1076   \everybtxlistentry\emptytoks % so only once per entry to be sure
1077   \publ_fast_setup\plusfour\s!list{#1}}
1078
1079\appendtoks
1080    \btx_check_language
1081\to \everybtxlistentry
1082
1083\protected\def\btx_reference_indeed
1084  {\begingroup
1085   % redundant will go away:
1086   \setbtxparameterset{\c!list:\s!numbering}\currentbtxnumbering
1087   %
1088   \ifempty\currentbtxnumbering
1089     % nothing
1090   \orelse\ifx\currentbtxnumbering\v!no
1091     % nothing
1092   \else
1093     \usebtxstyleandcolor\c!style\c!color % new, needed?
1094     \ifconditional\c_publ_prefixed\btxlistprefixednumber\fi
1095     \clf_btxlistvariant % some can go
1096       {\currentbtxdataset}%
1097       {\currentbtxblock}%
1098       {\currentbtxtag}%
1099       {\currentbtxnumbering}%
1100       {\currentbtxnumber}%
1101     \relax
1102   \fi
1103   \endgroup}
1104
1105\permanent\protected\def\btxlistprefixednumber % hack but alan needs it
1106  {\clf_listprefixednumber
1107     {\currentlist}%
1108     \currentbtxlistindex
1109     {%
1110        prefix        {\listparameter\c!prefix}%
1111        separatorset  {\listparameter\c!prefixseparatorset}%
1112        conversionset {\listparameter\c!prefixconversionset}%
1113        starter       {\listparameter\c!prefixstarter}%
1114        stopper       {\listparameter\c!prefixstopper}%
1115        set           {\listparameter\c!prefixset}%
1116        segments      {\listparameter\c!prefixsegments}%
1117        connector     {\listparameter\c!prefixconnector}%
1118     }%
1119   \relax}
1120
1121\protected\def\btx_reference_checked
1122  {\dontleavehmode\hbox\bgroup % \hpack
1123     \btx_reference_indeed
1124   \egroup}
1125
1126\newinteger\c_btx_list_reference
1127
1128\protected\def\btx_list_reference_inject
1129  {\dontleavehmode\begingroup % no box
1130     \iftrialtypesetting\else
1131       \btx_list_reference_inject_now
1132     \fi
1133   % \btx_reference_indeed % else double entry in list
1134   \endgroup}
1135
1136\def\btx_list_reference_inject_now
1137  {\strc_references_direct_full_user
1138      {\ifx\currentbtxdataset\v!default\else\s!btxset=\currentbtxdataset,\fi%
1139       \s!btxref=\currentbtxtag,%
1140       \s!btxspc=\currentbtxspecification,%
1141       \s!btxlst=\the\c_btx_list_reference,% check if needed
1142      %\ifempty\currentbtxcombis  \else\s!btxcom={\currentbtxcombis},\fi
1143       \ifempty\currentbtxbefore  \else\s!btxbtx={\currentbtxbefore},\fi
1144       \ifempty\currentbtxafter   \else\s!btxatx={\currentbtxafter },\fi
1145       \ifempty\currentbtxbacklink\else\s!btxint=\number\currentbtxbacklink\fi
1146      }%
1147      {\s!btx::\v!list::\the\c_btx_list_reference}%
1148      {\currentbtxnumber}}
1149
1150\newconditional\c_btx_cite_reference_injected
1151
1152\permanent\protected\def\btx_cite_reference_inject
1153  {\ifconditional\c_btx_cite_reference_injected \else
1154     \dontleavehmode
1155     \iftrialtypesetting \else
1156       \ifempty\currentbtxbacklink
1157         % can be made empty when combining author / year
1158       \orelse\ifnum\currentbtxbacklink>\zerocount
1159         \btx_cite_reference_inject_indeed
1160         \c_btx_cite_reference_injected\conditionaltrue
1161       \fi
1162     \fi
1163  \fi}
1164
1165\newtoks\t_btx_reference_inject
1166
1167\def\btx_cite_reference_inject_indeed
1168  {\the\t_btx_reference_inject
1169   \strc_lists_inject_direct % todo: make like \btx_list_reference_inject_now with { }
1170      [\s!btx]%
1171      [\c!type=\s!btx,\c!location=\v!here]%
1172      [\ifx\currentbtxdataset\v!default\else\s!btxset=\currentbtxdataset,\fi%
1173       \s!btxref=\currentbtxtag,%
1174      %\ifempty\currentbtxcombis  \else\s!btxcom={\currentbtxcombis},\fi%
1175       \ifempty\currentbtxbefore  \else\s!btxbtx={\currentbtxbefore},\fi%
1176       \ifempty\currentbtxafter   \else\s!btxatx={\currentbtxafter },\fi%
1177       \ifempty\currentbtxbacklink\else\s!btxint=\number\currentbtxbacklink,\fi
1178       \ifempty\currentbtxciteuservariables\else,\currentbtxciteuservariables\fi]}
1179
1180\permanent\def\currentbtxuservariable #1{\clf_btxuservariable        {\currentbtxdataset}{#1}}
1181\permanent\def\btxdoifelseuservariable#1{\clf_btxdoifelseuservariable{\currentbtxdataset}{#1}}
1182
1183\aliased\let\btxdoifuservariableelse\btxdoifelseuservariable
1184
1185\aliased\let\btxcitereference\btx_cite_reference_inject
1186
1187\mutable\lettonothing\currentbtxnumbering
1188\mutable\lettonothing\currentbtxcitealternative
1189
1190\appendtoks
1191    \edef\currentbtxnumbering{\btxrenderingparameter\c!numbering}%
1192    \ifx\currentbtxnumbering\v!yes
1193        \def\currentbtxnumbering{num}% convenient alias
1194        \letbtxrenderingparameter\c!numbering\currentbtxnumbering
1195        \letlistparameter\c!headnumber\v!always
1196    \orelse\ifx\currentbtxnumbering\v!no
1197        \letlistparameter\c!headnumber\v!no
1198        \lettonothing\currentbtxnumbering
1199      % \letlistparameter\c!textcommand\outdented % needed? we can use titlealign
1200        \letlistparameter\c!symbol     \v!none
1201        \letlistparameter\c!aligntitle \v!yes
1202        \letlistparameter\c!numbercommand\firstofoneargument % for the moment, no doubling needed
1203    \else
1204        \letlistparameter\c!headnumber\v!always
1205    \fi
1206    \let\currentlistmethod\s!btx
1207\to \everysetupbtxlistplacement
1208
1209\permanent\tolerant\protected\def\btxremapauthor[#1]#*[#2]%
1210  {\clf_btxremapauthor{#1}{#2}}
1211
1212\permanent\protected\def\btxshowauthorremapping
1213  {\clf_btxshowauthorremapping}
1214
1215\permanent\protected\def\btxflushauthor
1216  {\doifelsenextoptionalcs\btx_flush_author_yes\btx_flush_author_nop}
1217
1218\permanent\protected\def\btxflushsuffix
1219  {\ifempty\currentbtxsuffix
1220     % nothing
1221   \else
1222     \characters{\currentbtxsuffix}% todo : rendering specific converter
1223   \fi}
1224
1225\def\btx_flush_author_yes[#1]{\btx_flush_author{#1}}
1226\def\btx_flush_author_nop    {\btx_flush_author{\btxparameter\c!authorconversion}}
1227
1228\protected\def\btx_flush_author#1#2%
1229  {\begingroup
1230   \edef\currentbtxfield{#2}%
1231   \setbtxparameterset\s!list\currentbtxfield
1232% \let\currentbtxlistvariant\currentbtxfield
1233   \clf_btxauthor
1234        {\currentbtxdataset}%
1235        {\currentbtxtag}%
1236        {\currentbtxfield}%
1237        {%
1238            combiner    {#1}%
1239            kind        {list}%
1240            etallimit   {\btxparameter\c!etallimit}%
1241            etaldisplay {\btxparameter\c!etaldisplay}%
1242            etaloption  {\btxparameter\c!etaloption}%
1243            symbol      {\btxparameter{\c!stopper:initials}}%
1244            connector   {\btxparameter{\c!connector:initials}}%
1245        }%
1246   \relax
1247   \endgroup}
1248
1249% yes or no: maybe just \flushauthor{...}{...}
1250
1251\permanent\protected\def\btxflushauthorname         {\btx_flush_author{name}}          % #1
1252\permanent\protected\def\btxflushauthornormal       {\btx_flush_author{normal}}        % #1
1253\permanent\protected\def\btxflushauthornormalshort  {\btx_flush_author{normalshort}}   % #1
1254\permanent\protected\def\btxflushauthorinverted     {\btx_flush_author{inverted}}      % #1
1255\permanent\protected\def\btxflushauthorinvertedshort{\btx_flush_author{invertedshort}} % #1
1256
1257\mutable\let\currentbtxauthorfield\s!author
1258
1259\permanent\protected\def\btxsetauthorfield#1{\edef\currentbtxauthorfield{#1}}
1260
1261\permanent\protected\def\currentbtxciteauthorbyfield
1262  {\begingroup
1263   %\setbtxparameterset\s!cite\s!author
1264   % the alternatives inherit from cite:author
1265   % and APA distinguishes authoryears from authoryear ("and" vs. "&")
1266   \setbtxparameterset\s!cite\currentbtxcitealternative
1267   \clf_btxauthor
1268        {\currentbtxdataset}%
1269        {\currentbtxtag}%
1270        {\currentbtxauthorfield}%
1271        {%
1272            combiner    {\btxparameter\c!authorconversion}%
1273            kind        {cite}%
1274            etallimit   {\btxparameter\c!etallimit}%
1275            etaldisplay {\btxparameter\c!etaldisplay}%
1276            etaloption  {\btxparameter\c!etaloption}%
1277            symbol      {\btxparameter{\c!stopper:initials}}%
1278        }%
1279   \relax
1280   \endgroup}
1281
1282\permanent\protected\def\currentbtxciteauthor
1283  {\let\currentbtxauthorfield\s!author
1284   \currentbtxciteauthorbyfield} % always author
1285
1286\permanent\protected\def\btxstartauthor#1#2#3% a state > 0 signals that some authors can clash
1287  {\begingroup
1288   \currentbtxauthorindex#1\relax
1289   \currentbtxauthorcount#2\relax
1290   \currentbtxauthorstate#3\relax}
1291
1292\permanent\protected\def\btxstopauthor
1293  {\endgroup}
1294
1295\permanent\protected\def\btxciteauthorsetup#1{\fastsetup{\s!btx:\s!cite:\s!author:#1}}
1296\permanent\protected\def\btxlistauthorsetup#1{\fastsetup{\s!btx:\s!list:\s!author:#1}}
1297
1298% \btxflushauthor{author}
1299% \btxflushauthor{editor}
1300%
1301% \btxflushauthor[name]{author}
1302% \btxflushauthor[normal]{author}
1303% \btxflushauthor[normalshort]{author}
1304% \btxflushauthor[inverted]{author}
1305% \btxflushauthor[invertedshort]{author}
1306
1307% \btxflushauthor{author}
1308% \btxflushauthor{editor}
1309
1310% Interaction
1311%
1312% Because we have more complex entries in lists we don't use the normal list
1313% interaction features.
1314
1315\newconditional\btxinteractive
1316\newconditional\btxinteractivenumber
1317\newconditional\btxinteractivetext
1318\newconditional\btxinteractivepage
1319
1320\mutable\lettonothing\currentbtxinteraction
1321
1322\installcorenamespace{btxinteraction}
1323
1324\defcsname\??btxinteraction\v!number\endcsname{\btxinteractivenumber\conditionaltrue}
1325\defcsname\??btxinteraction\v!text  \endcsname{\btxinteractivetext\conditionaltrue}
1326\defcsname\??btxinteraction\v!page  \endcsname{\btxinteractivepage\conditionaltrue}
1327\defcsname\??btxinteraction\v!all   \endcsname{\btxinteractivenumber\conditionaltrue
1328                                               \btxinteractivetext\conditionaltrue
1329                                               \btxinteractivepage\conditionaltrue}
1330
1331% \setupbtx[interaction=page] % or text or number or all
1332% \setupbtxrendering[pagestate=start]
1333
1334\appendtoks
1335    \iflocation
1336        \edef\currentbtxinteraction{\btxparameter\c!interaction}%
1337        \ifx\currentbtxinteraction\v!stop
1338            \btxinteractive\conditionalfalse
1339        \else
1340            \enforced\lettonothing\structurelistlocation
1341            \btxinteractive\conditionaltrue
1342            \begincsname\??btxinteraction\currentbtxinteraction\endcsname
1343        \fi
1344    \else
1345        \btxinteractive\conditionalfalse
1346    \fi
1347\to \everysetupbtxlistplacement
1348
1349\appendtoks
1350    \iflocation
1351        \edef\currentbtxinteraction{\btxparameter\c!interaction}%
1352        \ifx\currentbtxinteraction\v!stop
1353            \btxinteractive\conditionalfalse
1354        \else
1355            \btxinteractive\conditionaltrue
1356        \fi
1357    \else
1358        \btxinteractive\conditionalfalse
1359    \fi
1360\to \everysetupbtxciteplacement
1361
1362%D When a publication is cited, we need to signal that somehow. This is done with the
1363%D following (not user) command. We could tag without injecting a node but this way
1364%D we also store the location, which makes it possible to ask local lists.
1365
1366%D \macros{cite,nocite,citation,nocitation,usecitation}
1367%D
1368%D The inline \type {\cite} command creates a (often) short reference to a publication
1369%D and for historic reasons uses a strict test for brackets. This means, at least
1370%D in the default case that spaces are ignored in the argument scanner. The \type
1371%D {\citation} commands is more liberal but also gobbles following spaces. Both
1372%D commands insert a reference as well as a visual clue.
1373%D
1374%D The \type {no} commands all do the same (they are synonyms): they make sure that
1375%D a reference is injected but show nothing. However, they do create a node so best
1376%D attach them to some text in order to avoid spacing interferences. A slightly
1377%D less efficient alternative is \type {\cite[none][tag]}.
1378
1379% [tags]
1380% [settings|variant][tags]
1381% [base::tags]
1382% [settings|variant][base::tags]
1383
1384% these need to be sort of protected:
1385
1386% methods:
1387%
1388% hidden : mark for list, don't show in text
1389% list   : mark for list, show in text only when in list
1390% text   : not to list, show in text
1391% always : mark for list, show in text
1392
1393\lettonothing\p_publ_cite_before
1394\lettonothing\p_publ_cite_after
1395\lettonothing\p_publ_cite_lefttext
1396\lettonothing\p_publ_cite_righttext
1397
1398\mutable\lettonothing\currentbtxciteuservariables
1399\mutable\lettonothing\currentbtxcitealternative
1400
1401\permanent\protected\def\btxhybridcite % so one can alias the old
1402  {\dontleavehmode
1403   \begingroup
1404   \strictdoifelsenextoptional\publ_cite_tags_options\publ_cite_tags_indeed}
1405
1406\protected\def\publ_cite_tags_options[#1]%
1407  {\strictdoifelsenextoptional{\publ_cite_tags_options_indeed{#1}}{\publ_cite_tags_indeed{#1}}}
1408
1409\protected\def\publ_cite_tags_indeed#1%
1410  {\resetinteractionstyle
1411   \setbtxparametersetroot\s!cite % we need to get the default
1412   \edef\currentbtxcitealternative{\btxparameter\c!alternative}%
1413   \setbtxparameterset\s!cite\currentbtxcitealternative
1414   \edef\currentbtxcitetag{#1}%
1415   \expand\everysetupbtxciteplacement
1416   \publ_cite_variant
1417   \endgroup}
1418
1419\protected\def\publ_cite_tags_options_indeed#1%
1420  {\doifelseassignment{#1}\publ_cite_tags_settings_indeed\publ_cite_tags_variants_indeed{#1}}
1421
1422\def\publ_cite_tags_settings_indeed#1[#2]%
1423  {\resetinteractionstyle
1424  %\resetinteractioncolor
1425   \resetdummyparameter\c!reference
1426   \resetdummyparameter\c!alternative
1427   \resetdummyparameter\c!before
1428   \resetdummyparameter\c!after
1429   \resetdummyparameter\c!lefttext
1430   \resetdummyparameter\c!righttext
1431   \getdummyparameters[#1]%
1432   \edef\p_reference{\dummyparameter\c!reference}%
1433   \ifempty\p_reference
1434      \edef\currentbtxcitetag{#2}%
1435   \else
1436      \let\currentbtxcitetag\p_reference
1437      \edef\currentbtxciteuservariables{#2}%
1438   \fi
1439   \edef\p_specification{\dummyparameter\c!specification}%
1440   \ifempty\p_specification
1441   \else
1442     \let\currentbtxspecification\p_specification
1443   \fi
1444   \edef\p_alternative{\dummyparameter\c!alternative}%
1445   \ifempty\p_alternative
1446     \setbtxparametersetroot\s!cite
1447     \edef\currentbtxcitealternative{\btxparameter\c!alternative}%
1448   \else
1449     \let\currentbtxcitealternative\p_alternative
1450   \fi
1451   \setbtxparameterset\s!cite\currentbtxcitealternative
1452   \setupcurrentbtx[#1]%
1453   %
1454   \edef\p_publ_cite_before   {\dummyparameter\c!before}%
1455   \edef\p_publ_cite_after    {\dummyparameter\c!after}%
1456   \edef\p_publ_cite_lefttext {\dummyparameter\c!lefttext}%
1457   \edef\p_publ_cite_righttext{\dummyparameter\c!righttext}%
1458   %
1459   \expand\everysetupbtxciteplacement
1460   \publ_cite_variant
1461   \endgroup}
1462
1463\def\publ_cite_tags_variants_indeed#1[#2]%
1464  {\resetinteractionstyle
1465   \edef\currentbtxcitealternative{#1}%
1466   \edef\currentbtxcitetag{#2}%
1467   \setbtxparameterset\s!cite\currentbtxcitealternative
1468   \expand\everysetupbtxciteplacement
1469   \publ_cite_variant
1470   \endgroup}
1471
1472\newconditional\btxcitecompress
1473
1474\mutable\let\currentbtxcitemethod\v!hidden
1475
1476\def\publ_cite_variant
1477  {\begingroup
1478   \publ_cite_handle_variant_indeed[\currentbtxcitetag]}
1479
1480\protected\def\publ_cite_handle_variant#1%
1481  {\begingroup
1482   \edef\currentbtxcitealternative{#1}%
1483   \setbtxparameterset\s!cite\currentbtxcitealternative
1484   \expand\everysetupbtxciteplacement
1485   \publ_cite_handle_variant_indeed}
1486
1487\permanent\protected\def\publ_cite_handle_variant_blob
1488  {\clf_btxhandlecite
1489     dataset          {\currentbtxdataset}%
1490     reference        {\currentbtxreference}%
1491     method           {\currentbtxcitemethod}%
1492     variant          {\currentbtxcitealternative}%
1493     sorttype         {\btxparameter\c!sorttype}%
1494     compress         {\btxparameter\c!compress}%
1495     author           {\btxparameter\c!author}%
1496     authorconversion {\c!authorconversion}%
1497     lefttext         {\p_publ_cite_lefttext}%
1498     righttext        {\p_publ_cite_righttext}%
1499     before           {\p_publ_cite_before}%
1500     after            {\p_publ_cite_after}%
1501   \relax
1502   \iftrialtypesetting\else
1503    %\clf_btxflushmarked
1504   \fi}
1505
1506\aliased\let\dobtxcitevariantblob\publ_cite_handle_variant_blob % command can use it via lua
1507
1508\let\publ_cite_trace_blob\relax
1509
1510\tolerant\def\publ_cite_handle_variant_indeed[#1]%
1511  {\letbtxparameter\c!alternative\currentbtxcitealternative
1512   \edef\currentbtxreference{#1}%
1513   \saverunningstyleandcolor
1514   \usebtxstyleandcolor\c!style\c!color
1515   \uselanguageparameter\btxdatasetparameter % new
1516   \dostarttaggednodetail\t!citation
1517   \btxparameter\c!left
1518   \btxparameter\c!command{\dobtxcitevariantblob}% {\publ_cite_handle_variant_blob}%
1519   \btxparameter\c!right
1520   \dostoptagged
1521   \publ_cite_trace_blob
1522   \endgroup}
1523
1524\permanent\protected\def\btxstarttaggedcite
1525  {\dostarttagged\t!cite{\currentbtxdataset::\currentbtxtag}}
1526
1527\permanent\protected\def\btxstoptaggedcite
1528  {\dostoptagged}
1529
1530\permanent\protected\def\btxlistcitation  {\publ_citation\v!list}
1531\permanent\protected\def\btxtextcitation  {\publ_citation\v!text}
1532\permanent\protected\def\btxalwayscitation{\publ_citation\v!always}
1533
1534\tolerant\def\publ_citation#1[#2]#,[#3]% could be made more efficient but not now
1535  {\dontleavehmode
1536   \begingroup
1537   \let\currentbtxcitemethod#1%
1538   \ifparameter#3\or
1539     \publ_cite_tags_options_indeed{#2}[#3]%
1540   \else
1541     \publ_cite_tags_indeed{#2}%
1542   \fi}
1543
1544\permanent\tolerant\protected\def\btxhiddencitation[#1]%
1545  {\iftrialtypesetting \else
1546     \begingroup
1547     \let\currentbtxcitemethod\v!hidden
1548     \edef\currentbtxreference{#1}%
1549     \clf_btxhandlenocite
1550       method    {\currentbtxcitemethod}%
1551       dataset   {\currentbtxdataset}%
1552       reference {\currentbtxreference}%
1553     \relax
1554    %\clf_btxflushmarked
1555     \endgroup
1556   \fi}
1557
1558% \permanent\protected\def\btxmissing#1%
1559%   {\dontleavehmode{\tttf<#1>}}
1560
1561\permanent\protected\def\currentbtxmissingreference
1562  {\clf_btxmissing{\currentbtxdataset}{\currentbtxreference}}
1563
1564\permanent\protected\def\btxmissing#1%
1565  {\dontleavehmode{\tttf<\clf_btxmissing{\currentbtxdataset}{#1}>}}
1566
1567%D Compatibility:
1568
1569\aliased\let\hiddencitation\btxhiddencitation  \aliased\let\hiddencite\hiddencitation
1570\aliased\let\listcitation  \btxlistcitation    \aliased\let\listcite  \listcitation
1571\aliased\let\textcitation  \btxtextcitation    \aliased\let\textcite  \textcitation
1572\aliased\let\alwayscitation\btxalwayscitation  \aliased\let\alwayscite\alwayscitation
1573
1574\permanent\protected\def\citation  {\doifelsenextoptionalcs\btxlistcitation  \btxdirectlistcite}
1575\permanent\protected\def\nocitation{\doifelsenextoptionalcs\btxhiddencitation\btxdirecthiddencite}
1576
1577\aliased\let\cite       \citation
1578\aliased\let\nocite     \nocitation
1579\aliased\let\usecitation\nocitation
1580
1581\protected\def\publ_entry_citation  {\doifelsenextoptionalcs\btxlistcitation  \btxdirectlistcite}
1582\protected\def\publ_entry_nocitation{\doifelsenextoptionalcs\btxhiddencitation\btxdirecthiddencite}
1583
1584\appendtoks
1585    \enforced\let\cite  \publ_entry_citation
1586    \enforced\let\nocite\publ_entry_nocitation
1587\to \everybtxlistrendering
1588
1589\permanent\protected\def\btxdirectlistcite  #1{\btxlistcitation  [#1]\relax} % no optional arguments
1590\permanent\protected\def\btxdirecthiddencite#1{\btxhiddencitation[#1]\relax} % no optional arguments
1591
1592%D Setup helpers, beware, we need to wrap this .. now we need to know
1593%D how setups are implemented.
1594
1595\defcsname\??setup:\s!btx:\s!unknown\endcsname#1{\inframed{\tttf#1}}
1596
1597\def\publ_fast_setup_yes#1#2%
1598  {\csname\??setup:\s!btx:%
1599     \ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname
1600        \currentbtxspecification:#1:#2%
1601     \orelse\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:#2\endcsname
1602        \currentbtxspecificationfallback:#1:#2%
1603     \orelse\ifcsname\??setup:\s!btx:#1:#2\endcsname
1604        #1:#2%
1605     \orelse\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname
1606        \currentbtxspecification:#1:\s!unknown
1607     \orelse\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:\s!unknown\endcsname
1608        \currentbtxspecificationfallback:#1:\s!unknown
1609     \else
1610        #1:\s!unknown
1611     \fi
1612   \endcsname{#2}}
1613
1614\def\publ_fast_setup_nop#1#2%
1615  {\csname\??setup:\s!btx:%
1616     \ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname
1617        \currentbtxspecification:#1:#2%
1618     \orelse\ifcsname\??setup:\s!btx:#1:#2\endcsname
1619        #1:#2%
1620     \orelse\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname
1621        \currentbtxspecification:#1:\s!unknown
1622     \else
1623        #1:\s!unknown
1624     \fi
1625   \endcsname{#2}}
1626
1627\newconstant\btxsetuptype
1628
1629% 0 = unknown   darkred
1630% 1 = cite      darkblue
1631% 2 = subcite   darkgreen
1632% 3 = numbering darkorange
1633% 4 = list      darkcyan
1634% 5 = page      darkmagenta
1635% 6 = unknown   darkred
1636
1637\protected\def\publ_fast_btx_setup_chain_inbetween{\allowbreak->\allowbreak}
1638\protected\def\publ_fast_btx_setup_colon_inbetween{\allowbreak :\allowbreak}
1639
1640\protected\def\publ_fast_btx_setup_chain_yes#1#2%
1641  {\dontleavehmode\begingroup
1642   \enforced\let\:\publ_fast_btx_setup_colon_inbetween
1643   \infofont
1644   \ifcase\btxsetuptype\darkred\or\darkblue\or\darkgreen\or\darkcyan\or\darkmagenta\else\darkred\fi
1645   [\prewordbreak
1646   \currentbtxspecification        \:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname\else
1647   \publ_fast_btx_setup_chain_inbetween
1648   \currentbtxspecificationfallback\:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#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   \currentbtxspecificationfallback\:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecificationfallback:#1:\s!unknown\endcsname\else
1655   \publ_fast_btx_setup_chain_inbetween
1656   unset\fi\fi\fi\fi\fi
1657   \space @\space
1658   \currentbtx
1659   \prewordbreak]%
1660   \endgroup}
1661
1662\protected\def\publ_fast_btx_setup_chain_nop#1#2%
1663  {\dontleavehmode\begingroup
1664   \enforced\let\:\publ_fast_btx_setup_colon_inbetween
1665   \infofont
1666   \darkred
1667   [\prewordbreak
1668   \currentbtxspecification\:#1\:#2\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:#2\endcsname\else
1669   \publ_fast_btx_setup_chain_inbetween
1670                             #1\:#2\ifcsname\??setup:\s!btx:#1:#2\endcsname\else
1671   \publ_fast_btx_setup_chain_inbetween
1672   \currentbtxspecification\:#1\:\s!unknown\ifcsname\??setup:\s!btx:\currentbtxspecification:#1:\s!unknown\endcsname\else
1673   \publ_fast_btx_setup_chain_inbetween
1674   unset\fi\fi\fi
1675   \space @\space
1676   \currentbtx
1677   \prewordbreak]%
1678   \endgroup}
1679
1680\protected\def\publ_fast_btx_setup_normal#1%
1681  {\btxsetuptype#1\relax
1682   \ifempty\currentbtxspecificationfallback
1683     \expandafter\publ_fast_setup_nop
1684   \else
1685     \expandafter\publ_fast_setup_yes
1686   \fi}
1687
1688\protected\def\publ_fast_btx_setup_visual#1#2#3%
1689  {\btxsetuptype#1\relax
1690   \ifempty\currentbtxspecificationfallback
1691     \expandafter\publ_fast_btx_setup_chain_nop
1692   \else
1693     \expandafter\publ_fast_btx_setup_chain_yes
1694   \fi{#2}{#3}%
1695   \ifempty\currentbtxspecificationfallback
1696     \expandafter\publ_fast_setup_nop
1697   \else
1698     \expandafter\publ_fast_setup_yes
1699   \fi{#2}{#3}}
1700
1701\installtextracker
1702  {publications.setups}
1703  {\let\publ_fast_setup\publ_fast_btx_setup_visual}
1704  {\let\publ_fast_setup\publ_fast_btx_setup_normal}
1705
1706\let\publ_fast_setup\publ_fast_btx_setup_normal
1707
1708%D Cite helpers:
1709
1710\newtoks\everybtxciteentry
1711
1712\prependtoks
1713    \c_btx_cite_reference_injected\conditionalfalse
1714\to \everybtxciteentry
1715
1716\permanent\protected\def\btxcitesetup#1%
1717  {\expand\everybtxciteentry
1718   \everybtxciteentry\emptytoks % tricky maybe not when subcites
1719   \publ_fast_setup\plusone\s!cite{#1}}    % no \btxcitereset as we loose dataset and such
1720
1721\permanent\protected\def\btxsubcitesetup#1%
1722  {\expand\everybtxciteentry
1723   \everybtxciteentry\emptytoks % tricky maybe not when subcites
1724   \publ_fast_setup\plustwo\s!cite{#1}}    % no \btxcitereset as we loose dataset and such
1725
1726\appendtoks
1727    \btx_check_language
1728\to \everybtxciteentry
1729
1730\permanent\protected\def\btxstartsubcite#1%
1731  {\begingroup
1732   \btx_reset_cite % todo: limited set
1733 % \saverunningstyleandcolor % let's see when Alan needs it
1734   \def\currentbtxcitealternative{#1}%
1735   \setbtxparameterset\s!cite\currentbtxcitealternative
1736   \usebtxstyleandcolor\c!style\c!color
1737   \btxparameter\c!left
1738   \relax}
1739
1740\permanent\protected\def\btxstopsubcite
1741  {\relax
1742   \btxparameter\c!right
1743   \endgroup}
1744
1745\permanent\protected\def\btxstartciterendering[#1]%
1746  {\begingroup
1747   \edef\currentbtxcitealternative{#1}%
1748   \setbtxparameterset\s!cite\currentbtxcitealternative
1749   \usebtxstyleandcolor\c!style\c!color
1750   \btxparameter\c!left
1751   \relax}
1752
1753\permanent\protected\def\btxstopciterendering
1754  {\relax
1755   \btxparameter\c!right
1756   \endgroup}
1757
1758\aliased\let\btxstartciteauthor\begingroup
1759\aliased\let\btxstopciteauthor \endgroup
1760
1761\permanent\protected\def\btxstartcite{\begingroup\btx_reset_cite}
1762\aliased            \let\btxstopcite  \endgroup
1763
1764%D Whatever helpers:
1765
1766\permanent\protected\def\btxsingularplural#1{\clf_btxsingularorplural{\currentbtxdataset}{\currentbtxtag}{#1}}
1767\permanent\protected\def\btxoneorrange    #1{\clf_btxoneorrange      {\currentbtxdataset}{\currentbtxtag}{#1}}
1768\permanent\protected\def\btxfirstofrange  #1{\clf_btxfirstofrange    {\currentbtxdataset}{\currentbtxtag}{#1}}
1769
1770\aliased\let\btxsingularorplural\btxsingularplural
1771
1772\stopcontextdefinitioncode
1773
1774%D Journals
1775
1776\permanent\protected\def\btxloadjournallist [#1]{\clf_btxloadjournallist{#1}}
1777\permanent\protected\def\btxsavejournallist [#1]{\clf_btxsavejournallist{#1}}
1778\permanent\protected\def\btxaddjournal  [#1][#2]{\clf_btxaddjournal{#1}{#2}}
1779\permanent          \def\btxexpandedjournal   #1{\clf_btxexpandedjournal{#1}}    % \protected ?
1780\permanent          \def\btxabbreviatedjournal#1{\clf_btxabbreviatedjournal{#1}} % \protected ?
1781
1782% \installcorenamespace{btxjournal}
1783%
1784% \aliased\letcsname\s!btxjournal\v!long  \endcsname\btxexpandedjournal
1785% \aliased\letcsname\s!btxjournal\v!short \endcsname\btxabbreviatedjournal
1786% \aliased\letcsname\s!btxjournal\v!normal\endcsname\firstofoneargument
1787%
1788% \protected\def\btxcheckedjournal
1789%   {\expandnamespaceparameter\s!btxjournal\btxrenderingparameter\c!journalconversion}
1790
1791% \btxloadjournallist[list.txt] % Foo Journal of Bars = FBJ \n ....
1792%
1793% \btxexpandedjournal[fbj]
1794% \btxabbreviatedjournal[foo journal of bars]
1795
1796%D Saving data:
1797
1798\tolerant\permanent\protected\def\savebtxdataset[#1]#*[#2]#*[#3]
1799  {\ifarguments
1800     % bad news
1801   \or
1802     \ifhastok={#1}%
1803       \publ_save_dataset_indeed[\s!default][\jobname-saved.bib][#1]%
1804     \else
1805       \publ_save_dataset_indeed[\s!default][#1][]%
1806     \fi
1807   \or
1808     \ifhastok={#2}%
1809       \publ_save_dataset_indeed[\s!default][#1][#2]%
1810     \else
1811       \publ_save_dataset_indeed[#1][#2][]%
1812     \fi
1813   \or
1814     \publ_save_dataset_indeed[#1][#2][#3]%
1815   \fi}
1816
1817\protected\def\publ_save_dataset_indeed[#1][#2][#3]%
1818  {\begingroup
1819   \getdummyparameters
1820     [\c!criterium=\v!all,%
1821      \c!type=,%
1822      \c!dataset=#1,%
1823      \c!file=#2,%
1824      #3]% % all or used
1825   \clf_btxsavedataset
1826     dataset   {\dummyparameter\c!dataset}%
1827     filename  {\dummyparameter\c!file}%
1828     filetype  {\dummyparameter\c!type}%
1829     criterium {\dummyparameter\c!criterium}%
1830     options   {\dummyparameter\c!option}%
1831   \relax
1832   \endgroup}
1833
1834% \savebtxdataset[default][e:/tmp/foo.bib]
1835% \savebtxdataset[default][e:/tmp/foo.lua]
1836% \savebtxdataset[default][e:/tmp/foo.xml]
1837
1838%D In-text entries:
1839
1840\permanent\protected\def\placecitation{\citation[entry]} % [#1]
1841
1842\permanent\protected\def\btxhandleciteentry
1843  {\dontleavehmode
1844   \begingroup
1845   \def\currentbtxcitealternative{entry}%
1846   \setbtxparameterset\s!cite\currentbtxcitealternative % needs checking
1847   \btxcitereference
1848   \btx_entry_inject
1849   \endgroup}
1850
1851%D Registers
1852
1853% \setupbtxregister
1854%   [\c!state=\v!start,
1855%    \c!dataset=\v!all,
1856%    \c!method=\v!always]
1857
1858\protected\def\publ_registers_set
1859  {\ifempty\currentbtxregister \else
1860     \clf_btxsetregister
1861        specification {\currentbtxspecification}%
1862        name          {\currentbtxregister}%
1863        state         {\btxregisterparameter\c!state}%
1864        dataset       {\btxregisterparameter\c!dataset}%
1865        field         {\btxregisterparameter\c!field}%
1866        register      {\btxregisterparameter\c!register}%
1867        method        {\btxregisterparameter\c!method}%
1868        alternative   {\btxregisterparameter\c!alternative}%
1869     \relax
1870  \fi}
1871
1872\appendtoks
1873    \publ_registers_set
1874\to \everydefinebtxregister
1875
1876\appendtoks
1877    \publ_registers_set
1878\to \everysetupbtxregister
1879
1880\appendtoks
1881    \normalexpanded{%
1882      \defineprocessor
1883        [\s!btx:r:\currentbtxregister]%
1884        [\c!style=\noexpand\namedbtxregisterparameter{\currentbtxregister}\noexpand\c!style,
1885         \c!color=\noexpand\namedbtxregisterparameter{\currentbtxregister}\noexpand\c!color]}%
1886\to \everydefinebtxregister
1887
1888\appendtoks
1889    \clf_btxtoregister{\currentbtxdataset}{\currentbtxtag}%
1890\to \t_btx_reference_inject
1891
1892\permanent\protected\def\btxindexedauthor#1#2#3#4#5#6% alternative von last initials first junior
1893  {\begingroup
1894   \def\currentbtxcitealternative{#1}%
1895   \ifempty\currentbtxcitealternative
1896      \edef\currentbtxcitealternative{invertedshort}% maybe we need some default here too?
1897   \fi
1898   %let\currentbtxlistvariant\currentbtxcitealternative % we inherit
1899   \expand\everysetupbtxciteplacement
1900   \def\currentbtxvons       {#2}%
1901   \def\currentbtxsurnames   {#3}%
1902   \def\currentbtxinitials   {#4}%
1903   \def\currentbtxfirstnames {#5}%
1904   \def\currentbtxjuniors    {#6}%
1905   \setbtxparameterset\s!cite\currentbtxcitealternative
1906   \fastsetup{\s!btx:\s!cite:\s!author:\currentbtxcitealternative}%
1907   \endgroup}
1908
1909\permanent\protected\def\btxregisterauthor
1910  {\doifelsenextoptionalcs\publ_register_author_yes\publ_register_author_nop}
1911
1912\def\publ_register_author_yes[#1]#2%
1913  {\clf_btxauthortoregister{#1}{#2}\relax}
1914
1915\def\publ_register_author_nop#1%
1916  {\clf_btxauthortoregister{\currentbtxdataset}{#1}\relax}
1917
1918%D We hook some setters in the definition sets:
1919
1920% \installdefinitionsetmember \??btx {btxspecification} \??btxcitevariant {btxcitevariant}
1921% \installdefinitionsetmember \??btx {btxspecification} \??btxlistvariant {btxlistvariant}
1922% \installdefinitionsetmember \??btx {btxspecification} \??btxlist        {btxlist}
1923% \installdefinitionsetmember \??btx {btxspecification} \??btxrendering   {btxrendering}
1924% \installdefinitionsetmember \??btx {btxspecification} \??btx            {btx}
1925
1926%D And more helpers ... a never ending story these publications:
1927
1928% \definebtx
1929%   [btx:apa:list:article:title]
1930%   [style=bolditalic,
1931%    command=\WORD]
1932%
1933% \btxstartstyle[btx:apa:list:article:title]
1934%     \btxusecommand[btx:apa:list:article:title]{foo}
1935% \btxstopstyle
1936
1937\mutable\lettonothing\m_btx_saved_current
1938
1939\permanent\protected\def\btxstartstyle[#1]%
1940  {\begingroup
1941   \let\m_btx_saved_current\currentbtx
1942   \def\currentbtx{#1}%
1943   \usebtxstyleparameter\c!style
1944   \let\currentbtx\m_btx_saved_current}
1945
1946\permanent\protected\def\btxstartcolor[#1]%
1947  {\begingroup
1948   \let\m_btx_saved_current\currentbtx
1949   \def\currentbtx{#1}%
1950   \usebtxcolorparameter\c!color
1951   \let\currentbtx\m_btx_saved_current}
1952
1953\permanent\protected\def\btxstartstyleandcolor[#1]%
1954  {\begingroup
1955   \let\m_btx_saved_current\currentbtx
1956   \def\currentbtx{#1}%
1957   \usebtxstyleandcolor\c!style\c!color
1958   \let\currentbtx\m_btx_saved_current}
1959
1960\aliased\let\btxstopstyle        \endgroup
1961\aliased\let\btxstopcolor        \endgroup
1962\aliased\let\btxstopstyleandcolor\endgroup
1963
1964\permanent\protected\def\btxusecommand[#1]#2% using #2 permits space after []
1965  {\namedbtxparameter{#1}\c!command{#2}}
1966
1967\permanent\protected\def\startbtxrunningstyleandcolor
1968  {\dontleavehmode
1969   \begingroup
1970   \restorerunningstyleandcolor}
1971
1972\permanent\protected\def\stopbtxrunningstyleandcolor
1973  {\endgroup}
1974
1975%D Maybe handy:
1976
1977\permanent\protected\def\btxdoifelsematches#1#2#3%
1978  {\clf_btxdoifelsematches{#1}{#2}{#3}}
1979
1980%D Defaults:
1981
1982\setupbtxrendering
1983  [\c!interaction=\v!start, % \v!all
1984   \c!specification=\btxparameter\c!specification,
1985   \c!dataset=\v!default,
1986   \c!repeat=\v!no,
1987   \c!continue=\v!no,
1988   \c!method=\v!global,
1989 % \c!setups=btx:\btxrenderingparameter\c!alternative:initialize, % not the same usage as cite !
1990   \c!sorttype=\v!default,
1991   \c!criterium=\v!text,
1992   \c!refcommand=authoryears,  % todo
1993   \c!numbering=\v!yes,
1994  %\c!saveinlist=\v!no, % maybe for before/after
1995   \c!pagestate=\v!stop,
1996   \c!textstate=\v!start,
1997   \c!width=\v!auto,
1998   \c!separator={\removepunctuation;\space},
1999   \c!distance=1.5\emwidth]
2000
2001% Quite some interpunction and labels are the same of at least consistent within
2002% a standard when citations and list entries are involved. We assume that each
2003% standard defines its own set but it can fall back on these defaults.
2004
2005\setupbtx
2006  [\c!interaction=\v!start,
2007   \c!alternative=num, % default cite form, normally defined in the cite namespace
2008   \c!inbetween=\btxspace,
2009 % \c!range=\endash,   % separator:range?
2010   \c!range=\directdiscretionary\endash,
2011   \c!compress=\v!yes, % was no?
2012   \c!authorconversion=normal,
2013   \c!sorttype=normal, % normal, reverse or none
2014   \c!etallimit=3,
2015   \c!etaldisplay=\btxparameter\c!etallimit,
2016   \c!otherstext={\btxspace et al.},
2017   \c!separator:firstnames={\btxspace},
2018   \c!separator:juniors={\btxspace},
2019   \c!separator:vons={\btxnobreakspace},
2020   \c!separator:initials={\btxspace},
2021   \c!connector:initials={\btxhyphen},
2022   \c!stopper:initials={.},
2023  %\c!surnamesep={\btxcomma}, % is this used anywhere?
2024   \c!separator:invertedinitials={\btxcomma},
2025   \c!separator:invertedfirstnames={\btxcomma},
2026   \c!separator:names:2={\btxcomma}, % separates multiple names
2027   \c!separator:names:3=\btxparameter{\c!separator:2}, % before last name in a list
2028   \c!separator:names:4=\btxparameter{\c!separator:2}, % between only two names
2029   \c!separator:2={\btxsemicolon}, % aka pubsep - separates multiple objects
2030   \c!separator:3=\btxparameter{separator:2}, % before last object in a list
2031   \c!separator:4=\btxparameter{separator:2}] % between only two objects
2032
2033% Do we want these in the format? Loading them delayed is somewhat messy.
2034
2035\loadbtxdefinitionfile[commands]
2036\loadbtxdefinitionfile[definitions]
2037
2038\loadbtxdefinitionfile[cite]
2039\loadbtxdefinitionfile[list]
2040\loadbtxdefinitionfile[page]
2041\loadbtxdefinitionfile[author]
2042
2043% we assume that the users sets up the right specification and if not ... well,
2044% hope for the best that something shows up and consult the manual otherwise
2045
2046\permanent\protected\def\usebtxdefinitions[#1]%
2047  {\loadbtxdefinitionfile[#1]%     % for hh
2048   \setupbtx[\c!specification=#1]} % for ab
2049
2050\setupbtx
2051  [\c!specification=\s!default,
2052   \c!dataset=\v!default,
2053   \c!default=\v!default]
2054
2055\loadbtxdefinitionfile
2056  [\s!default]
2057
2058%D Delayed loading:
2059
2060\fetchmodulecommand \showbtxdatasetfields       \f!publ_tra
2061\fetchmodulecommand \showbtxdatasetcompleteness \f!publ_tra
2062\fetchmodulecommand \showbtxdatasetauthors      \f!publ_tra
2063\fetchmodulecommand \showbtxhashedauthors       \f!publ_tra
2064\fetchmodulecommand \showbtxfields              \f!publ_tra
2065\fetchmodulecommand \showbtxtables              \f!publ_tra
2066
2067%D Some potential crap:
2068%D
2069%D Because I consider this bad data management and a weird mix of languages only one
2070%D accessor is provided.
2071
2072\permanent\tolerant\protected\def\btxshortcut[#1]#:#2%
2073  {\clf_btxshortcut{\ifparameter#1\or#1\else\s!default\fi}{#2}}
2074
2075\protect
2076