blob: 231d80b202b084210a8106c78a2e7d8628ae7834 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \iffalse %%%%
% %
% Copyright (c) 2013 - Michiel Helvensteijn - www.mhelvens.net %
% %
% http://latex-underoverlap.googlecode.com %
% %
% This work may be distributed and/or modified under the conditions %
% of the LaTeX Project Public License, either version 1.3 of this %
% license or (at your option) any later version. The latest version %
% of this license is in http://www.latex-project.org/lppl.txt %
% and version 1.3 or later is part of all distributions of LaTeX %
% version 2005/12/01 or later. %
% %
% This work has the LPPL maintenance status `maintained'. %
% %
% The Current Maintainer of this work is Michiel Helvensteijn. %
% %
% This work consists of the files underoverlap.tex and underoverlap.sty. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \fi %%%%
% \CheckSum{99}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Package Info} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{underoverlap}[2013/02/03 0.0.1-r1
construct for partly overlapping math decorations]
% \end{macrocode}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Packages} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% These are the packages we'll need.
%
% \begin{macrocode}
\RequirePackage{etoolbox}
\RequirePackage{mathtools}
\RequirePackage{xparse}
% \end{macrocode}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Public Macros} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\newUOLdecorator}
% \marg{control sequence} \marg{definition}
%%% \\\nopagebreak
%
% \noindent This defines the macro \meta{control sequence} as a
% new decorator command that is capable of overlapping
% with others.
%
% \begin{macrocode}
\NewDocumentCommand{\newUOLdecorator}{mm}{%
\newcommand{#1}[1]{#2}%
\UOLaugment{#1}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\UOLaugment}
% \marg{control sequence}
%%% \\\nopagebreak
%
% \noindent This augments the macro \meta{control sequence}
% to allow it to be overlapped.
%
% \begin{macrocode}
\NewDocumentCommand{\UOLaugment}{m}{%
\cslet{\uol@oldcsname{#1}}{#1}%
\renewcommand{#1}{%
\ifbool{mmode}{%
\uol@construct{\csuse{\uol@oldcsname{#1}}}%
}{%
\csuse{\csuse{\uol@oldcsname{#1}}}%
}%
}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\UOLunaugment}
% \marg{original cs}
%%% \\\nopagebreak
%
% \noindent This unaugments the macro \meta{original cs} so
% it will once again have its original meaning. This will
% only make sense if you're previously augmented that command
% with |\UOLaugment|.
%
% \begin{macrocode}
\NewDocumentCommand{\UOLunaugment}{m}{%
\letcs{#1}{\uol@oldcsname{#1}}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Private Macros} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The content inside a decoration has three parts:
% \begin{itemize}
% \item A `left' part that may overlap with the
% previous construct.
% \item A `middle' part that does not overlap.
% \item A `right' part that overlaps with the next construct.
% \end{itemize}
%
% \noindent Only the `middle' and `right' parts are passed as parameters
% throughout most of the following commands. The `left' part is defined
% by the previous \meta{UOL decorator} inside the |\uol@overlap@content|
% macro.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\uol@oldcsname}
% \marg{control sequence}
%%% \\\nopagebreak
%
% \noindent Given a control sequence, this derives the corresponding
% 'old csname' used by this package when augmenting it.
%
% \begin{macrocode}
\newcommand{\uol@oldcsname}[1]{%
uol@old@\expandafter\@gobble\string#1%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\uol@construct}
% \marg{original macro}
% \marg{middle}
% \marg{right}
%%% \\\nopagebreak
%
% \noindent Scans ahead for subscript or superscript.
%
% \begin{macrocode}
\NewDocumentCommand{\uol@construct}{mmO{}}{%
\let\uol@sup\empty%
\let\uol@sub\empty%
\@ifnextchar^{%
\uol@construct@sup{#1}{#2}{#3}%
}{%
\@ifnextchar_%
{\uol@construct@sub {#1}{#2}{#3}}%
{\uol@construct@final{#1}{#2}{#3}}%
}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\uol@construct@sup}
% \marg{original macro}
% \marg{middle}
% \marg{right}
%%% \verb|^| \marg{superscript} \\\nopagebreak
%
% \noindent Processes superscript and scans ahead for subscript.
%
% \begin{macrocode}
\def\uol@construct@sup#1#2#3^#4{%
\def\uol@sup{#4}%
\@ifnextchar_%
{\uol@construct@sup@sub{#1}{#2}{#3}}%
{\uol@construct@final {#1}{#2}{#3}}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\uol@construct@sub}
% \marg{original macro}
% \marg{middle}
% \marg{right}
%%% \verb|_| \marg{subscript} \\\nopagebreak
%
% \noindent Processes subscript and scans ahead for superscript.
%
% \begin{macrocode}
\def\uol@construct@sub#1#2#3_#4{%
\def\uol@sub{#4}%
\@ifnextchar^%
{\uol@construct@sub@sup{#1}{#2}{#3}}%
{\uol@construct@final {#1}{#2}{#3}}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\uol@construct@sub@sup}
% \marg{original macro}
% \marg{middle}
% \marg{right}
%%% \verb|^| \marg{superscript} \\\nopagebreak
%
% \noindent Processes superscript and calls the 'final' command.
%
% \begin{macrocode}
\def\uol@construct@sub@sup#1#2#3^#4{%
\def\uol@sup{#4}%
\uol@construct@final{#1}{#2}{#3}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\uol@construct@sup@sub}
% \marg{original macro}
% \marg{middle}
% \marg{right}
%%% \verb|_| \marg{subscript} \\\nopagebreak
%
% \noindent Processes subscript and calls the 'final' command.
%
% \begin{macrocode}
\def\uol@construct@sup@sub#1#2#3_#4{%
\def\uol@sub{#4}%
\uol@construct@final{#1}{#2}{#3}%
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% \begin{macro}{\uol@overlap@content}\nopagebreak
%
% \noindent This macro stores the 'overlapped' part of the
% math content between two augmented macros. We make sure
% that it is empty at the beginning of a new equation.
%
% \begin{macrocode}
\let\uol@overlap@content\@empty
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\uol@construct@final}
% \marg{original macro}
% \marg{middle}
% \marg{right}
%%% \\\nopagebreak
%
% \noindent This command typesets the result and reserves
% space for the overlap.
%
% \begin{macrocode}
\newcommand{\uol@construct@final}[3]{
% \end{macrocode}
%
% The following block will set the visible ink of the
% decoration without visibly setting the content itself
% and without moving our current position (using |\mathrlap|).
%
% \begin{macrocode}
\mathrlap{%
% \end{macrocode}
%
% We do several things next. Using |\mathop| we allow any
% subscript and superscript to be positioned directly under
% or over the construct, even if the original command doesn't
% natively support it.
%
% We call the original command with |#1| and make it initially
% invisible using |\phantom|.
%
% Using braces we provide the spacing most likely to be
% satisfactory. If it's not, the user should manually
% correct with math-spacing commands.
%
% \begin{macrocode}
\displaystyle%
\mathop{#1{\phantom{%
{\uol@overlap@content}{{}#2{}}{#3}%
}}}%
% \end{macrocode}
%
% The following two lines set the subscript and superscript
% that we collected during the previous phases.
%
% \begin{macrocode}
^{\mathclap{\uol@sup}}%
_{\mathclap{\uol@sub}}%
% \end{macrocode}
% \uninteresting\begin{macrocode}
}%
% \end{macrocode}
%
% Next, we optionally print the debug-shadow (disabled right now).
%
% \begin{macrocode}
%\mathrlap{\textcolor{green}{\uol@overlap@content#2#3}}%
% \end{macrocode}
%
% The following code visibly typesets the `left' and `middle' parts of the content.
%
% \begin{macrocode}
{\uol@overlap@content}{{}#2{}}%
% \end{macrocode}
%
% We assume that the `right' part (that overlaps with the next construct)
% will be visibly set by the following command, which will be \emph{its}
% `left' part. We store it in the |\uol@overlap@content| macro now.
%
% \begin{macrocode}
\def\uol@overlap@content{#3}%
% \end{macrocode}
% \uninteresting\begin{macrocode}
}
% \end{macrocode}
%
%\end{macro}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \makeatletter\newcount\c@CodelineNoBackup
% \c@CodelineNoBackup=\c@CodelineNo
% \begin{macro}{\UOLoverbrace} \advance\c@CodelineNo\@ne
% \begin{macro}{\UOLunderbrace}\advance\c@CodelineNo\@ne
% \begin{macro}{\UOLoverline} \advance\c@CodelineNo\@ne
% \begin{macro}{\UOLunderline} \c@CodelineNo=\c@CodelineNoBackup
%%% \makeatother\ \\[-2\baselineskip]
%
% \noindent We predefine the following commands in a
% straightforward way:
%
% \begin{macrocode}
\newUOLdecorator{\UOLoverbrace} {\overbrace {#1}}
\newUOLdecorator{\UOLunderbrace}{\underbrace{#1}}
\newUOLdecorator{\UOLoverline} {\overline {#1}}
\newUOLdecorator{\UOLunderline} {\underline {#1}}
% \end{macrocode}
%
%\end{macro}\end{macro}\end{macro}\end{macro}%%%%%%%%%%%%%%%
|