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}{} 23 24\definesystemattribute[replacements][public,global] 25 26%D \startluacode 27%D 28%D -- todo: other nodes (prelude to more experiments with auto dropped caps) 29%D 30%D languages.replacements.add("basics", { 31%D ["aap"] = "monkey", 32%D ["noot"] = "nut", 33%D ["never"] = "forever", 34%D ["newer"] = "cooler", 35%D ["new"] = "cool", 36%D -- ["special"] = "veryspe{>>>}{<<<}{=}cial", 37%D }) 38%D 39%D \stopluacode 40%D 41%D \replaceword[more][this][that] 42%D \replaceword[more][crap][support] 43%D \replaceword[more][---][—] 44%D \replaceword[basics][special][veryspe{>>>}{<<<}{=}cial] 45%D 46%D \starttyping 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 53\unexpanded\def\setreplacements[#1]% 54 {\clf_setreplacements{#1}} 55 56\unexpanded\def\resetreplacements 57 {\c_attr_replacements\attributeunsetvalue} 58 59\unexpanded\def\replaceword 60 {\dotripleempty\languages_replacements_replace} 61 62\unexpanded\def\languages_replacements_replace[#1][#2][#3]% 63 {\ifthirdargument 64 \clf_addreplacements{#1}{#2}{#3}% 65 \else\ifsecondargument 66 \clf_addreplacementslist{#1}{#2}% 67 \fi\fi} 68 69\appendtoks 70 \resetreplacements 71\to \everyresettypesetting 72 73\appendtoks 74 \resetreplacements 75\to \everyinitializeverbatim 76 77\protect \endinput 78 |