Debian Codegraph @

texmf-dist/doc/latex/minitoc/dblaccnt.sty

raw
1 %% LaTeX2e file `./dblaccnt.sty'
2 %% generated by the `filecontents' environment
3 %% from source `minitoc' on 2018/07/13.
4 %%
5 % Copyright 2000 Frank Mittelbach <[email protected]>.
6 % License: LPPL, version 1.3a or newer, according to
7 % http://www.latex-project.org/lppl.txt.
8 %
9 % This work has the LPPL maintenance status `maintained'.
10 %
11 % The Current Maintainer of this work is Werner Lemberg <[email protected]>.
12 %
13 %
14 % This is the file dblaccnt.tex which implements support for multiple
15 % accents.
16 %
17 %
18 % The code below handles only the case of
19 %
20 % \acc1 \acc2 ... glyph
21 %
22 % with or without nesting braces.
23 %
24 % \acc1 {\acc2 a}
25 %
26 % etc. will be handled correctly by removing the brace group during
27 % the scanning process. This means in particular that conceptually
28 % any accent command can only handle single token arguments!
29 %
30 % It should also work for combinations generated from inputenc, i.e.,
31 % are presented as 8bit tokens or, after passing through something like
32 % an .aux file, as \IeC{\acc1} \IeC{\acc2} ...
33 %
34 % If you use OT1 encoding you have to explicitly reload it (with
35 % \usepackage[OT1]{fontenc}).
36 %
37 %
38 % History
39 %
40 % 1.0 2000/01/27
41 %
42 % Initial release.
43 %
44 % 1.1 2005/04/21
45 %
46 % Make it work with LaTeX release 2003/12/01.
47 % Add copyright message and history.
48 %
49
50 \ProvidesPackage{dblaccnt}[2005/04/21 v1.1 double accent support]
51
52 \endlinechar \m@ne
53
54
55 % We must redefine two internal LaTeX commands to provide hooks for
56 % assembling accents.
57
58 % Here we test whether #1 (the command to be executed) is \chardef or
59 % #3 (the encoding) is `?'. If both are false, \assemble@accent@cmds
60 % will be used.
61 %
62 % The first case catches \DeclareTextSymbol, the second catches
63 % \ProvideTextCommandDefault. Both checks are ugly hacks which hopefully
64 % disappear in the near future.
65 %
66 \def\@dec@text@cmd#1#2#3{
67 \ifx#1\chardef
68 \expandafter\def\expandafter#2\expandafter{
69 \csname#3-cmd\expandafter\endcsname
70 \expandafter#2
71 \csname#3\string#2\endcsname
72 }
73 \else
74 \ifx#1\chardef@text@cmd
75 \expandafter\def\expandafter#2\expandafter{
76 \csname#3-cmd\expandafter\endcsname
77 \expandafter#2
78 \csname#3\string#2\endcsname
79 }
80 \else
81 \if#3?
82 \expandafter\def\expandafter#2\expandafter{
83 \csname#3-cmd\expandafter\endcsname
84 \expandafter#2
85 \csname#3\string#2\endcsname
86 }
87 \else
88 \expandafter\def\expandafter#2\expandafter{
89 % start looking for acc tokens
90 \expandafter\assemble@accent@cmds
91 \csname#3-cmd\expandafter\endcsname
92 \expandafter#2
93 \csname#3\string#2\endcsname
94 }
95 \fi
96 \fi
97 \fi
98 \let\@ifdefinable\@rc@ifdefinable
99 \expandafter#1\csname#3\string#2\endcsname
100 }
101
102
103 % The redefined \@tabacckludge macro below assures that the top-level
104 % definition of the accents (which contains \assemble@accent@cmds)
105 % will be called.
106 %
107 \def\@make@tabacc#1#2{
108 \expandafter\def\csname @tabacc\string#1\endcsname{#2}
109 }
110
111 \@make@tabacc{'}{\@acci}
112 \@make@tabacc{`}{\@accii}
113 \@make@tabacc{=}{\@acciii}
114
115
116 % Here the redefinition of second internal LaTeX macro.
117 %
118 \def\@tabacckludge#1{
119 \csname @tabacc\string#1\endcsname
120 }
121
122
123 % We only look ahead for further accents if we are to typeset.
124 %
125 \def\assemble@accent@cmds{
126 \ifx\protect\@typeset@protect
127 \expandafter\assemble@tokensinit
128 \fi
129 }
130
131
132 % The init is special as we have to parse over some of the expansion
133 % of the encoding specific command; for example, \^ might expand to
134 %
135 % \assemble@accent@cmds \OT1-cmd \^ \OT1\^
136 % ^^^^^^ one token
137 %
138 % We start \assemble@tokens with the number of hits so far (\@empty),
139 % zero the actual code for the current, e.g., \OT1\^ in the above
140 % example (resp. the corresponding macro in the current font
141 % encoding), and as a third argument we will pick up the next token
142 % or group in the input stream for testing.
143 %
144 \def\assemble@tokensinit#1#2#3{
145 % the usual test for availability in the current encoding
146 % similar to the test in \@changed@cmd
147 \@inmathwarn#2
148 \expandafter\ifx\csname\cf@encoding\string#2\endcsname\relax
149 \expandafter\ifx\csname ?\string#2\endcsname\relax
150 \expandafter\def\csname ?\string#2\endcsname{
151 \TextSymbolUnavailable#2
152 }
153 \fi
154 \global\expandafter\let
155 \csname\cf@encoding \string#2\expandafter\endcsname
156 \csname ?\string#2\endcsname
157 \fi
158
159 % here we substitute the current encoding
160 \expandafter\assemble@tokens@\expandafter\@empty
161 \csname\cf@encoding\string#2\endcsname
162 }
163
164
165 % The next commands should be considered only as a proof of concept
166 % -- they can most certainly be streamlined. Here is roughly what
167 % they do:
168 %
169 % \assemble@tokens: If the picked up token is \IeC then get rid of it
170 % and parse the next token (or group) which is expected to be the
171 % argument of \IeC. This is done by restarting the whole process.
172 % Otherwise we have to figure out if the current token (#3) is an
173 % 8-bit from inputenc, i.e., expanding to \IeC{...}. This is
174 % handled by calling \assemble@tokensz passing an expansion of #3
175 % as well as #3 (or more exactly, its first token since the braces
176 % get removed in this process) itself.
177 %
178 % \assemble@tokensz: Test if the expansion start with \IeC in which
179 % case it is assumed that it comes from an inputenc 8bit; the next
180 % token will be considered as its argument and used for further
181 % processing in \assemble@tokensx. Otherwise the unexpanded #3
182 % from above is used.
183 %
184 % \assemble@tokensx: If this cmd is called its third argument should
185 % contain a normalized token from the input stream, i.e.
186 %
187 % {..} -> ..
188 % \IeC{..} -> ..
189 % ^^xx (expanding to) \IeC{..} -> ..
190 %
191 % Now all :-) that remains is testing whether the expansion of this
192 % token starts with \assemble@accent@cmds, since in this case we have
193 % found another accent cmd.
194 %
195 % #1 is the number of hits, #2 is the real definition in that
196 % encoding, and #3 is the next token (or group).
197 %
198 % The macros \assemble@tokens@ and \assemble@tokens@@ are
199 % intermediate steps to test whether #3 is empty; if yes, we simply
200 % expand #2.
201 %
202 \def\assemble@tokens@#1#2#3{
203 \assemble@tokens@@{#1}{#2}{#3}{#3\@empty}
204 }
205
206 \def\assemble@tokens@@#1#2#3#4{
207 \ifx#4\@empty
208 \expandafter\@firstoftwo
209 \else
210 \expandafter\@secondoftwo
211 \fi
212 {#2{}}
213 {\assemble@tokens{#1}{#2}{#3}}
214 }
215
216 \def\assemble@tokens#1#2#3{
217 \ifx\IeC#3
218 \expandafter\@firstoftwo
219 \else
220 \expandafter\@secondoftwo
221 \fi
222 % try again but pick up argument of \IeC
223 {\assemble@tokens@{#1}{#2}}
224 % this will get rid of a group argument -- nasty :-)
225 {\expandafter\assemble@tokensz#3\relax\assemble@tokensz{#1}{#2}#3}
226 }
227
228 \def\assemble@tokensz#1#2\assemble@tokensz#3#4#5{
229 \ifx#1\IeC
230 \expandafter\@firstoftwo
231 \else
232 \expandafter\@secondoftwo
233 \fi
234 {\assemble@tokensx{#3}{#4}#2}
235 {\assemble@tokensx{#3}{#4}#5}
236 }
237
238 % \assemble@tokensx: This passes an expanded and unexpanded version
239 % of #3 to \ifassemble@tokens to do the actual processing.
240 %
241 % \ifassemble@tokens: If we have found another accent command then
242 % keep its name and record that we had another hit and restart the
243 % scanning via \assemble@tokens, i.e., we append an `x' to the
244 % ``hit'' argument that we carry around for no good reason, and we
245 % append the official name of the accent command (which was picked
246 % up as part of the expansion of the input token) to the argument,
247 % storing the list of accents found so far. Note that we do use
248 % the official name, e.g. `\"', not `\OT1\"' -- the latter is only
249 % used for the very first accent!
250 %
251 % If it turns out that we don't have an accent command here it is
252 % time to stop the scanning and do some processing. Now finally the
253 % ``hit'' argument and the list of collected accents comes into play:
254 % We construct a command which name consists of the string
255 % ``handle@accent'', followed by a number of `x's each for each hit
256 % earlier on. Thus in a situation like \"\^a we would execute
257 % \handle@accentx and in case of \"a \handle@accent. This command
258 % gets as its arguments the collected accents followed by the token
259 % which stopped the scanning proccess, e.g.
260 %
261 % \handle@accentx \OT1\" \^ {a}
262 %
263 % and its purpose is to determine how to produce a glyph from it
264 % (e.g. as a composite or as a part composite or ...)
265 %
266 \def\assemble@tokensx#1#2#3{
267 \expandafter
268 \ifassemble@tokens#3\@empty\@empty\@empty\ifassemble@tokens{#1}{#2}{#3}}
269
270 \def\ifassemble@tokens#1#2#3#4\ifassemble@tokens#5#6#7{
271 % next token was defined via \DeclareText...
272 \ifx#1\assemble@accent@cmds
273 % thus #3 is its official name
274 \expandafter\assemble@tokens@
275 \else
276 % execute what has been assembled and exit
277 \csname handle@accent#5\endcsname#6{#7}
278 \expandafter\@gobbletwo
279 \fi
280 % first two args to \assemble@tokens on next pass
281 {#5x}{#6#3}
282 }
283
284
285 % Depending on the number of accents found, \handle@accent[x[x]] will
286 % be called.
287
288 % ONLY ONE: We check whether \#1-#2 is a known command (a composite)
289 % and execute it, otherwise try to execute #1{#2} as an accent
290 % command.
291 %
292 \def\handle@accent#1#2{
293 \expandafter\ifx\csname\string#1-\string#2\endcsname\relax
294 #1{#2}
295 \else
296 \csname\string#1-\string#2\endcsname
297 \fi
298 }
299
300 % TWO IN A ROW: We check for \#1-#2-#3. If undefined, we apply #1 to
301 % whatever is the result of #2{#3}. One could think of a more
302 % complex algorithm here, e.g., if #1-#2 is known as a composite
303 % modifier (whatever that is) apply that before trying the above but
304 % this is probably not necessary.
305 %
306 \def\handle@accentx#1#2#3{
307 \expandafter\ifx\csname\string#1-\string#2-\string#3\endcsname\relax
308 #1{#2{#3}}
309 \else
310 \csname\string#1-\string#2-\string#3\endcsname
311 \fi
312 }
313
314 % MORE THAN TWO: (Not handled so far.) If there are more than three,
315 % then the parsing will die at some point when \handle@accentxx...
316 % will turn out to be \relax, and then one accent will become an
317 % argument of another -- too bad.
318 %
319 \def\handle@accentxx#1#2#3#4{
320 % catch more than two accents in a row
321 \errmessage{Too many accents, dropping first}
322 #2#3#4
323 }
324
325
326 % This is simpler now.
327 %
328 \def\DeclareTextCompositeCommand#1#2#3#4{
329 \expandafter\def\csname\expandafter\string\csname
330 #2\endcsname\string#1-\string#3\endcsname{#4}
331 }
332
333 % This is new.
334 %
335 \def\DeclareTextDoubleCompositeCommand#1#2#3#4#5{
336 \expandafter\def\csname\expandafter\string\csname
337 #2\endcsname\string#1-\string#3-\string#4\endcsname{#5}
338 }
339
340 % This also.
341 %
342 \catcode\z@=11\relax
343 \def\DeclareTextDoubleComposite#1#2#3#4#5{
344 \def\reserved@a{\DeclareTextDoubleCompositeCommand#1{#2}{#3}{#4}}
345 \bgroup
346 \lccode\z@#5
347 \lowercase{
348 \egroup
349 \reserved@a ^^@}
350 }
351 \catcode\z@=15\relax
352
353
354 % Now we reinitialize the \@acc... macros to use our new definitions.
355 %
356 \AtBeginDocument{
357 \let\@acci \'
358 \let\@accii \`
359 \let\@acciii \=
360 }
361
362
363 \endlinechar `\^^M
364
365 \endinput
366
367 % end of dblaccnt.tex