typo-ovl.mkiv /size: 3880 b    last modification: 2020-07-01 14:35
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
\registerctxluafile
{
typo
-
ovl
}{}
26 27
\definesystemattribute
[
overloads
][
public
,
global
]
28 29
\installcorenamespace
{
overloads
}
30 31
%D Watch how we abuse highlights.
32 33
\newcount
\c_typo_overload_font_id
34 35
\unexpanded
\def
\typo_overloads_define
#
1
%
36
{
\begingroup
37
% we pack so we avoid interference (and for sure don't process!)
38
\setbox
\scratchbox
\hpack
\bgroup
39
\global
\c_typo_overload_font_id
\fontid\font
40
\resetallattributes
% so we only change what gets set
41
\highlight
[#
1
]
%
42
\signalcharacter
43
\global
\c_typo_overload_font_id
44
\ifnum
\c_typo_overload_font_id
=
\fontid\font
45
\zerocount
46
\else
47
\fontid\font
48
\fi
49
\egroup
50
\global\expandafter\chardef\csname
\??overloads
#
1
\endcsname
51
\clf_overloadsattribute
{
#
1
}
\c_typo_overload_font_id
\scratchbox
52
\endgroup
}
53 54
\unexpanded
\def
\setoverloads
[#
1
]
%
55
{
\ifcsname
\??overloads
#
1
\endcsname\else
56
\typo_overloads_define
{
#
1
}
%
57
\fi
58
\c_attr_overloads
\csname
\??overloads
#
1
\endcsname
}
59 60
\unexpanded
\def
\registeroverloads
[#
1
]
%
61
{
\ifcsname
\??overloads
#
1
\endcsname\else
62
\typo_overloads_define
{
#
1
}
%
63
\fi
}
64 65
\unexpanded
\def
\resetoverloads
66
{
\c_attr_overloads
\attributeunsetvalue
}
67 68
%D We hook this into the replacement module, probably the only place where it makes
69
%D sense. Here is an adapted version of an example:
70
%D
71
%D \starttyping
72
%D \replaceword[basics][new] [old]
73
%D \replaceword[basics][now] [hl3->never]
74
%D \replaceword[basics][never][now]
75
%D \replaceword[basics][heck] []
76
%D
77
%D \definehighlight[hl1][style={\setbar[underbar]\red\setcharactercasing[WORD]\bf}]
78
%D \definehighlight[hl2][style={\setbar[overbar]\blue\setcharactercasing[Words]}]
79
%D \definehighlight[hl3][style={\setbar[overstrike]\green\bs}]
80
%D
81
%D \registeroverloads[hl1]
82
%D \registeroverloads[hl2]
83
%D \registeroverloads[hl3]
84
%D
85
%D \start \setreplacements[basics][hl1] What the heck, it's now or never, isn't it new? \stop \par
86
%D \start \setreplacements[basics][hl2] What the heck, it's now or never, isn't it new? \stop \par
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] What the heck, it's now or never, isn't it new? \stop \par
89
%D \stoptyping
90
%D
91
%D We used it to mark synonyms that should not be corrected by the editor. Sort of the
92
%D reverse of not having a word in a vetted wordlist. A bit out of place in a typesetting
93
%D system. If really needed we can support multiple words seperataed by spaces but I didn't
94
%D need it. And \unknown\ fonts are supported but at fixed size!
95 96
\ifdefined
\setreplacements
97 98
\unexpanded
\def
\setreplacements
99
{
\dodoubleempty
\languages_replacements_set
}
100 101
\unexpanded
\def
\languages_replacements_set
[#
1
][#
2
]
%
102
{
\clf_setreplacements
{
#
1
}
%
103
\ifsecondargument
104
\setoverloads
[#
2
]
%
105
\else
106
\resetoverloads
107
\fi
}
108 109
\else
110 111
% something weird
112 113
\fi
114 115
\protect
116