spac-chr.mkiv /size: 4707 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=spac-chr,
3%D        version=2011.05.24, % code moved from core-spa.mkiv
4%D          title=\CONTEXT\ Spacing Macros,
5%D       subtitle=Characters,
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 Spacing Macros / Characters}
15
16\unprotect
17
18\registerctxluafile{spac-chr}{optimize}
19
20\definesystemattribute[characters][public]
21
22%D The nobreakspace is special as it needs to keep track of the space being
23%D flexible. Another option is to use space (glue) nodes and tag them as characters
24%D instead. No big deal but takes a moment of coding. So, as a prelude we
25%D tag the nobreakspace only. Interesting is that it also fits better in the
26%D tagging mechanism.
27%D
28%D But we need to do some checking as from then on we no longer can compare
29%D them in a string. So this needs thinking. Not that we can compare the
30%D nobreakspace now anyway.
31
32% \unexpanded\def\specialspacecharacter#1{\begingroup\c_attr_characters#1\ \endgroup}
33%
34% \unexpanded\edef\nobreakspace            {\specialspacecharacter{"00A0}} % 1 = left
35% \unexpanded\edef\ideographicspace        {\specialspacecharacter{"2000}}
36% \unexpanded\edef\ideographichalffillspace{\specialspacecharacter{"2001}}
37% \unexpanded\edef\twoperemspace           {\specialspacecharacter{"2002}}
38% \unexpanded\edef\threeperemspace         {\specialspacecharacter{"2004}}
39% \unexpanded\edef\fourperemspace          {\specialspacecharacter{"2005}}
40% \unexpanded\edef\sixperemspace           {\specialspacecharacter{"2006}}
41% \unexpanded\edef\figurespace             {\specialspacecharacter{"2007}}
42% \unexpanded\edef\punctuationspace        {\specialspacecharacter{"2008}}
43% \unexpanded\edef\breakablethinspace      {\specialspacecharacter{"2009}}
44% \unexpanded\edef\hairspace               {\specialspacecharacter{"200A}}
45% \unexpanded\edef\zerowidthspace          {\specialspacecharacter{"200B}}
46% \unexpanded\edef\zwnj                    {\specialspacecharacter{"200C}}
47% \unexpanded\edef\zwj                     {\specialspacecharacter{"200D}}
48% \unexpanded\edef\narrownobreakspace      {\specialspacecharacter{"202F}}
49
50% This does not work as spaceskip is only inserted in the case of raggedleft
51% and we need to be able to figure out all of them. Which makes me wonder ...
52% can't we just always set spaceskip to some value?
53
54% Making them active is also not an option unless we do that in every
55% catcode vector.
56
57\pushoverloadmode
58
59%    \nobreakspace            {\begingroup\setalignstateattribute\normalUchar"00A0\endgroup} % 1 = left
60\edef\nobreakspace            {\normalUchar"00A0} % space
61\edef\softhyphen              {\normalUchar"00AD} % softhyohen
62\edef\enquad                  {\normalUchar"2000} % quad/2
63\edef\emquad                  {\normalUchar"2001} % quad
64
65\let\ideographicspace         \enquad
66\let\ideographichalffillspace \emquad
67
68\unletfrozen\hairspace
69\unletfrozen\sixperemspace
70
71\edef\twoperemspace           {\normalUchar"2002} % quad/2
72%                             %            "2003  % quad == \quad == \hskip\emwidth
73\edef\threeperemspace         {\normalUchar"2004} % quad/3
74\edef\fourperemspace          {\normalUchar"2005} % quad/4
75%edef\fiveperemspace          {\normalUchar"001E} % quad/5 (bonus)
76\edef\sixperemspace           {\normalUchar"2006} % quad/6
77\edef\figurespace             {\normalUchar"2007} % width of zero
78\edef\punctuationspace        {\normalUchar"2008} % width of period
79\edef\breakablethinspace      {\normalUchar"2009} % quad/8
80\edef\hairspace               {\normalUchar"200A} % quad/8
81\edef\zerowidthspace          {\normalUchar"200B} % 0
82\edef\zerowidthnonjoiner      {\normalUchar"200C} % 0
83\edef\zerowidthjoiner         {\normalUchar"200D} % 0
84\edef\narrownobreakspace      {\normalUchar"202F} % quad/8
85%edef\mediummathspace         {\normalUchar"205F} % space/8 (math)
86%edef\zerowidthnobreakspace   {\normalUchar"FEFF}
87%edef\fiveperemspace          {\normalUchar"001E}
88
89\udef\zerowidthnobreakspace   {\penalty\plustenthousand\kern\zeropoint}
90\udef\fiveperemspace          {\hskip\dimexpr\emwidth/5\relax}
91
92\let\zwnj                     \zerowidthnonjoiner
93\let\zwj                      \zerowidthjoiner
94\let\nbsp                     \nobreakspace
95
96\popoverloadmode
97
98\chardef\optionalspace    "1F % will be space unless before punctuation
99\chardef\autoinsertedspace"1E % a more clever \autoinsertspace
100
101% Shortcuts:
102
103% unexpanded as otherwise we need to intercept / cleanup a lot
104
105\unexpanded\def~{\nobreakspace}
106
107\protect \endinput
108
109