1%D \module 2%D [ file=lang-ovl, 3%D version=2016.02.03, % about that time (maybe earlier) 4%D title=\CONTEXT\ Typesetting Macros, 5%D subtitle=Overloads, 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 / Overloads} 15 16\unprotect 17 18%D See \LUA\ file for comments. I'll probably never use this code outside the 19%D project where it had some experimental use. (Occasionally we do some spell 20%D checking and suspicious word usage marking.) So there is not much documentation 21%D here. Keep in mind that overloading only makes sense for content that gets 22%D replaced as otherwise normal attributes make more sense. Using this otherwise 23%D is weird but one never knows what users come up with. 24 25%D Todo: compact fonts. 26 27\registerctxluafile{typo-ovl}{autosuffix} 28 29\definesystemattribute[overloads][public,global] 30 31\installcorenamespace{overloads} 32 33%D Watch how we abuse highlights. 34 35\newinteger\c_typo_overload_font_id 36 37\protected\def\typo_overloads_define#1% 38 {\begingroup 39 % we pack so we avoid interference (and for sure don't process!) 40 \setbox\scratchbox\hpack\bgroup 41 \global\c_typo_overload_font_id\fontid\font 42 \resetallattributes % so we only change what gets set 43 \highlight[#1]% 44 \signalcharacter 45 \global\c_typo_overload_font_id 46 \ifnum\c_typo_overload_font_id=\fontid\font 47 \zerocount 48 \else 49 \fontid\font 50 \fi 51 \egroup 52 \global\expandafter\chardef\csname\??overloads#1\endcsname 53 {#1}\c_typo_overload_font_id\scratchbox 54 \endgroup} 55 56\permanent\protected\def\setoverloads[#1]% 57 {\ifcsname\??overloads#1\endcsname\else 58 \typo_overloads_define{#1}% 59 \fi 60 \c_attr_overloads\csname\??overloads#1\endcsname} 61 62\permanent\protected\def\registeroverloads[#1]% 63 {\ifcsname\??overloads#1\endcsname\else 64 \typo_overloads_define{#1}% 65 \fi} 66 67\permanent\protected\def\resetoverloads 68 {\c_attr_overloads\attributeunsetvalue} 69 70%D We hook this into the replacement module, probably the only place where it makes 71%D sense. Here is an adapted version of an example: 72%D 73%D \starttyping 74%D \replaceword[basics][new] [old] 75%D \replaceword[basics][now] [hl3->never] 76%D \replaceword[basics][never][now] 77%D \replaceword[basics][heck] [] 78%D 79%D \definehighlight[hl1][style={\setbar[underbar]\red\setcharactercasing[WORD]\bf}] 80%D \definehighlight[hl2][style={\setbar[overbar]\blue\setcharactercasing[Words]}] 81%D \definehighlight[hl3][style={\setbar[overstrike]\green\bs}] 82%D 83%D \registeroverloads[hl1] 84%D \registeroverloads[hl2] 85%D \registeroverloads[hl3] 86%D 87%D \start \setreplacements[basics][hl1] What the heck, it's now or never, isn't it new? \stop \par 88%D \start \setreplacements[basics][hl2] What the heck, it's now or never, isn't it new? \stop \par 89%D \start \setreplacements[basics][hl1] What the heck, it's now or never, isn't it new? \stop \par 90%D \start \setreplacements[basics] What the heck, it's now or never, isn't it new? \stop \par 91%D \stoptyping 92%D 93%D We used it to mark synonyms that should not be corrected by the editor. Sort of the 94%D reverse of not having a word in a vetted wordlist. A bit out of place in a typesetting 95%D system. If really needed we can support multiple words seperataed by spaces but I didn't 96%D need it. And \unknown\ fonts are supported but at fixed size! 97 98\ifdefined\setreplacements 99 100 \pushoverloadmode 101 102 \permanent\tolerant\protected\def\setreplacements[#1]#*[#2]% 103 {{#1}% 104 \ifparameter#2\or 105 \setoverloads[#2]% 106 \else 107 \resetoverloads 108 \fi} 109 110 \popoverloadmode 111 112\else 113 114 % something weird 115 116\fi 117 118\protect 119 |