1%D \module 2%D [ file=lang-rep, 3%D version=2013.04.28, 4%D title=\CONTEXT\ Language Macros, 5%D subtitle=Substitution, 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 As I needed an example of messing with nodes for the bacho\TEX\ tutorial 15%D I cooked up this. In the end I decided to stick to a simpler example and 16%D just finished this off in case someone really needs it. 17 18\writestatus{loading}{ConTeXt Language Macros / Replacements} 19 20\unprotect 21 22\registerctxluafile{lang-rep}{autosuffix} 23 24\definesystemattribute[replacements][public,global] 25 26%D \starttyping 27%D \startluacode 28%D 29%D -- todo: other nodes (prelude to more experiments with auto dropped caps) 30%D 31%D languages.replacements.add("basics", { 32%D ["aap"] = "monkey", 33%D ["noot"] = "nut", 34%D ["never"] = "forever", 35%D ["newer"] = "cooler", 36%D ["new"] = "cool", 37%D -- ["special"] = "veryspe{>>>}{<<<}{=}cial", 38%D }) 39%D 40%D \stopluacode 41%D 42%D \replaceword[more][this][that] 43%D \replaceword[more][crap][support] 44%D \replaceword[more][---][—] 45%D \replaceword[basics][special][veryspe{>>>}{<<<}{=}cial] 46%D 47%D \start \setreplacements[basics] What the heck, it's now or never, isn't it new? \par \stop 48%D \start \setreplacements[more] Do we --- {\it really} --- need this kind of crap? \par \stop 49%D \start \setreplacements[basics] All kinds of special thingies! \par \stop 50%D \start \setreplacements[basics] \hsize1mm special \par \stop 51%D \stoptyping 52%D 53%D Only in \LUA, functions: 54%D 55%D \startluacode 56%D languages.replacements.add("basics", { 57%D ["one"] = "cool", 58%D ["two"] = function(s) 59%D return "warm" 60%D end 61%D }) 62%D \stopluacode 63%D 64%D \starttyping 65%D \start \setreplacements[basics] It's one in here! \stop \par 66%D \start \setreplacements[basics] It's two in here! \stop \par 67%D \stoptyping 68 69\permanent\protected\def\setreplacements[#1]% 70 {{#1}} 71 72\permanent\protected\def\resetreplacements 73 {\c_attr_replacements\attributeunsetvalue} 74 75\permanent\tolerant\protected\def\replaceword[#1]#*[#S#2]#*[#S#3]% 76 {\ifarguments\or\or 77 {#1}{#2}% 78 \or 79 {#1}{#2}{#3}% 80 \fi} 81 82\appendtoks 83 \resetreplacements 84\to \everyresettypesetting 85 86\appendtoks 87 \resetreplacements 88\to \everyinitializeverbatim 89 90\protect \endinput 91 |