1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
%D \module
%D [ file=font-sty,
%D version=2011.01.13, % (copied fron font-ini)
%D title=\CONTEXT\ Font Macros,
%D subtitle=Styles,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\writestatus{loading}{ConTeXt Font Macros / Styles}
\unprotect
%D \macros
%D {definealternativestyle}
%D
%D In the main modules we are going to implement lots of
%D parameterized commands and one of these parameters will
%D concern the font to use. To suit consistent use of fonts we
%D here implement a mechanism for defining the keywords that
%D present a particular style or alternative.
%D
%D \starttyping
%D \definealternativestyle [keywords] [\style] [\nostyle]
%D \stoptyping
%D
%D The first command is used in the normal textflow, while the
%D second command takes care of headings and alike. Consider
%D the next two definitions:
%D
%D \starttyping
%D \definealternativestyle [bold] [\bf] []
%D \definealternativestyle [cap] [\cap] [\cap]
%D \stoptyping
%D
%D A change \type{\bf} in a heading which is to be set in
%D \type{\tfd} does not look that well, so therefore we leave
%D the second argument of \type{\definealternativestyle} empty.
%D When we capatalize characters using the pseudo small cap
%D command \type{\cap}, we want this to take effect in both
%D text and headings, which is accomplished by assigning both
%D arguments.
\installcorenamespace{alternativestyles}
\setnewconstant \c_font_current_alternative_style_index \plusone
\unexpanded\def\definealternativestyle
{\dotripleempty\font_basics_define_alternative_style}
\def\font_basics_define_alternative_style[#commands][#variantone][#varianttwo]%
{\processcommalist[#commands]{\font_basics_define_alternative_style_indeed{#variantone}{#varianttwo}}}
\let\definestyle\definealternativestyle % later redefined
\def\font_basics_define_alternative_style_indeed#variantone#varianttwo#command%
{\ifcsname#command\endcsname
% no redefinition
\else
\setuvalue{#command}{\groupedcommand{#variantone}{}}%
\fi
\setvalue{\??alternativestyles#command}{\font_helpers_apply_alternative_style{#variantone}{#varianttwo}}}%
\def\font_helpers_apply_alternative_style
{\ifcase\c_font_current_alternative_style_index
\expandafter\gobbletwoarguments
\or
\expandafter\firstoftwoarguments
\or
\expandafter\secondoftwoarguments
\else
\expandafter\firstoftwoarguments
\fi}
\def\applyalternativestyle#name% public
{\ifcsname\??alternativestyles#name\endcsname\csname\??alternativestyles#name\expandafter\endcsname\fi}
%D Maybe too geneneric, but probably ok is the following. (Maybe one
%D day we will use a dedicated grouped command for styles.)
% \appendtoks
% \let\groupedcommand\thirdofthreearguments
% \to \everysimplifycommands
%D This command also defines the keyword as command. This means
%D that the example definition of \type{bold} we gave before,
%D results in a command \type{\bold} which can be used as:
%D
%D \startbuffer
%D He's a \bold{bold} man with a {\bold head}.
%D \stopbuffer
%D
%D \typebuffer
%D
%D or
%D
%D \startexample
%D \definealternativestyle[bold][\bf][]\getbuffer
%D \stopexample
%D
%D Such definitions are of course unwanted for \type{\cap}
%D because this would result in an endless recursive call.
%D Therefore we check on the existance of both the command and
%D the substitution. The latter is needed because for instance
%D \type{\type} is an entirely diferent command. That command
%D handles verbatim, while the style command would just switch
%D to teletype font. This is just an example of a tricky
%D naming coincidence.
%D \macros
%D {doconvertfont,noconvertfont,
%D dontconvertfont,redoconvertfont}
%D
%D After having defined such keywords, we can call for them by
%D using
%D
%D \starttyping
%D \doconvertfont{keyword}{text}
%D \stoptyping
%D
%D We deliberately pass an argument. This enables us to
%D assign converters that handle one argument, like
%D \type{\cap}.
%D
%D By default the first specification is used to set the style,
%D exept when we say \type{\dontconvertfont}, after which the
%D second specification is used. We can also directly call for
%D \type{\noconvertfont}. In nested calls, we can restore the
%D conversion by saying \type{\redoconvertfont}.
%D These commands are not grouped! Grouping is most probably
%D done by the calling macro's and would lead to unnecessary
%D overhead.
\let\m_current_convert_font \empty
\let\m_current_convert_font_dt\empty
\unexpanded\def\doconvertfont#specification% takes second argument / this command is obsolete
{\edef\m_current_convert_font{#specification}%
\ifx\m_current_convert_font\empty
%\expandafter\firstofoneargument
\else
\expandafter\font_helpers_do_convert_font
\fi}
\def\font_helpers_do_convert_font
{\edef\m_current_convert_font_dt{\detokenize\expandafter{\m_current_convert_font}}%
\ifcsname\??alternativestyles\m_current_convert_font_dt\endcsname
\csname\??alternativestyles\m_current_convert_font_dt\expandafter\endcsname
\else\ifcsname\m_current_convert_font_dt\endcsname
\csname\m_current_convert_font_dt\expandafter\endcsname
\else
\doubleexpandafter\m_current_convert_font
\fi\fi}
%D Low level switches (downward compatible, but we keep them as one can use
%D them in styles):
%D
%D \starttyping
%D \usemodule[abr-02]
%D \setuphead[chapter][style=\bfb]
%D \setupfooter[style=\dontconvertfont\bf]
%D \chapter{This is \TEX}
%D \stoptyping
\unexpanded\def\dontconvertfont{\c_font_current_alternative_style_index\plustwo} % needs checking in usage
\unexpanded\def\redoconvertfont{\c_font_current_alternative_style_index\plusone} % needs checking in usage
%D The new one:
\unexpanded\def\dousestyleparameter#value%
{\edef\currentstyleparameter{#value}%
\ifx\currentstyleparameter\empty\else
\expandafter\dousecurrentstyleparameter
\fi}
\unexpanded\def\dousestylehashparameter#hash#parameter%
{\ifcsname#hash#parameter\endcsname
\expandafter\dousestyleparameter\csname#hash#parameter\endcsname
\fi}
\unexpanded\def\dousecurrentstyleparameter % empty check outside here
{\edef\detokenizedstyleparameter{\detokenize\expandafter{\currentstyleparameter}}%
\settrue\fontattributeisset % reset is done elsewhere
\ifcsname\??alternativestyles\detokenizedstyleparameter\endcsname
\csname\??alternativestyles\detokenizedstyleparameter\endcsname
\else\ifcsname\detokenizedstyleparameter\endcsname
\csname\detokenizedstyleparameter\endcsname
\else
\currentstyleparameter
\fi\fi}
\let\dosetfontattribute\dousestylehashparameter % for a while
%D New commands (not yet interfaced):
%D
%D \startbuffer
%D \definestyle[one][style=bold,color=darkblue]
%D
%D test \one{test} test
%D test \style[one]{test} test
%D test \style[color=red]{test} test
%D test \style[Serif at 20pt]{test} test
%D \stopbuffer
%D
%D \typebuffer \startlines \getbuffer \stoplines
% definitions .. no tagging here
\installcorenamespace{style}
\installcorenamespace{stylecheck}
\installcommandhandler \??style {style} \??style
\setupstyle
[%\c!style=,
%\c!color=,
\c!method=\v!command]
\appendtoks
\letvalue{\??stylecheck\currentstyle}\relax
\edef\p_method{\styleparameter\c!method}%
\ifx\p_method\v!command
\setuevalue{\e!start\currentstyle}{\font_styles_apply_start{\currentstyle}}%
\setuevalue{\e!stop \currentstyle}{\font_styles_apply_stop}%
\setuevalue {\currentstyle}{\font_styles_apply_grouped{\currentstyle}}% no longer groupedcommand here
\fi
\to \everydefinestyle
\unexpanded\def\font_styles_apply_start#name%
{\begingroup
\font_styles_use_defined{#name}}
\unexpanded\def\font_styles_apply_stop
{\endgroup}
\unexpanded\def\font_styles_apply_grouped#name% assumes that the next is { or \bgroup
{\bgroup
\def\g_style{\font_styles_use_defined{#name}}%
\afterassignment\g_style
\let\nexttoken}
\unexpanded\def\font_styles_use_defined#name%
{\edef\currentstyle{#name}%
\usestylestyleandcolor\c!style\c!color}
\unexpanded\def\font_styles_use_generic#specification%
{\let\currentstyle\s!unknown % reasonable generic tag
\letstyleparameter\c!style\empty
\letstyleparameter\c!color\empty
\setupcurrentstyle[#specification]%
\usestylestyleandcolor\c!style\c!color}
% commands
\installcorenamespace{styleargument}
\unexpanded\def\style[#name]% as this is can be a switch we use groupedcommand
{\csname\??styleargument
\ifcsname\??stylecheck#name\endcsname
2% defined as style
\else\ifcsname#name\endcsname
1% defined as command
\else
3% specification
\fi\fi
\endcsname{#name}}
\setvalue{\??styleargument1}#name%
{\groupedcommand{\csname#name\endcsname}{}}
\setvalue{\??styleargument2}#name%
{\groupedcommand{\font_styles_use_defined{#name}}{}} % or {\font_styles_apply_grouped{#name}}
\setvalue{\??styleargument3}#specification%
{\doifassignmentelse{#specification}\font_styles_assignment\font_styles_direct{#specification}}
\def\font_styles_assignment#specification{\groupedcommand{\font_styles_use_generic{#specification}}{}}
\def\font_styles_direct #specification{\groupedcommand{\definedfont[#specification]}{}}
% environments
\installcorenamespace{styleenvironment}
\unexpanded\def\startstyle[#name]%
{\begingroup
\csname\??styleenvironment
\ifcsname\??stylecheck#name\endcsname
2% defined as style
\else\ifcsname#name\endcsname
1% defined as command
\else
3% specification
\fi\fi
\endcsname{#name}}
\unexpanded\def\stopstyle
{\endgroup
\autoinsertnextspace} % will be configurable, maybe also in \definestartstop
\setvalue{\??styleenvironment1}#name%
{\csname#name\endcsname}
\setvalue{\??styleenvironment2}#name%
{\font_styles_use_defined{#name}}
\setvalue{\??styleenvironment3}#specification%
{\doifassignmentelse{#specification}\font_styles_start_assignment\font_styles_start_direct{#specification}}
\def\font_styles_start_assignment#specification{\font_styles_use_generic{#specification}}
\def\font_styles_start_direct #specification{\definedfont[#specification]\relax}
%D Still experimental (might even go away).
% \definestylecollection[mine]
% \definestyleinstance[mine][default][sorry]
% \definestyleinstance[mine][tt][bs][ttbs:\rm\sl]
% \definestyleinstance[mine][tt][bf][ttbf:\rm\sl]
% \definestyleinstance[mine][bf][\sl]
% \definestyleinstance[mine][sl][\tt]
% {\bf test \mine test \sl test \mine test \bs oeps \mine oeps {\tt test \mine \bf test}}
\installcorenamespace{stylecollection}
\unexpanded\def\definestylecollection
{\dosingleargument\font_styles_define_style_collection}
\def\font_styles_define_style_collection[#name]%
{\iffirstargument
\setuvalue{#name}{\styleinstance[#name]}%
\def\font_styles_define_style_collection_a#style%
{\def\font_styles_define_style_collection_b#alternative{\letbeundefined{\??stylecollection#name:#style:#alternative}}%
\font_helpers_process_alternative_list\font_styles_define_style_collection_b
\font_styles_define_style_collection_b\s!default}%
\font_helpers_process_style_list\font_styles_define_style_collection_a
\font_styles_define_style_collection_a\s!default
\fi}
\unexpanded\def\definestyleinstance
{\doquadrupleargument\font_styles_define_style_instance}
\def\font_styles_define_style_instance[#instance][#2][#3][#4]% [name] [rm|ss|tt|..] [sl|bf|...] [whatever]
{\iffirstargument
\ifcsname#1\endcsname\else\font_styles_define_style_collection[#instance]\fi
\fi
\iffourthargument
\setvalue{\??stylecollection#instance:#2:#3}{#4}%
\else\ifthirdargument
\setvalue{\??stylecollection#instance::#2}{#3}%
\else\ifsecondargument
\letvalueempty{\??stylecollection#instance::#2}%
\fi\fi\fi}
% \unexpanded\def\styleinstance[#instance]% will be made faster
% {%\begingroup\normalexpanded{\noexpand\infofont[#1:\fontstyle:\fontalternative]}\endgroup
% \executeifdefined{\??stylecollection#instance:\fontstyle:\fontalternative}%
% {\executeifdefined{\??stylecollection#instance:\fontstyle:\s!default}%
% {\executeifdefined{\??stylecollection#instance::\fontalternative}
% {\getvalue {\??stylecollection#instance::\s!default}}}}}
\unexpanded\def\styleinstance[#instance]%
{\csname\??stylecollection#instance:%
\ifcsname\??stylecollection#instance:\fontstyle:\fontalternative\endcsname
\fontstyle:\fontalternative
\else\ifcsname\??stylecollection#instance:\fontstyle:\s!default\endcsname
\fontstyle:\s!default
\else\ifcsname\??stylecollection#instance::\fontalternative\endcsname
:\fontalternative
\else
:\s!default
\fi\fi\fi
\endcsname}
%D Variant selectors
%D
%D \starttyping
%D \mathematics {\vsone{\utfchar{0x2229}}}
%D \mathematics {\utfchar{0x2229}\vsone{}}
%D \stoptyping
\unexpanded\edef\vsone#character{#character\normalUchar"FE00 } % used
\unexpanded\edef\vstwo#character{#character\normalUchar"FE01 } % not used but handy for testing
%D For historic reasons we keep the following around but they are no longer
%D that relevant for \MKIV.
\unexpanded\def\doattributes#1#2#3#4%
{\begingroup % geen \bgroup, anders in mathmode lege \hbox
\dousestylehashparameter{#1}{#2}%
\dousecolorhashparameter{#1}{#3}%
#4%
\endgroup}
\unexpanded\def\dostartattributes#1#2#3%
{\begingroup % geen \bgroup, anders in mathmode lege \hbox
\dousestylehashparameter{#1}{#2}%
\dousecolorhashparameter{#1}{#3}}
\let\dostopattributes\endgroup
\protect \endinput
|