| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% % |
| 3 |
% Copyright (c) 2013 - Michiel Helvensteijn - www.mhelvens.net % |
| 4 |
% % |
| 5 |
% http://latex-concepts.googlecode.com % |
| 6 |
% % |
| 7 |
% This work may be distributed and/or modified under the % |
| 8 |
% conditions of the LaTeX Project Public License, either % |
| 9 |
% version 1.3 of this license or (at your option) any later % |
| 10 |
% version. The latest version of this license is in % |
| 11 |
% http://www.latex-project.org/lppl.txt % |
| 12 |
% and version 1.3 or later is part of all distributions of % |
| 13 |
% LaTeX version 2005/12/01 or later. % |
| 14 |
% % |
| 15 |
% This work has the LPPL maintenance status `maintained'. % |
| 16 |
% % |
| 17 |
% The Current Maintainer of this work is Michiel Helvensteijn. % |
| 18 |
% % |
| 19 |
% This work consists of the files underoverlap.tex and underoverlap.sty. % |
| 20 |
% % |
| 21 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 22 |
|
| 23 |
\documentclass[a4paper]{packagedoc} |
| 24 |
|
| 25 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 26 |
% Setup % |
| 27 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 28 |
|
| 29 |
\moretexcs{% |
| 30 |
newUOLdecorator, UOLaugment,% |
| 31 |
UOLoverbrace, UOLunderbrace,% |
| 32 |
UOLoverline, UOLunderline,% |
| 33 |
UOLfbox, bigstrut% |
| 34 |
} |
| 35 |
|
| 36 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 37 |
% Global Changes % |
| 38 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 39 |
|
| 40 |
\changes{0.0.1}{2013/02/02} |
| 41 |
{initial version} |
| 42 |
|
| 43 |
\changes{0.0.1-r1}{2012/02/03} |
| 44 |
{several improvements in the documentation} |
| 45 |
|
| 46 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 47 |
\begin{document} % |
| 48 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 49 |
|
| 50 |
\maketitle |
| 51 |
|
| 52 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 53 |
\section{Introduction} % |
| 54 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 55 |
|
| 56 |
\TeX\ and \LaTeX\ provide several commands for decorating parts of our |
| 57 |
equations---to direct attention or to indicate some special meaning. For |
| 58 |
\hbox{example}: |
| 59 |
|
| 60 |
\begin{latex-example-show} |
| 61 |
\[ n \times x = \overbrace{x + \cdots + x}^n \] |
| 62 |
\end{latex-example-show} |
| 63 |
|
| 64 |
\noindent I'm refering to the |\overbrace|, of course. You can even nest |
| 65 |
such commands: |
| 66 |
|
| 67 |
\begin{latex-example-show} |
| 68 |
\[ n \times x = |
| 69 |
\overbrace{x + \underbrace{x + \cdots + x}_{n-2}{} + x}^n \] |
| 70 |
\end{latex-example-show} |
| 71 |
|
| 72 |
\noindent But they have an inherent limitation: they cannot overlap partially. For |
| 73 |
example, you cannot do the following out-of-the-box: |
| 74 |
\[ |
| 75 |
a + \UOLoverbrace{b +}[c + d]^x \UOLunderbrace{+ e}_y + f |
| 76 |
\] |
| 77 |
That's what this package is all about. It allows you to define new |
| 78 |
decorator commands that can partially overlap like this, as well as |
| 79 |
augment existing commands. |
| 80 |
|
| 81 |
\break |
| 82 |
|
| 83 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 84 |
\section{Usage} % |
| 85 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 86 |
|
| 87 |
\describemetamacro{UOL decorator}{ |
| 88 |
\marg{non-overlapping content} \oarg{overlapping content} |
| 89 |
} |
| 90 |
|
| 91 |
\noindent An \meta{UOL decorator} is a decorator command prepared by this |
| 92 |
package, such as |\UOLoverbrace| and |\UOLunderbrace| in the examples below. |
| 93 |
|
| 94 |
If you never use the optional argument at all, they should behave exactly like |
| 95 |
the simple \TeX\ commands |\overbrace| and |\underbrace|. |
| 96 |
|
| 97 |
As far as the `current \meta{UOL decorator}' is concerned, the optional |
| 98 |
content is placed directly to the right of the mandatory content and both are |
| 99 |
decorated as a whole. But a subsequent \meta{UOL decorator} will be |
| 100 |
expected directly following this one. Its decorator will cover also the |
| 101 |
optional content from the current command. That's how we can |
| 102 |
typeset the example from the introduction: |
| 103 |
|
| 104 |
\begin{latex-example-show} |
| 105 |
\[ a + \UOLoverbrace{b +}[c + d]^x \UOLunderbrace{+ e}_y + f \] |
| 106 |
\end{latex-example-show} |
| 107 |
|
| 108 |
\noindent |
| 109 |
\DescribeMacro{\UOLoverbrace} |
| 110 |
\DescribeMacro{\UOLunderbrace} |
| 111 |
\DescribeMacro{\UOLoverline} |
| 112 |
\DescribeMacro{\UOLunderline} |
| 113 |
The following \meta{UOL decorator} commands are predefined by the package, |
| 114 |
with obvious meaning: |
| 115 |
\begin{itemize}\parskip=0pt |
| 116 |
\item |\UOLoverbrace| |
| 117 |
\item |\UOLunderbrace| |
| 118 |
\item |\UOLoverline| |
| 119 |
\item |\UOLunderline| |
| 120 |
\end{itemize} |
| 121 |
|
| 122 |
\noindent Note that you are not limited to \emph{two} overlapping decorators: |
| 123 |
|
| 124 |
\begin{latex-example-show} |
| 125 |
\[ a + \UOLoverbrace{b +}[c]^x \UOLunderbrace{+}[d]_y |
| 126 |
\UOLoverbrace{+ e}^z + f \] |
| 127 |
\end{latex-example-show} |
| 128 |
|
| 129 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 130 |
|
| 131 |
\describemacro{\newUOLdecorator}{ |
| 132 |
\marg{command sequence} \marg{definition containing\/ {\upshape|\#1|}} |
| 133 |
} |
| 134 |
|
| 135 |
\noindent Using this command you can create a new \meta{UOL decorator}. The |
| 136 |
first argument is the desired command sequence and the second contains its |
| 137 |
definition. |
| 138 |
|
| 139 |
Define it as if a simple |\newcommand| were used for a traditional decorator. |
| 140 |
The package will automatically augment it to allow it to overlap. You can use |
| 141 |
|#1| to stand for the content provided by the user. The |\UOLoverline| decorator, |
| 142 |
for example, was defined as follows: |
| 143 |
|
| 144 |
\let\UOLoverline\relax |
| 145 |
\begin{latex-example} |
| 146 |
\newUOLdecorator\UOLoverline{\overline{#1}} |
| 147 |
\end{latex-example} |
| 148 |
|
| 149 |
\noindent But note that the result will not be satisfactory unless the decorator |
| 150 |
requires no \emph{horizontal space} to be allocated other than for its |
| 151 |
content. For the commands listed above, this is no problem. But this |
| 152 |
may not be true for all native decorations. |
| 153 |
|
| 154 |
For example, one may naively try to define a |\UOLfbox| command as follows: |
| 155 |
|
| 156 |
\begin{latex-example} |
| 157 |
\newUOLdecorator\UOLfbox{{% |
| 158 |
\fboxsep=1.2pt \fboxrule=.8pt \fbox{$#1$}% |
| 159 |
}} |
| 160 |
\end{latex-example} |
| 161 |
|
| 162 |
\noindent To test it, we define the following command as well: |
| 163 |
|
| 164 |
\begin{latex-example} |
| 165 |
\newcommand\bigstrut{\vrule height 10pt depth 4pt width 0pt} |
| 166 |
\end{latex-example} |
| 167 |
|
| 168 |
\noindent The result will look like this: |
| 169 |
|
| 170 |
\begin{latex-example-show} |
| 171 |
\[ a + \UOLfbox{b +c +}[d]^x \UOLfbox{\bigstrut + e}^y + f \] |
| 172 |
\end{latex-example-show} |
| 173 |
|
| 174 |
\noindent The spacing is incorrect because |\fbox| allocates horizontal space for itself |
| 175 |
in addition to the space for its content and our package cannot take that into |
| 176 |
account. We'll have to correct for this manually: |
| 177 |
|
| 178 |
\let\UOLfbox\relax |
| 179 |
\begin{latex-example} |
| 180 |
\newUOLdecorator\UOLfbox{{% |
| 181 |
\fboxsep=1.2pt \fboxrule=.8pt% |
| 182 |
\kern-\fboxrule \kern-\fboxsep% |
| 183 |
\fbox{$#1$}% |
| 184 |
\kern-\fboxsep \kern-\fboxrule% |
| 185 |
}} |
| 186 |
\end{latex-example} |
| 187 |
|
| 188 |
\begin{latex-example-show} |
| 189 |
\[ a + \UOLfbox{b +c +}[d]^x \UOLfbox{\bigstrut + e}^y + f \] |
| 190 |
\end{latex-example-show} |
| 191 |
|
| 192 |
\noindent Much better! |
| 193 |
|
| 194 |
Note that subscripts / superscripts will be placed directly |
| 195 |
below / above the content, even if the original decorator did not |
| 196 |
support that. |
| 197 |
|
| 198 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 199 |
|
| 200 |
\describemacro{\UOLaugment}{ |
| 201 |
\marg{command sequence} |
| 202 |
} |
| 203 |
|
| 204 |
\noindent This command can augment an existing native decorator command to |
| 205 |
allow overlapping with its original name: |
| 206 |
|
| 207 |
\begin{latex-example-show} |
| 208 |
\UOLaugment\overline |
| 209 |
\UOLaugment\overbrace |
| 210 |
\[ a + \overline{b +}[c + d] \overbrace{\bigstrut + e}^y + f \] |
| 211 |
\end{latex-example-show} |
| 212 |
|
| 213 |
\noindent Note, however, the following assumptions on the original command: |
| 214 |
\begin{itemize} |
| 215 |
\item It should not be a native \TeX\ command such as |\underline|. |
| 216 |
Augmenting |\underline| like this actually seems to work fine, but the |
| 217 |
\TeX\ specification can give us no guarantees about its behavior if |
| 218 |
we do. |
| 219 |
\item It should originally only support one standard mandatory argument. |
| 220 |
If it already supported optional arguments or other code structures |
| 221 |
then that behavior will be lost after augmentation. |
| 222 |
\end{itemize} |
| 223 |
|
| 224 |
\noindent If these requirements are satisfied then the new command should be |
| 225 |
\emph{almost} backwards compatible. The exceptions being, of course, |
| 226 |
when you supply an optional argument or when it follows another |
| 227 |
\meta{UOL decorator} that does. The other exception is the behavior of |
| 228 |
subscripts and superscripts if the original decorator did not place them |
| 229 |
directly below / above the content. |
| 230 |
|
| 231 |
Of course, you can manually correct for these exceptions, but be aware |
| 232 |
that backwards compatibility is not completely guaranteed if you simply |
| 233 |
augment a decorator without any other measures. |
| 234 |
|
| 235 |
This package does not `pre-augment' any commands. |
| 236 |
|
| 237 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 238 |
|
| 239 |
\describemacro{\UOLunaugment}{ |
| 240 |
\marg{command sequence} |
| 241 |
} |
| 242 |
|
| 243 |
\noindent Assuming that \meta{command sequence} has been augmented by the |
| 244 |
|\UOLaugment| command, using |\UOLunaugment| reverses the effects and |
| 245 |
\meta{command sequence} will once again have its original meaning. |
| 246 |
|
| 247 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 248 |
\section{Acknowledgements} % |
| 249 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 250 |
|
| 251 |
I originaly read the following question on \url{http://tex.stackexchange.com}: |
| 252 |
\begin{itemize} |
| 253 |
\item \url{http://tex.stackexchange.com/questions/12963} |
| 254 |
\end{itemize} |
| 255 |
The commands of this package are partially based on the technique described by |
| 256 |
Herbert and the command definitions proposed by Martin Scharrer. |
| 257 |
|
| 258 |
I got a lot of useful help from the answers to my own questions too: |
| 259 |
\begin{itemize} |
| 260 |
\item \url{http://tex.stackexchange.com/questions/95786} |
| 261 |
\item \url{http://tex.stackexchange.com/questions/95897} |
| 262 |
\end{itemize} |
| 263 |
Thanks in particular to David Carlisle and Hendrik Vogt. |
| 264 |
|
| 265 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 266 |
\end{document} % |
| 267 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |