strc-usr.mkiv /size: 5495 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=strc-bkm,
3
%D version=2009.04.01,
4
%D title=\CONTEXT\ Structure Macros,
5
%D subtitle=Bookmarks,
6
%D author=Wolfgang Schuster,
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
\writestatus
{
loading
}{
ConTeXt
Structure
Macros
/
Userdata
}
15 16
\registerctxluafile
{
strc
-
usr
}{}
17 18
%D It's a bit like blocks that also use buffers but more lightweight and with
19
%D inplace settings.
20
%D
21
%D \starttyping
22
%D \defineuserdata [test] [style=italic]
23
%D
24
%D \samplefile{klein}
25
%D
26
%D \startuserdata [before=\blank,after=\blank,color=red]
27
%D \samplefile{greenfield}
28
%D \stopuserdata
29
%D
30
%D \samplefile{sapolsky}
31
%D
32
%D \startuserdata [test]
33
%D \samplefile{bryson}
34
%D \stopuserdata
35
%D
36
%D \samplefile{jojomayer}
37
%D
38
%D \startuserdata [test] [before=\blank,after=\blank,color=red]
39
%D \samplefile{linden}
40
%D \stopuserdata
41
%D
42
%D \samplefile{montgomery}
43
%D \stoptyping
44
%D
45
%D Or from \LUA:
46
%D
47
%D \starttyping
48
%D \startluacode
49
%D context.startuserdata({color="blue"})
50
%D context.samplefile("klein")
51
%D context.stopuserdata()
52
%D \stopluacode
53
%D \stoptyping
54
%D
55
%D An example of an alternative:
56
%D
57
%D \starttyping
58
%D \defineuserdataalternative [epigraph] [renderingsetup=userdata:epigraph]
59
%D
60
%D \startsetups [userdata:epigraph]
61
%D \startframedtext [location=right,frame=off,align={flushleft,broad},style=\tfx,offset=.25ex,width=.5\textwidth]
62
%D \begstrut\inlinebuffer[userdata]\endstrut
63
%D \hairline
64
%D \wordright{\userdataparameter{author}}
65
%D \stopframedtext
66
%D \stopsetups
67
%D
68
%D \defineuserdata
69
%D [epigraph]
70
%D [alternative=epigraph]
71
%D
72
%D \startuserdata [epigraph] [author={Sean B. Carrol}]
73
%D The fraction of fossil olfactory receptor genes is significantly higher in
74
%D all species with full color vision. This suggests that the evolution of
75
%D trichromatic vision --- which allows these primates to detect food, mates,
76
%D and danger with visual cues --- has reduced their reliance on the sense of
77
%D smell.
78
%D \stopuserdata
79
%D
80
%D \startuserdata [epigraph] [author={Sean B. Carrol}]
81
%D \samplefile{carrol}
82
%D \stopuserdata
83
%D \stoptyping
84 85
\unprotect
86 87
\installnamespace
{
userdata
}
88
\installnamespace
{
userdataalternative
}
89
\installnamespace
{
userdatarenderings
}
90 91
\installcommandhandler
\????userdata
{
userdata
}
\????userdata
92
\installcommandhandler
\????userdataalternative
{
userdataalternative
}
\????userdataalternative
93 94
\unexpanded
\def
\startuserdata
95
{
\begingroup
96
\let
\currentuserdata
\empty
97
\doifelsenextoptionalcs
\userdata_start_delayed
\userdata_start_indeed
}
98 99
% This variant works only when the userdata instance exists while the assignment check
100
% can also be used with undefined instances which falls back to the global settings.
101
%
102
% \def\userdata_start_delayed[#1]%
103
% {\ifcsname\nameduserdatahash{\detokenize\expandafter{\normalexpanded{#1}}}\s!parent\endcsname
104
% \expandafter\userdata_start_delayed_name
105
% \else
106
% \expandafter\userdata_start_delayed_parameters
107
% \fi[#1]}
108 109
\def
\userdata_start_delayed
[#
1
]
%
110
{
\doifelseassignmentcs
{
#
1
}
%
111
\userdata_start_delayed_parameters
112
\userdata_start_delayed_name
113
[#
1
]
}
114 115
\def
\userdata_start_delayed_parameters
[#
1
]
%
116
{
\setupcurrentuserdata
[#
1
]
%
117
\userdata_start_indeed
}
118 119
\def
\userdata_start_delayed_name
[#
1
]
%
120
{
\edef
\currentuserdata
{
#
1
}
%
121
\checkuserdataparent
122
\doifelsenextoptionalcs
\userdata_start_delayed_parameters
\userdata_start_indeed
}
123 124
\def
\userdata_start_indeed
125
{
\grabbufferdatadirect
\s!userdata
{
\csstring
\startuserdata
}{
\csstring
\stopuserdata
}}
126 127
% \unexpanded\def\stopuserdata
128
% {\useuserdatastyleandcolor\c!style\c!color
129
% \usealignparameter\userdataparameter
130
% \edef\currentuserdataalternative{\userdataparameter\c!alternative}%
131
% \ifcsname\currentuserdataalternativehash\s!parent\endcsname \else
132
% \let\currentuserdataalternative\s!default
133
% \fi
134
% \edef\p_renderingsetup{\userdataalternativeparameter\c!renderingsetup}%
135
% \directsetup\p_renderingsetup
136
% \endgroup}
137 138
\unexpanded
\def
\stopuserdata
139
{
\userdataparameter
\c!before
% HH: moved, so we obey the outer spacing
140
\dostarttagged
\t!userdata
\currentuserdata
% HH: added, maybe move up ?
141
\begingroup
142
\useuserdatastyleandcolor
\c!style\c!color
143
\usealignparameter
\userdataparameter
% HH: added
144
\edef
\currentuserdataalternative
{
\userdataparameter
\c!alternative
}
%
145
\ifcsname
\currentuserdataalternativehash
\s!parent
\endcsname
\else
146
\let
\currentuserdataalternative
\s!default
147
\fi
148
\usesetupsparameter
\userdataparameter
149
\edef
\p_renderingsetup
{
\userdataalternativeparameter
\c!renderingsetup
}
%
150
\directsetup
\p_renderingsetup
151
\endgroup
152
\dostoptagged
153
\userdataparameter
\c!after
% HH: moved
154
\endgroup
}
155 156
\unexpanded
\def
\getuserdata
157
{
\getbufferdata
[
\s!userdata
]
}
158 159
\unexpanded
\def
\getinlineuserdata
160
{
\inlinebuffer
[
\s!userdata
]
}
161 162
\defineuserdataalternative
163
[
\s!default
]
164
[
\c!renderingsetup
=
\????userdatarenderings
:
\s!default
]
165 166
% \startsetups[\????userdatarenderings:\s!default]
167
% \userdataparameter\c!before
168
% \usesetupsparameter\userdataparameter
169
% \getbufferdata[\s!userdata]
170
% \userdataparameter\c!after
171
% \stopsetups
172 173
\startsetups
[
\????userdatarenderings
:
\s!default
]
174
\getuserdata
175
\stopsetups
176 177
\setupuserdata
178
[
\c!alternative
=
\s!default
]
179 180
\protect
181