publications-extensions.tex /size: 3148 b    last modification: 2020-07-01 14:35
1\environment publications-style
2
3\startcomponent publications-extensions
4
5\startchapter[title=Extensions]
6
7As \TEX\ and \LUA\ are both open and accessible in \CONTEXT\ it is possible to
8extend the functionality of the bibliography related code. For instance, you
9could add extra loaders, sketched as follows:
10
11\startTEX
12\startluacode
13function publications.loaders.myformat(dataset,filename)
14    local t = { }
15    -- Load data from 'filename' and convert it to a Lua table 't' with
16    -- the key as hash entry and fields conforming the luadata table
17    -- format.
18    loaders.lua(dataset,t)
19end
20\stopluacode
21\stopTEX
22
23This would then permit the loading a database (into a dataset) with the command:
24
25\cindex{usebtxdataset}
26
27\startTEX
28\usebtxdataset[default][myfile.myformat]
29\stopTEX
30
31The \type {myformat} suffix is recognized automatically. If you want to use another
32suffix, you can do this:
33
34\cindex{usebtxdataset}
35
36\startTEX
37\usebtxdataset[default][myformat::myfile.txt]
38\stopTEX
39
40%% NO SETUP BTX:APA:LEFTTEXT SO THE FOLLOWING DOES NOT WORK:
41%%
42%% If you want to add information to an entry at runtime you can pass so called user
43%% variables with the \type {\cite} command. The following example demonstrates
44%% this. First we define a dataset:
45%%
46%% \startbuffer
47%% \startbuffer [knuth]
48%% @Book{knuth-texbook,
49%%     title     = {The TeXbook},
50%%     author    = {Knuth, Donald Ervin},
51%%     isbn      = {0-201-13447-0},
52%%     series    = {Computers {\&} Typesetting},
53%%     volume    = {A},
54%%     year      = {1986},
55%%     publisher = {Addison Wesley},
56%%     address   = {Reading, MA},
57%% }
58%% \stopbuffer
59%%
60%% \definebtxdataset[knuth]
61%% \usebtxdataset [knuth] [knuth.buffer]
62%% \definebtxrendering[knuth][dataset=knuth]
63%% \stopbuffer
64%%
65%% \typeTEXbuffer
66%% \getbuffer
67%%
68%% \startbuffer[setup]
69%% \startsetups btx:apa:lefttext
70%%     \currentbtxlefttext
71%%     \btxspace
72%%     \btxdoifelseuservariable {notabene} {
73%%         {\bs \currentbtxuservariable{notabene}}
74%%     } {
75%%         % nothing
76%%     }
77%%     \btxspace
78%% \stopsetups
79%% \stopbuffer
80%%
81%% \getbuffer[setup]
82%%
83%% \startbuffer
84%% We all know the \TeX book by Don Knuth \citation [reference=knuth::knuth-texbook,
85%% lefttext={\bf >}] [notabene=Well known to \TEX\ users:].
86%% \stopbuffer
87%%
88%% We use this example where we use \type {\citation} instead of \type {\cite} because
89%% it is more tolerant with spaces. Because we pass user variables as second argument
90%% the first argument also has to be a key|/|value set.
91%%
92%% \typeTEXbuffer
93%%
94%% \getbuffer
95%%
96%% The list is typeset using:
97%%
98%% \startbuffer
99%% \placelistofpublications [knuth] [criterium=all]
100%% \stopbuffer
101%%
102%% \typeTEXbuffer
103%%
104%% and looks like this:
105%%
106%% \getbuffer
107%%
108%% The injection of the user variables is up to you. Here we hooked it into an
109%% existing setup that we overload:
110%%
111%% \typeTEXbuffer [setup]
112%%
113%% The \type {lefttext} and \type {righttext} variables are also kept with the
114%% entry but these are checked for automatically. In this case it means that
115%% when no \type {lefttext} is specified, the \type {notabene} doesn't show up.
116
117\stopchapter
118
119\stopcomponent
120