typo-prc.mkvi /size: 3381 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=typo-prc,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Processors,
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\writestatus{loading}{ConTeXt Typesetting Macros / Processors}
15
16%D For the moment manipulators are loaded here too, as they're in the same
17%D category as processors. This might change. (They are used in publications.)
18
19\registerctxluafile{typo-prc}{}
20\registerctxluafile{typo-man}{}
21
22\unprotect
23
24%D Processors are used when we cannot easily associate typesetting directives
25%D with (for instance) structural elements. Instead of ending up with numerous
26%D additional definitions we can group treatments in so called processors.
27%D
28%D An example of where processors can be used is in separator sets (these are
29%D related to typesetting numbers using structure).
30%D
31%D \starttyping
32%D \defineprocessor[demo][style=\bfb,color=red]
33%D \stoptyping
34%D
35%D This defines a processor named \type {demo}. Such a name ends up as prefix in
36%D for instance:
37%D
38%D \starttyping
39%D \defineseparatorset [demosep] [demo->!,demo->?,demo->!,demo->?] [demo->@]
40%D \stoptyping
41%D
42%D Here the \type {!} and \type {?} are just the seperator characters that end
43%D up between part, chapter, section, etc.\ numbers. The third argument defines the
44%D default. When a separator is inserted, the \type{demo} processor will be applied.
45%D Here the number will be separated by red slightly bigger than normal bold
46%D exclamation marks and questionmarks
47%D
48%D Valid keys for defining a processor are \type {style}, \type {color}, \type {left},
49%D \type {right}, and \type {command} (the given command takes one argument).
50
51\installcorenamespace{processor}
52\installcorenamespace{processorcheck}
53
54\installcommandhandler \??processor {processor} \??processor
55
56\appendtoks
57    \letvalue{\??processorcheck\currentprocessor}\relax
58    \clf_registerstructureprocessor{\currentprocessor}% global, but it permits using processor that are yet undefined
59\to \everydefineprocessor
60
61%D The following command can be used by users but normally it will be
62%D invoked behind the screens. After all, processor prefixes need to
63%D be split off first. At the \LUA\ end we do check for a processor
64%D being registered anyway.
65
66\unexpanded\def\applyprocessor#tag%
67  {\def\currentprocessor{#tag}%
68   \ifcsname\??processorcheck\currentprocessor\endcsname
69     \expandafter\typo_processor_apply
70   \else
71     \expandafter\firstofoneargument
72   \fi}
73
74\def\typo_processor_apply
75  {\edef\p_state{\processorparameter\c!state}%
76   \ifx\p_state\v!stop
77     \expandafter\firstofoneargument
78   \else
79     \expandafter\typo_processor_apply_indeed
80   \fi}
81
82\def\typo_processor_apply_indeed#content%
83  {\begingroup
84   \useprocessorstyleandcolor\c!style\c!color
85   \processorparameter\c!left
86   \processorparameter\c!command{#content}%
87   \processorparameter\c!right
88   \endgroup}
89
90%D \startbuffer
91%D \defineprocessor[first]        [style=bold]
92%D \defineprocessor[last] [first] [color=red]
93%D
94%D \applyprocessor{first}{hans} \applyprocessor{last}{hagen}
95%D \stopbuffer
96%D
97%D \typebuffer \start \blank \getbuffer \blank \stop
98
99\protect \endinput
100