| 1 |
% multislot.sty |
| 2 |
% |
| 3 |
% Second version |
| 4 |
|
| 5 |
|
| 6 |
\needsfontinstversion{1.900} |
| 7 |
% Relies heavily on _etx_pass_hook commands. |
| 8 |
|
| 9 |
|
| 10 |
%%%%%%%%%%%%%%% RESOURCES USED %%%%%%%%%%%%%%% |
| 11 |
% |
| 12 |
% The following classes of control sequences are used by the multislot |
| 13 |
% routines, in addition to the ones defined below and the ones fontinst |
| 14 |
% normally uses: |
| 15 |
% |
| 16 |
% \name-NUM |
| 17 |
% |
| 18 |
% where NUM is a number consisting of one, two, or three decimal digits. |
| 19 |
% These are also used by \pltomtx, so they probably already exist as |
| 20 |
% hash table entries. |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
%%%%%%%%%%%%%%% SAVE CATCODES %%%%%%%%%%%%%%% |
| 25 |
% |
| 26 |
% Save the current values of the catcodes of space, @, NL, ~ and _. |
| 27 |
% _ and @ are made letters, ~ is a space, and space and NL are ignored. |
| 28 |
|
| 29 |
\edef\spacecatcode{\the\catcode`\ } |
| 30 |
\edef\atcatcode{\the\catcode`\@} |
| 31 |
\edef\nlcatcode{\the\catcode`\^^M} |
| 32 |
\edef\underscorecatcode{\the\catcode`\_} |
| 33 |
\edef\tildecatcode{\the\catcode`\~} |
| 34 |
|
| 35 |
\catcode`\ =9 |
| 36 |
\catcode`\^^M=9 |
| 37 |
\catcode`\@=11 |
| 38 |
\catcode`\_=11 |
| 39 |
\catcode`\~=10 |
| 40 |
|
| 41 |
|
| 42 |
%%%%%%%%%%%%%%% MULTIPLE SLOT COMMANDS %%%%%%%%%%%%%%% |
| 43 |
% |
| 44 |
% The user-level commands are quite simple. As usual, you can write |
| 45 |
% |
| 46 |
% \setslot{NAME} |
| 47 |
% <slot commands> |
| 48 |
% \endsetslot |
| 49 |
% |
| 50 |
% to assign a glyph to a slot. The difference is that if there are |
| 51 |
% multiple \setslot commands for a slot, this will no longer cause |
| 52 |
% strange results. Instead, only the first \setslot-\endsetslot pair |
| 53 |
% for each slot will be used, the others are ignored. |
| 54 |
% |
| 55 |
% If you instead write |
| 56 |
% |
| 57 |
% \resetslot{NAME} |
| 58 |
% <slot commands> |
| 59 |
% \endsetslot |
| 60 |
% |
| 61 |
% then this will override any earlier occurences of \setslot or |
| 62 |
% \resetslot. Finally, there is the command |
| 63 |
% |
| 64 |
% \unsetslot{NUMBER} |
| 65 |
% |
| 66 |
% which makes fontinst forget any earlier occurences of \setslot |
| 67 |
% or \resetslot commands for that particular slot. |
| 68 |
|
| 69 |
|
| 70 |
% The way this works is that every \setslot or \resetslot command is |
| 71 |
% implicitly assigned an index, namely the number of such commands |
| 72 |
% perviously encountered since the start of the ETX pass. The count |
| 73 |
% register \slot_index is allocated to keep track of the current |
| 74 |
% index: |
| 75 |
|
| 76 |
\newcount\slot_index |
| 77 |
\def\clear_slot_index{\slot_index=\m@ne} |
| 78 |
\add_to\pre_first_etx_pass_hook{\clear_slot_index} |
| 79 |
\add_to\pre_second_etx_pass_hook{\clear_slot_index} |
| 80 |
\add_to\pre_third_etx_pass_hook{\clear_slot_index} |
| 81 |
\add_to\pre_fourth_etx_pass_hook{\clear_slot_index} |
| 82 |
|
| 83 |
% \setslot, \setleftboundary, and \setrightboundary increments the |
| 84 |
% counter just before checking it. |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
% The point of maintaining the index is that the index of the |
| 89 |
% \setslot (or whatever) that actually sets a particular slot gets |
| 90 |
% stored in the \name-SLOT control sequence (which is \mathchardef'ed |
| 91 |
% to the index). After assignments are made, all a \setslot (or |
| 92 |
% whatever) needs to do is to check whether the stored index matches |
| 93 |
% the current one, and gobble itself if they don't. |
| 94 |
|
| 95 |
% The basic check is performed by the command \later_index_check. |
| 96 |
% This has the syntax |
| 97 |
% |
| 98 |
% \later_index_check{SLOT}{<else-code>} |
| 99 |
% |
| 100 |
% and expands to nothing if this \setslot will be active, but to |
| 101 |
% <else-code> if it will not. |
| 102 |
\def\later_index_check#1{ |
| 103 |
\x_cs\ifnum {name-#1}=\slot_index |
| 104 |
\expandafter\gobble_one |
| 105 |
\else |
| 106 |
\expandafter\identity_one |
| 107 |
\fi |
| 108 |
} |
| 109 |
% However, when deciding which \setslots will be active, the condition |
| 110 |
% to test is slightly different: is the control sequence in question |
| 111 |
% already defined to be a mathchar token? If it isn't, then this will |
| 112 |
% be the active \setslot. |
| 113 |
\def\setslot_index_check#1{\x_cs\setslot_index_check_i{name-#1}} |
| 114 |
\def\temp_command#1{ |
| 115 |
\def\setslot_index_check_ii##1#1##2\setslot_index_check_ii{##1} |
| 116 |
\def\setslot_index_check_i##1{ |
| 117 |
\expandafter\setslot_index_check_ii \expandafter\ifx |
| 118 |
\expandafter$ \meaning##1 #1 0 \setslot_index_check_ii $ |
| 119 |
\expandafter\identity_one |
| 120 |
\else |
| 121 |
\mathchardef##1=\slot_index |
| 122 |
\expandafter\gobble_one |
| 123 |
\fi |
| 124 |
} |
| 125 |
} |
| 126 |
\expandafter\temp_command \expandafter{ \string\mathchar " } |
| 127 |
|
| 128 |
% The stated definition of \setslot_index_check should thus be in |
| 129 |
% force during the first etx pass, but after that the |
| 130 |
% \later_index_check definition should rule. |
| 131 |
\add_to\post_first_etx_pass_hook{ |
| 132 |
\let\setslot_index_check=\later_index_check |
| 133 |
} |
| 134 |
|
| 135 |
% The following is used to ignore a \setslot--\endsetslot or |
| 136 |
% \setleftboundary--\endsetleftboundary construction; the argument is |
| 137 |
% the command which marks the end. The reason not to use |
| 138 |
% \gobble_setslot is that it still executes \end_do_slot, which is |
| 139 |
% quite wrong for the kind of ignoring done here. |
| 140 |
\def\ignore_to_end#1{ |
| 141 |
\bgroup |
| 142 |
\let#1=\fi |
| 143 |
\expandafter |
| 144 |
\egroup |
| 145 |
\iffalse |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
% The \setslot, \setleftboundary, and \setrightboundary commands must |
| 150 |
% be equipped with checks at the start. |
| 151 |
\def\checked_setslot{ |
| 152 |
\advance \slot_index \@ne |
| 153 |
\setslot_index_check{\the\slot_number}{ |
| 154 |
\advance \slot_number \@ne |
| 155 |
\ignore_to_end\endsetslot |
| 156 |
} |
| 157 |
\unchecked_setslot |
| 158 |
} |
| 159 |
|
| 160 |
\def\checked_setleftboundary{ |
| 161 |
\advance \slot_index \@ne |
| 162 |
\setslot_index_check{leftboundary}{\ignore_to_end\endsetleftboundary} |
| 163 |
\unchecked_setleftboundary |
| 164 |
} |
| 165 |
|
| 166 |
\def\checked_setrightboundary#1{ |
| 167 |
\advance \slot_index \@ne |
| 168 |
\setslot_index_check{\the\slot_number}{ |
| 169 |
\advance \slot_number \@ne |
| 170 |
\gobble_two |
| 171 |
} |
| 172 |
\unchecked_setrightboundary{#1} |
| 173 |
} |
| 174 |
\add_to\pre_first_etx_pass_hook{ |
| 175 |
\let\unchecked_setslot=\setslot |
| 176 |
\let\setslot=\checked_setslot |
| 177 |
\let\unchecked_setleftboundary=\setleftboundary |
| 178 |
\let\setleftboundary=\checked_setleftboundary |
| 179 |
\let\unchecked_setrightboundary=\setrightboundary |
| 180 |
\let\setrightboundary=\checked_setrightboundary |
| 181 |
} |
| 182 |
% But that's it, as far as the \set... commands are concerned. |
| 183 |
|
| 184 |
|
| 185 |
% What about \unsetslot? In principle, it _should_ just be a matter of |
| 186 |
\def\unsetslot#1{ |
| 187 |
\eval_expr{#1} |
| 188 |
\x_cs\let{name-\the\result}\undefined_command |
| 189 |
} |
| 190 |
\add_to\post_first_etx_pass_hook{\let\unsetslot=\gobble_one} |
| 191 |
% given which \resetslot is simply |
| 192 |
\def\resetslot{\unsetslot\slot_number \setslot} |
| 193 |
% and this sort-of works, but not quite. |
| 194 |
% |
| 195 |
% The problem is that the ordinary slot assignment table, which is |
| 196 |
% used for ligature and kerning instructions, is not updated by |
| 197 |
% \unsetslot. Hence ligatures and kerns will be generated as if all |
| 198 |
% glyphs that have been set for a slot are present there; after |
| 199 |
% |
| 200 |
% \nextslot{108} |
| 201 |
% \setslot{l} \endsetslot |
| 202 |
% |
| 203 |
% \nextslot{108} |
| 204 |
% \resetslot{lambda} \endsetslot |
| 205 |
% |
| 206 |
% the effect will be as if one had given the command |
| 207 |
% |
| 208 |
% \setleftkerning{lambda}{l}{1000} |
| 209 |
% |
| 210 |
% and moreover the same happens for ligatures, so an f + l -> fl |
| 211 |
% ligature will also work as an f + lambda -> fl ligature. |
| 212 |
% |
| 213 |
% This is of course a BUG, and there doesn't seem to be any way |
| 214 |
% around it, short of adding another pass of reading ETX files. Doing |
| 215 |
% so would probably not be worth the effort, since the usefulness of |
| 216 |
% a \resetslot command is not clear; unlike \resetglyph, it cannot be |
| 217 |
% used to amend an existing \set..., but only to override it. |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
%%%%%%%%%%%%%%% RESTORE CATCODES %%%%%%%%%%%%%%% |
| 222 |
% |
| 223 |
% Restore the catcodes that were changed. |
| 224 |
|
| 225 |
\catcode`\@=\atcatcode |
| 226 |
\catcode`\^^M=\nlcatcode |
| 227 |
\catcode`\ =\spacecatcode |
| 228 |
\catcode`\~=\tildecatcode |
| 229 |
\catcode`\_=\underscorecatcode |
| 230 |
|
| 231 |
%%%%%%%%%%%%%%% THE END %%%%%%%%%%%%%%% |
| 232 |
|
| 233 |
\endinput |
| 234 |
|