diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/oubraces |
Initial commit
Diffstat (limited to 'macros/latex/contrib/oubraces')
-rw-r--r-- | macros/latex/contrib/oubraces/oubraces.pdf | bin | 0 -> 66372 bytes | |||
-rw-r--r-- | macros/latex/contrib/oubraces/oubraces.sty | 92 | ||||
-rw-r--r-- | macros/latex/contrib/oubraces/oubraces.tex | 211 |
3 files changed, 303 insertions, 0 deletions
diff --git a/macros/latex/contrib/oubraces/oubraces.pdf b/macros/latex/contrib/oubraces/oubraces.pdf Binary files differnew file mode 100644 index 0000000000..74f33f8559 --- /dev/null +++ b/macros/latex/contrib/oubraces/oubraces.pdf diff --git a/macros/latex/contrib/oubraces/oubraces.sty b/macros/latex/contrib/oubraces/oubraces.sty new file mode 100644 index 0000000000..e5adc2282a --- /dev/null +++ b/macros/latex/contrib/oubraces/oubraces.sty @@ -0,0 +1,92 @@ +% oubraces.sty: Interleave \overbrace with \underbrace +% +% \overunderbraces{upper_braces}{main_formula}{lower_braces} +% +% Instructions are given below, after \endinput, and in oubraces.tex (.pdf) +% +% Copyright 1993,2011 Donald Arseneau, Vancouver, Canada +% +% Redistribution and use, with or without modification, are permitted provided +% that the above copyright notice and this condition for use are retained. + +\begingroup +\catcode`\@=\catcode`A +\gdef\overunderbraces #1#2#3{{% + \baselineskip\z@skip \lineskip4\p@ \lineskiplimit4\p@ + \displaystyle % deliberately generate error if not in math mode! +% first, do the top half of the alignment in a save-box ... + \setbox\z@\vbox{\ialign{&\hfil${}##{}$\hfil\cr + \global\let\br\br@label #1\cr % upper labels + \global\let\br\br@down #1\cr % upper braces + #2\cr % main line of the formula + }}% finished partial alignment and \vbox. + \dimen@-\ht\z@ % Measure height of partial alignment -- +% ... it is the height we want for the whole. +% Now do the whole alignment (notice the repetition from above) + \setbox\z@\vbox{\ialign{&\hfil${}##{}$\hfil\cr + \global\let\br\br@label #1\cr % upper labels + \global\let\br\br@down #1\cr % upper braces + #2\cr % main line of the formula + \global\let\br\br@up #3\cr % lower braces +% \noalign{\kern2\p@}% % because + \global\let\br\br@label #3\cr % lower labels + }}% finished whole alignment and \vbox. + \advance\dimen@\ht\z@ % calc. the necessary lowering + \lower\dimen@\hbox{\box\z@}% shift to get the desired height +}} + +% Three aliases for \br. +% #1=number of spanned columns, #2=label +\gdef\br@up#1#2{\multispan{#1}\upbracefill} +\gdef\br@down#1#2{\multispan{#1}\downbracefill} +\gdef\br@label#1#2{\multispan{#1}\hidewidth $\scriptstyle {#2}$\hidewidth} + +\endgroup +\endinput +% +%----------------------------------------------------------------- +% +% oubraces.sty: Interleave \overbrace with \underbrace +% Donald Arseneau, 1993 +% +% The syntax is: +% +% \overunderbraces{upper_braces}{main_formula}{lower_braces} +% +% Suppose we want the equation: +% x y +% ,-----^-----. ,-----^-----. +% a + b + c + d + e + f + g + h + i + j + k + l + m = \pi r^2 +% `-----v-----' +% z +% There are seven segments: +% x y +% ,-----^-----. ,-----^-----. +% a + b + c + d + e + f + g + h + i + j + k + l + m = \pi r^2 +% 11111111222222223333344455555666666667777777777... +% `-----v-----' +% z +% Insert & between each segment (where the tips of the braces point) +% to type the main_formula: +% x y +% ,-----^-----. ,-----^-----. +% a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m +% `-----v-----' +% z +% Each brace should be specified by typing +% +% \br{number_of_segments}{label}, +% +% separated by & to indicate which segment to start at; and +% where & & skips a segment that has no brace. For our +% example formula, the upper and lower brace specifiers are: +% +% top row: &\br{2}{x}& &\br{2}{y} +% bot row: & &\br{3}{z} +% +% Now put them all together: +% +% \overunderbraces{&\br{2}{x}& &\br{2}{y}}% +% {a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m}% +% {& &\br{3}{z}} +% = \pi r^2 diff --git a/macros/latex/contrib/oubraces/oubraces.tex b/macros/latex/contrib/oubraces/oubraces.tex new file mode 100644 index 0000000000..03aa56b14e --- /dev/null +++ b/macros/latex/contrib/oubraces/oubraces.tex @@ -0,0 +1,211 @@ +\documentclass[11pt]{article} +\usepackage{oubraces} +\overfullrule=5pt +\title{\textsf{oubraces.sty}\\[5pt] + \large{Interleave \textbackslash overbrace with \textbackslash underbrace}} +\author{Donald Arseneau} +\date{2011 (1993)} + +\makeatletter + +% LaTeX article explaining \overunderbraces + +% hacked version with extra labels for this article: +% \Xoverunderbraces{upper_brace}{main_formula}{lower_brace}{special_labels} +% +\newdimen \Xheight + +\def\Xoverunderbraces #1#2#3#4{{% #4 = special labels + \baselineskip\z@skip \lineskip4pt \lineskiplimit4pt + \displaystyle % generate error if not in math mode! +% first, do the top half of the alignment in a save-box to measure the height + \setbox\z@\vbox{\ialign{&\hfil${}##{}$\hfil\cr + \global\let\br\br@label #1\cr % upper labels + \global\let\br\br@down #1\cr % upper braces + #2\cr % main line of the formula + }}% finished partial alignment and \vbox. + \dimen@-\ht\z@ % Measure height -- it is the height we want for the whole +% second, do the whole alignment without the rules to find its size + \Xheight\z@ + \setbox\z@\vbox{\ialign{&\hfil${}##{}$\hfil\cr + \global\let\br\br@label #1\cr % upper labels + \global\let\br\br@down #1\cr % upper braces + #2\cr % main line of the formula + \global\let\br\br@up #3\cr % lower braces + \global\let\br\br@label #3\cr % lower labels + \noalign{\kern4pt}% Extra space + #4\cr % special labels + }}% finished whole alignment and \vbox. + \Xheight\ht\z@ \global\let\XV\relax +% finally, do the whole alignment yet again in its final format + \setbox\z@\vbox{\ialign{\XV\hfil${}##{}$\hfil\XV&&\hfil${}##{}$\hfil\XV\cr + \global\let\br\br@label #1\cr % upper labels + \global\let\br\br@down #1\cr % upper braces + #2\cr % main line of the formula + \global\let\br\br@up #3\cr % lower braces + \global\let\br\br@label #3\cr % lower labels + \noalign{\kern4pt \global\let\XV\XVR}% Extra space + #4\cr % special labels + }}% finished whole alignment and \vbox. + \advance\dimen@\ht\z@ + \lower\dimen@\hbox{\box\z@}% move alignment to get the desired height +}} + +\def\XVR{\kern-.05pt\vbox to\z@{\vss\hrule width.1pt height\Xheight}\kern-.05pt} + +\begin{document} + +\maketitle + +\parskip=4pt +\linespread{1.05}\selectfont + +\noindent Sometimes one would like to interleave braces labelling +parts of an equation, like in +$$ + \overunderbraces{&\br{2}{x}& &\br{2}{y}}% + {a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m}% + {& &\br{3}{z}} + = \pi r^2 +$$ +which is something that straightforward \verb"\overbrace" and +\verb"\underbrace" cannot do. + +There is a trick, which I heard from Etienne Riga, that works well +for simple cases without requiring any packages or new commands, and +it involves \emph{overprinting} parts of the equation: +put an overlapping \verb"\overbrace" (or \verb"\underbrace") +into \verb"\rlap{$...$}", and insert it into the equation. +This does not easily handle the multiple-overlap of the example +above (the overlapping gets misaligned) but can do +$$ +\rlap{$\overbrace{A+B}^x$}A+\underbrace{B+C}_z +$$ +with \verb"\rlap{$\overbrace{A+B}^x$}A+\underbrace{B+C}_z". + +The oubraces package provides an alternative solution (for both plain +\TeX\ and \LaTeX) based on visual formatting into columns, like an array +or table. The formula at top is then produced by +\begin{verbatim} + \overunderbraces{&\br{2}{x}& &\br{2}{y}}% + {a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m}% + {& &\br{3}{z}} + = \pi r^2 +\end{verbatim} + +First, (on paper or imagination) write the formula +and divide it into segments at the tip of each brace. +In our example there are seven segments: +$$ + \Xoverunderbraces{&\br{2}{x}& &\br{2}{y}}% + {a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m}% + {& &\br{3}{z}}% + {1&2&3&4&5&6&7} + = \pi r^2 +$$ +although segments 1 and 7 could be omitted. +We will type the main line of the formula with \verb"&" inserted +between each segment: +\begin{verbatim} + a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m +\end{verbatim} +Each segment then becomes a column in an alignment, +and each brace may span multiple columns. The idea is best +illustrated by a \LaTeX{} array: +\begin{verbatim} +\begin{array}[c]{ccccccc} + & \multicolumn{2}{c}{x}& & \multicolumn{2}{c}{y}\\ + & \multicolumn{2}{c}{\downbracefill}& + & \multicolumn{2}{c}{\downbracefill}\\ + a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m\\ + & & \multicolumn{3}{c}{\upbracefill}\\ + & & \multicolumn{3}{c}{z} +\end{array} = \pi r^2 +\end{verbatim} +This doesn't work well at all, having bad braces with bad vertical and +horizontal spacing. We should instead use \TeX's primitive +\verb"\halign" command, and measure the size of boxes to get the +correct vertical positioning of the formula's main line. Rather +than type the very messy \TeX\ commands directly with each use, +it is better to make a new command: +$$ +\hbox to\hsize{\indent\verb"\overunderbraces{"{\sl + upper\_braces\/}\verb"}{"{\sl main\_formula\/}\verb"}{"{\sl + lower\_braces\/}\verb"}"\hfil} +$$ +We already know how to write the main line of the formula +(by segmenting the formula and inserting \verb"&" between +segments), and we will also use \verb"&" between braces. +Each labelled brace will be specified in the format: +$$ +\hbox to\hsize{\indent\verb"\br{"$n$\verb"}{"\mbox{\sl + label\/}\verb"}"\hfil} +$$ +where $n$ is the number of segments spanned by the brace. +Each top brace of our example spans two segments (with an +empty segment between them) and the bottom +brace spans three segments, so they are specified by: + +\medskip +\indent \hbox to8em{top braces:\hfil}\verb" &\br{2}{x}& &\br{2}{y}"\\ +\indent \hbox to8em{bottom braces:\hfil}\verb" & &\br{3}{z}" + +\medskip + +Having determined all three parameters to use with +\verb"\over"\-\verb"under"\-\verb"braces", the complete command is +\begin{verbatim} + \overunderbraces{&\br{2}{x}& &\br{2}{y}}% + {a + b +&c + d +&e + f&+&g + h&+ i + j&+ k + l + m}% + {& &\br{3}{z}} + = \pi r^2 +\end{verbatim} +which produces the equation at the start of this article. + +\end{document} + +Here is the definition of \verb"\overunderbraces". It may look +long, but it has some repetition in order to measure the height of +the top half of the formula. There are also the auxiliary macros +\verb"\brAup", \verb"\brAdown", and \verb"\brAlabel" that allow +the same \verb"\br" command to produce up-braces, down-braces, and +centered labels at the appropriate places. + +\begin{verbatim} +% \overunderbraces{upper_braces}{main_formula}{lower_braces} +% +\def\overunderbraces #1#2#3{{% + \baselineskip=0pt \lineskip=4pt \lineskiplimit=4pt + \displaystyle % generate error if not in math mode! +% first, do the top half of the alignment in a save-box + \setbox0=\vbox{\ialign{&\hfil${}##{}$\hfil\cr + \global\let\br\brAlabel #1\cr % upper labels + \global\let\br\brAdown #1\cr % upper braces + #2\cr % main line of the formula + }}% finished partial alignment and \vbox. + \dimen0=-\ht0 % Measure height of partial alignment -- +% ... it is the height we want for the whole. +% Now do the whole alignment (notice the repetition from above) + \setbox0=\vbox{\ialign{&\hfil${}##{}$\hfil\cr + \global\let\br\brAlabel #1\cr % upper labels + \global\let\br\brAdown #1\cr % upper braces + #2\cr % main line of the formula + \global\let\br\brAup #3\cr % lower braces + \global\let\br\brAlabel #3\cr % lower labels + }}% finished whole alignment and \vbox. + \advance\dimen0 by\ht0 % calc. the necessary lowering + \lower\dimen0\hbox{\box0}% shift to get the desired height +}} + +% Three aliases for \br. +% #1=number of spanned columns, #2=label +\def\brAup#1#2{\multispan{#1}\upbracefill} +\def\brAdown#1#2{\multispan{#1}\downbracefill} +\def\brAlabel#1#2{\multispan{#1}\hidewidth $#2$\hidewidth} +\end{verbatim} + +If you check the definitions in oubraces.sty, you will +find some streamlining with `internal' commands such as \verb"\dimen@" +used for \verb"\dimen0". + +\end{document} |