symb-ini.mkiv /size: 10 Kb    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=symb-ini,
3%D        version=1998.07.20,
4%D          title=\CONTEXT\ Symbol Libraries,
5%D       subtitle=Basic Symbols Commands,
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%D The macros described here used to be part of the \type {core-con} module. I
15%D decided to move them here when symbolsets saw the light. Let their light shine.
16
17\writestatus{loading}{ConTeXt Symbol Libraries / Initialization}
18
19\registerctxluafile{symb-ini}{}
20
21\unprotect
22
23%D \macros
24%D   {definesymbol, symbol}
25%D
26%D Converting numbers or levels into a character, romannumeral, symbol or something
27%D else, is supported by many \CONTEXT\ commands. Therefore we need a mechanism for
28%D linking such numbers to their counterparts.
29%D
30%D First we take care of symbols. These are for instance used in enumerations and
31%D itemizations. We have:
32%D
33%D \showsetup{definesymbol}
34%D \showsetup{symbol}
35%D
36%D Symbols are simply linked to a tag. Such tags can be numbers or strings.
37%D
38%D \starttyping
39%D \definesymbol [1]       [$\bullet$]
40%D \definesymbol [level 5] [$\star$]
41%D \stoptyping
42
43\installcorenamespace{symbol}
44\installcorenamespace{symbols}
45\installcorenamespace{symbolset}
46\installcorenamespace{symboldefault}
47
48%D For now we only have one option.
49
50\installparameterhandler\??symbols {symbols}
51\installsetuphandler    \??symbols {symbols}
52
53\appendtoks
54   \doifelse{\symbolsparameter\c!stylealternative}\v!math
55     \settrue\setfalse\prefermathovertextchar
56\to \everysetupsymbols
57
58\setupsymbols
59  [\c!stylealternative=\v!text]
60
61\let\currentsymbol   \empty
62\let\currentsymbolset\empty
63
64\newtoks\t_symb_setups
65
66\let\m_symb_current_set\empty
67
68\newconditional\c_symb_found
69
70\newtoks\everysymbol
71
72%D We don't use the commandhandler as symbols have their own subsystem for resolving
73%D values.
74
75\unexpanded\def\definesymbol
76  {\dotripleempty\symb_define}
77
78\def\symb_define[#1][#2][#3]% class name meaning
79  {\ifthirdargument
80     \setvalue{\??symbol#1:#2}{#3}%
81     \doifsomething{#1}{\addvalue{\??symbolset#1}{#2}}%
82   \else
83     \setvalue{\??symbol\m_symb_current_set:#1}{#2}%
84     \addvalue{\??symbolset\m_symb_current_set}{#1}%
85   \fi}
86
87\unexpanded\def\doifelseinsymbolset#1#2{\ifcsname\??symbol#1:#2\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
88\unexpanded\def\doifinsymbolset    #1#2{\ifcsname\??symbol#1:#2\endcsname\expandafter\firstofoneargument \else\expandafter\gobbleoneargument   \fi}
89\unexpanded\def\doifelsesymbolset    #1{\ifcsname\??symbolset#1\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
90
91\let\doifinsymbolsetelse\doifelseinsymbolset
92\let\doifsymbolsetelse  \doifelsesymbolset
93
94\letvalue{\??symbolset}\empty
95
96%def\symbolset#1{\csname\??symbolset\ifcsname\??symbolset#1\endcsname#1\fi\endcsname} % no [#1], to be used in commalists etc
97
98\def\symbolset#1{\begincsname\??symbolset#1\endcsname} % no [#1], to be used in commalists etc
99
100%D Since symbols are used frequently in interactive documents, we speed up this one.
101%D Well, that was history, since now we simplified things a bit, because the low
102%D level macros have been sped up every now and then.
103
104% We support both:
105%
106% Test test \symbol[whatever]\ test \symbol[whatever].
107% Test test \symbol{whatever}  test \symbol{whatever}.
108
109\unexpanded\def\symbol
110  {\dontleavehmode % so we can start a paragraph with it
111   \dodoubleempty\symb_place}
112
113\def\symb_place   % so we also handle \symbol{name}
114  {\iffirstargument  % which is nicer with following spaces
115     \expandafter\symb_place_normal
116   \else
117     \expandafter\symb_place_special
118   \fi}
119
120\def\symb_place_normal
121  {\ifsecondargument
122     \expandafter\symb_place_normal_a
123   \else
124     \expandafter\symb_place_normal_b
125   \fi}
126
127% \def\symb_place_normal_a[#1][#2]%
128%   {\edef\currentsymbol{#2}%
129%    \ifcsname\??symbol#1:#2\endcsname
130%       \symb_place_indeed{#1:#2}%
131%    \else
132%      \symb_place_normal_c
133%    \fi}
134
135\def\symb_place_normal_a[#1][#2]%
136  {\edef\currentsymbol{#2}%
137   \ifcsname\??symbol#1:#2\endcsname
138      \symb_place_indeed{#1:#2}% maybe use \lastnamescs
139   \else\ifcsname\??symboldefault#1\endcsname
140      \symb_place_named{#1}% maybe use \lastnamescs
141   \else
142     \symb_place_normal_c
143   \fi\fi}
144
145\def\symb_place_normal_b[#1][#2]%
146  {\edef\currentsymbol{#1}%
147   \ifcsname\??symbol\currentsymbolset:#1\endcsname
148     \symb_place_indeed{\currentsymbolset:#1}%
149   \else
150     \symb_place_normal_c
151   \fi}
152
153\def\symb_place_normal_c
154  {\setfalse\c_symb_found
155   \the\t_symb_setups
156   \ifconditional\c_symb_found \else
157     \symb_place_retry\currentsymbol % hm, isn't this redundant?
158   \fi}
159
160\def\symb_place_special[#1][#2]#3%
161  {\firstargumenttrue
162   \secondargumentfalse
163   \symb_place_normal[#3][]}
164
165\def\symb_place_indeed#1% \relax's prevent lookahead problems
166  {\settrue\c_symb_found
167   \begingroup
168   \the\everysymbol
169   \csname\??symbol#1\endcsname\relax
170   \endgroup}
171
172\letvalue{\??symbol}\firstofoneargument
173
174\def\directsymbol#1#2% no \relax, there can be an argument, see lists
175 %{\csname\??symbol\ifcsname\??symbol#1:#2\endcsname#1:#2\fi\endcsname}
176  {\begincsname\??symbol#1:#2\endcsname}
177
178\unexpanded\def\symb_fetch
179  {\ifconditional\c_symb_found
180     \expandafter\gobbleoneargument
181   \else
182     \expandafter\symb_fetch_indeed
183   \fi}
184
185% \def\symb_fetch_indeed#1%
186%   {\ifcsname\??symbol#1:\currentsymbol\endcsname
187%      \symb_place_indeed{#1:\currentsymbol}%
188%    \fi}
189
190\def\symb_fetch_indeed#1%
191  {\ifcsname\??symbol#1:\currentsymbol\endcsname
192     \symb_place_indeed{#1:\currentsymbol}%
193   \else\ifcsname\??symboldefault#1\endcsname
194     \symb_place_named{#1}%
195   \fi\fi}
196
197\def\symb_place_named#1% \relax's prevent lookahead problems
198  {\begingroup
199   \setbox\scratchbox\hbox\bgroup
200     \the\everysymbol
201     \getglyphstyled
202       {\csname\??symboldefault#1\endcsname}%
203       {\tochar{n:\currentsymbol}}%
204     \relax
205   \egroup
206   \ifdim\wd\scratchbox>\zeropoint
207     \unhbox\scratchbox
208     \endgroup
209     \setxvalue{\??symbol#1:\currentsymbol}%
210       {\symb_place_named_indeed{#1}{\currentsymbol}}%
211     \settrue\c_symb_found
212   \else
213     \endgroup
214   \fi}
215
216\unexpanded\def\symb_place_named_indeed#1#2% \relax's prevent lookahead problems
217  {\settrue\c_symb_found
218   \begingroup
219   \the\everysymbol
220   \getglyphstyled
221     {\csname\??symboldefault#1\endcsname}%
222     {\tochar{n:#2}}%
223   \relax
224   \endgroup}
225
226\def\symb_place_retry#1%
227  {\ifcsname\??symbol:#1\endcsname
228     \symb_place_indeed{:#1}%
229   \else
230     #1%
231   \fi}
232
233%D \macros
234%D   {definefiguresymbol}
235%D
236%D To simplify defining figure symbols, we offer:
237%D
238%D \showsetup{definefiguresymbol}
239%D
240%D By default, such symbols scale along the current bodyfont size or running font
241%D size (which is better).
242
243\def\defaultsymbolfactor{10}
244\def\defaultsymbolheight{1.25ex}
245
246\unexpanded\def\figuresymbol
247  {\dodoubleempty\symb_figure}
248
249\ifdefined\externalfigure       \else \def\externalfigure[#1][#2]{#1} \fi
250\ifdefined\resetexternalfigures \else \let\resetexternalfigures\relax \fi
251
252\def\symb_figure[#1][% #2]%
253  {\externalfigure[#1][\c!reset=\v!yes,\c!symbol=\v!yes,\c!height=\defaultsymbolheight,}% #2]}
254
255\appendtoks \resetexternalfigures \to \everysymbol
256
257\unexpanded\def\definefiguresymbol
258  {\dotripleempty\symb_figure_define}
259
260\def\symb_figure_define[#1][#2][#3]%
261  {\ifsecondargument
262     \definesymbol[#1][{\symb_figure[#2][#3]}]%
263   \fi}
264
265%D \macros
266%D   {doifsymboldefinedelse}
267%D
268%D A handy private one:
269
270\def\symb_fetch_first
271  {\ifconditional\c_symb_found
272     \expandafter\gobbleoneargument
273   \else
274     \expandafter\symb_fetch_first_indeed
275   \fi}
276
277\def\symb_fetch_first_indeed#1%
278  {\doifinsymbolset{#1}\currentsymbol{\settrue\c_symb_found}}
279
280\def\symb_fetch_second#1%
281  {\doifinsymbolset\empty\currentsymbol{\settrue\c_symb_found}}
282
283\unexpanded\def\doifelsesymboldefined#1%
284  {\begingroup
285   \edef\currentsymbol{#1}%
286   \let\symb_fetch\symb_fetch_first
287   \setfalse\c_symb_found
288   \the\t_symb_setups
289   \ifconditional\c_symb_found
290     \endgroup\expandafter\firstoftwoarguments
291   \else
292     \symb_fetch_second\currentsymbol
293     \ifconditional\c_symb_found
294       \endgroup\doubleexpandafter\firstoftwoarguments
295     \else
296       \endgroup\doubleexpandafter\secondoftwoarguments
297     \fi
298   \fi}
299
300\let\doifsymboldefinedelse\doifelsesymboldefined
301
302%D \macros
303%D   {setupsymbolset,startsymbolset}
304%D
305%D From these macro definitions one can deduce that symbols can be grouped in
306%D symbol sets:
307%D
308%D \starttyping
309%D \startsymbolset [navigation 1]
310%D   \definefiguresymbol [Next] [mp-symb.1]
311%D   \definefiguresymbol [Prev] [mp-symb.2]
312%D \stopsymbolset
313%D \stoptyping
314%D
315%D Such a symbol can be typeset with:
316%D
317%D \starttyping
318%D \setupsymbolset[navigation 1]\symbol[Next]
319%D \stoptyping
320%D
321%D or simply:
322%D
323%D \starttyping
324%D \symbol[navigation 1][Next]
325%D \stoptyping
326%D
327%D Formally:
328%D
329%D \showsetup{setupsymbolset}
330%D \showsetup{startsymbolset}
331
332\installcorenamespace{symbolsets}
333
334% \unexpanded\def\startsymbolset[#1]%
335%   {\pushmacro\m_symb_current_set
336%    \def\m_symb_current_set{#1}}
337
338% maybe a parameterhandler:
339
340\unexpanded\def\startsymbolset
341  {\dodoubleargument\symb_start_set}
342
343\def\symb_start_set[#1][#2]%
344  {\pushmacro\m_symb_current_set
345   \def\m_symb_current_set{#1}%
346   \ifsecondargument
347     \getdummyparameters[\s!font=,#2]%
348     \edef\p_font{\dummyparameter\s!font}%
349     \ifx\p_font\empty\else
350       \letvalue{\??symboldefault#1}\p_font
351     \fi
352   \fi}
353
354\unexpanded\def\stopsymbolset
355  {\popmacro\m_symb_current_set}
356
357\unexpanded\def\setupsymbolset[#1]%
358  {\edef\currentsymbolset{#1}%
359   \ifcsname\??symbolsets\currentsymbolset\endcsname \else
360     \symb_setup_symbol_set
361   \fi}
362
363\def\symb_setup_symbol_set
364  {\normalexpanded{\t_symb_setups{\symb_fetch{\currentsymbolset}\the\t_symb_setups}}%
365   \letvalue{\??symbolsets\currentsymbolset}\empty} % speedup
366
367\unexpanded\def\resetsymbolset
368  {\t_symb_setups\emptytoks}
369
370\unexpanded\def\forcesymbolset[#1]%
371  {\t_symb_setups{\symb_fetch{#1}}}
372
373%D \macros
374%D   {showsymbolset}
375%D
376%D \showsetup{showsymbolset}
377
378\fetchruntimecommand \showsymbolset \f!symb_run
379
380%D \macros
381%D   {usesymbols}
382%D
383%D \showsetup{usesymbols}
384
385\unexpanded\def\usesymbols[#1]{\clf_usesymbols{#1}}
386
387%D As longs as symbols are linked to levels or numbers, we can also use the
388%D conversion mechanism, but in for instance the itemization macros, we prefer
389%D symbols because they can more easier be (partially) redefined.
390
391\protect \endinput
392