typo-prc.mklx /size: 3464 b    last modification: 2023-12-21 09:44
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 category
17%D as processors. This might change. (They are used in publications.)
18
19\registerctxluafile{typo-prc}{autosuffix}
20\registerctxluafile{typo-man}{autosuffix}
21
22\unprotect
23
24%D Processors are used when we cannot easily associate typesetting directives with
25%D (for instance) structural elements. Instead of ending up with numerous additional
26%D 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 for
36%D 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 up
43%D 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
49%D {left}, \type {right}, and \type {command} (the given command takes one
50%D argument).
51
52\installcorenamespace{processor}
53\installcorenamespace{processorcheck}
54
55\installcommandhandler \??processor {processor} \??processor
56
57\mutable\let\currentprocessor\empty % weird that this is needed
58
59\appendtoks
60    \letcsname\??processorcheck\currentprocessor\endcsname\relax
61    \clf_registerstructureprocessor{\currentprocessor}% global, but it permits using processor that are yet undefined
62\to \everydefineprocessor
63
64%D The following command can be used by users but normally it will be invoked behind
65%D the screens. After all, processor prefixes need to be split off first. At the
66%D \LUA\ end we do check for a processor being registered anyway.
67
68\permanent\protected\def\applyprocessor#tag%
69  {\cdef\currentprocessor{#tag}%
70   \ifcsname\??processorcheck\currentprocessor\endcsname
71     \expandafter\typo_processor_apply
72   \else
73     \expandafter\firstofoneargument
74   \fi}
75
76\def\typo_processor_apply
77  {\ifcstok{\processorparameter\c!state}\v!stop
78     \expandafter\firstofoneargument
79   \else
80     \expandafter\typo_processor_apply_indeed
81   \fi}
82
83\def\typo_processor_apply_indeed#content%
84  {\begingroup
85   \useprocessorstyleandcolor\c!style\c!color
86   \processorparameter\c!left
87   \processorparameter\c!command{#content}%
88   \processorparameter\c!right
89   \endgroup}
90
91%D \startbuffer
92%D \defineprocessor[first]        [style=bold]
93%D \defineprocessor[last] [first] [color=red]
94%D
95%D \applyprocessor{first}{hans} \applyprocessor{last}{hagen}
96%D \stopbuffer
97%D
98%D \typebuffer \start \blank \getbuffer \blank \stop
99
100\protect \endinput
101