toks-map.mkiv /size: 2035 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=toks-map, % experimental moved from toks-ini
3%D        version=2007.03.03,
4%D          title=\CONTEXT\ Token Support,
5%D       subtitle=Initialization,
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 Token Support / Remapping}
15%
16% \registerctxluafile{toks-map}{}
17%
18% \unprotect
19%
20% %D Inspired by a prototype by Taco for Thomas cum suis.
21% %D
22% %D \starttyping
23% %D \defineremapper[babelgreek]
24% %D
25% %D \remapcharacter[babelgreek][`a]{\alpha}
26% %D \remapcharacter[babelgreek][`b]{\beta}
27% %D \remapcharacter[babelgreek][`c]{\gamma}
28% %D \remapcharacter[babelgreek][`d]{OEPS}
29% %D
30% %D \starttext
31% %D
32% %D [\startbabelgreek
33% %D a b c some stuff here \blank[big] oeps b d
34% %D \stopbabelgreek]
35% %D
36% %D [\babelgreek{some stuff here}]
37% %D
38% %D \stoptext
39% %D \stoptyping
40%
41% \unexpanded\def\defineremapper[#1]%
42%   {\setuevalue{\e!start#1}{\toks_start_remapper{#1}}%
43%    \setuevalue{\e!stop #1}{\toks_stop_remapper {#1}}%
44%    \letvalue{#1}\relax
45%    \normalexpanded{\expandafter\def\csname#1\endcsname##1{\csname\e!start#1\endcsname##1\csname\e!stop#1\endcsname}}}
46%
47% \unexpanded\def\toks_start_remapper#1%
48%   {\ctxlua{tokens.collectors.install("#1", "\e!stop#1")}}
49%
50% \unexpanded\def\toks_stop_remapper#1%
51%   {\ctxlua{tokens.collectors.handle("#1",function(str) return tokens.collectors.remapper.convert("#1",str) end, true)}}
52%
53% \unexpanded\def\remaptokens#1%
54%   {\ctxlua{tokens.collectors.handle("#1",function(str) return tokens.collectors.remapper.convert("#1",str) end)}}
55%
56% \unexpanded\def\remapcharacter
57%   {\dodoubleempty\toks_remap_character}
58%
59% \def\toks_remap_character[#1][#2]#3%
60%   {\ctxlua{tokens.collectors.install("store", "ctxlua")}#3%
61%    \ctxlua{tokens.collectors.remapper.store("store","#1",\number#2)}}
62%
63% \protect \endinput
64