Debian Codegraph @

texmf-dist/doc/latex/abraces/abraces-doc.tex

raw
1 % $Id: abraces-doc.tex,v 2.2 2024/08/02 00:00:00 wgrundlingh stable $
2 \RequirePackage{xcolor}% http://ctan.org/pkg/xcolor (required to "overload" color package)
3 \documentclass[10pt]{ltxdockit}[2011/03/25]
4
5 %\usepackage{xspace}% Already loaded by ltxdockit
6 \usepackage[overload]{abraces}
7 \usepackage{booktabs,shortvrb,amsmath,xfp}
8 \MakeShortVerb{\|}
9
10 \rcsid{$Id: abraces.tex,v 2.2 2024/08/02 00:00:00 wgrundlingh stable $}
11 %\setcounter{secnumdepth}{2}
12 %\setcounter{tocdepth}{4}
13
14 % https://tex.stackexchange.com/a/472150/5764
15 % Use cases for breaking a paragraph that is not visible to the end user, forcing the paragraph to be set with a full-width/-length
16 % last line. Then one could insert a \pagebreak if needed, depending on the layout requirements
17 \newcommand{\parnopar}[1][]{\parfillskip=0pt\par%
18 #1%
19 \parskip=0pt\noindent\parfillskip=0pt plus1fil}
20
21 \newsavebox{\codebox}% For storing code segments in footer.
22 \newcommand*{\abracesctan}{http://ctan.org/pkg/abraces}
23
24 \lstset{
25 language={[LaTeX]TeX},
26 morekeywords={%
27 aoverbrace,
28 aunderbrace,
29 color,
30 bracetext,
31 bracescript,
32 FnD,
33 newcolumntype,
34 newbracespec,
35 bracecolor,
36 color,
37 textcolor,
38 aftergroup,
39 text}
40 }
41
42 \titlepage{%
43 title={The \sty{abraces} package},
44 subtitle={Asymmetric or arbitrary braces},
45 url={\abracesctan},
46 author={Werner Grundlingh},
47 email={[email protected]},
48 revision={\rcsrevision},
49 date={\rcstoday}}
50
51 \hypersetup{%
52 pdftitle={The abraces package},
53 pdfsubject={Asymmetric or arbitrary braces},
54 pdfauthor={Werner Grundlingh ([email protected])},
55 pdfkeywords={tex, latex, braces, overbrace, underbrace, math-mode}}
56
57 \usepackage{parskip}
58
59 \newlength{\bracecusplen}
60 \settowidth{\bracecusplen}{$\braceru\bracelu$}
61
62 \begin{document}
63
64 \printtitlepage
65 %\tableofcontents
66
67 \section{Introduction} \label{sec:introduction}
68
69 The \href{http://ctan.org/pkg/abraces}{\sty{abraces} package} provides a character key-driven interface to supplement new constructions of the traditional \lstinline!\overbrace! and \lstinline!\underbrace! pairs in an asymmetric or arbitrary way.
70
71 \section{Basic user interface} \label{sec:user-interface}
72
73 This package defines two counterparts to the existing braces:
74
75 \begin{ltxsyntax}
76
77 \cmditem{aoverbrace}[brace spec]{stuff}[script spec]\lstinline!^{!\prm{upper script}\lstinline!}_{!\prm{lower script}\lstinline!}!
78
79 \cmditem{aunderbrace}[brace spec]{stuff}[script spec]\lstinline!^{!\prm{upper script}\lstinline!}_{!\prm{lower script}\lstinline!}!
80
81 \end{ltxsyntax}
82
83 Note that both the \prm{brace spec} and \prm{script spec} arguments are optional, as well as the use of an \prm{upper script} and \prm{lower script}. As such, in its most basic form, \lstinline!\aoverbrace{!\prm{stuff}\lstinline!}! (and \lstinline!\aunderbrace{!\prm{stuff}\lstinline!}!) would be similar to the traditional \lstinline!\overbrace{!\prm{stuff}\lstinline!}! (and \lstinline!\underbrace{!\prm{stuff}\lstinline!}!). However, if you specify a \prm{brace spec} -- a construction pattern based on the elements in \hyperref[tab:abrace-spec]{Table~\ref*{tab:abrace-spec}} -- you could adjust the shape of the brace in an arbitrary way. These definitions are robust.
84
85 The \prm{brace spec} interface is based on a ratio-principle, allowing one to put a larger share of ``filler'' (the horizontal rule) at any location within the brace construction. The traditional \lstinline!\overbrace! and \lstinline!\underbrace! pairs have a \mbox{1:1} share between the left and right side (either side of the tip/cusp of the brace), thereby forcing the tip/cust to be placed directly in the center horizontally. With \lstinline!abraces!, using a \mbox{1:2} ratio would place the brace cusp one third (from the left) into the brace. Similary a \mbox{3:2} ratio would place the cusp 40\% (or two fifths) from the right edge of the brace. The same holds for elements specified within \prm{script spec}, except these are used to alter the location of the scrips. For more detail, see section \hyperref[sec:advanced-interface]{\ref*{sec:advanced-interface}~\nameref*{sec:advanced-interface}}.
86
87 Other, more complex constructions are possible by mixing the elements presented in \hyperref[tab:abrace-spec]{Table~\ref*{tab:abrace-spec}}. See section \hyperref[sec:examples]{\ref*{sec:examples} \nameref*{sec:examples}} for a showcase of uses.
88
89 \begin{ltxsyntax}
90
91 \cmditem{newbracespec}{char}{brace spec}
92
93 \end{ltxsyntax}
94
95 This allows the user to define a new brace specification \prm{char} that results in the (possibly complex) construction \prm{brace spec}. Note that \prm{char} should be different from any already used (see \hyperref[tab:abrace-spec]{Table~\ref*{tab:abrace-spec}}). The usage is similar to that of a \lstinline!\newcolumntype! construction provided by the \href{http://ctan.org/pkg/array}{\sty{array} package}.
96
97 \begin{table}[t]
98 \centering
99 \makeatletter
100 \begin{tabular}{cl}
101 \toprule
102 \prm{spec} character & Output \\
103 \midrule
104 |l| & $\bracelu$ (left upward brace) \\
105 |L| & $\braceld$ (left downward brace) \\
106 |r| & $\braceru$ (right upward brace) \\
107 |R| & $\bracerd$ (right downward brace)\\
108 |U| & $\braceru\bracelu$ (upward cusp) \\
109 |D| & $\bracerd\braceld$ (downward cusp) \\
110 |,[|\prm{len}|]| & % Similar to \downbracketend in abraces.sty
111 \sbox\z@{$\braceld$}\dimen@\ht\z@ \advance\[email protected]\fontdimen5\textfont2\relax
112 \vrule \@width\ht\z@ \@height\ht\z@ \@depth\dimexpr\dimen@-\ht\z@\ (downward end with optional \prm{len}gth control) \\
113 |'[|\prm{len}|]| & % Similar to \upbracketend in abraces.sty
114 \sbox\z@{$\bracelu$}\dimen@\ht\z@ \advance\[email protected]\fontdimen5\textfont2\relax
115 \vrule \@width\ht\z@ \@height\dimen@ \@depth\z@\ (upward end with optional \prm{len}gth control) \\
116 |0| & (single) Empty fill \\
117 |1|, \ldots, |9| & Copies of regular fill \rule[.4ex]{2em}{1.5pt} \\
118 |@{|\prm{stuff}|}| & Places \prm{stuff} into brace \\
119 |!{|\prm{len}|}| & Regular fill of length \prm{len} \\
120 |*{|\prm{num}|}{|\prm{stuff}|}| & Repeat \prm{stuff} a total of \prm{num} times \\
121 \bottomrule
122 \end{tabular}
123 \makeatother
124 \caption{Character specifications within \prm{brace spec} used to construct braces.}
125 \label{tab:abrace-spec}
126 \end{table}
127
128 By default, any scripts will be placed at the cusp (|D| when providing a \prm{lower script} via \lstinline|_| or |U| when providing an \prm{upper script} via \lstinline|^|) of the brace. If you use more than one cusp within your \prm{brace spec}, you can separate scripts using \lstinline!&! which will place them above/below subsequent brace cusps, similar to separating columns within a \lstinline!tabular!.
129
130 \begin{ltxsyntax}
131
132 \cmditem{bracecolor}{spec}
133
134 \end{ltxsyntax}
135
136 If you're interested in using any form of colour, \lstinline|\bracecolor| will allow you to change the brace colour via an \lstinline!@!-insertion (for example, \lstinline!@{\bracecolor{red}}! would yield a \textcolor{red}{red} brace from that point onward). Regular script colouring can still be achieved using \lstinline!\color! or \lstinline!\textcolor!. The motivation here is that elements within the \lstinline!@!-insertions are grouped; \lstinline!\bracecolor! uses \lstinline!\aftergroup! to re-insert the use of \lstinline!\color!.
137
138 If the package is loaded with the \lstinline!overload! option
139 \begin{lstlisting}
140 \usepackage[overload]{abraces}
141 \end{lstlisting}
142 the traditional \lstinline!\overbrace!/\lstinline!\underbrace! pairs are redefined to be equivalent to \lstinline!\aoverbrace! and \lstinline!\aunderbrace!, respectively, via a straight-forward \lstinline!\let!:
143 \begin{lstlisting}
144 \let\overbrace\aoverbrace
145 \let\underbrace\aunderbrace
146 \end{lstlisting}
147
148 \section{Advanced uses} \label{sec:advanced-interface}
149
150 There are some cases where you don't want to place elements exactly at the tip(s) of the brace(s). Maybe it's because you don't have any tips on your braces, or need to write other information around the tips. To that end, the second optional \prm{script spec} argument is provided where you can specify a new sequence that may differ from the original brace specification. Without any tips, for example, one could write \lstinline!$\aoverbrace[L1R]{a + b + \cdots +!\parnopar\lstinline!z}[U]^{\text{26 terms}}$! to denote a grouping of elements:
151 \[
152 \aoverbrace[L1R]{a + b + \cdots + z}[U]^{\text{26 terms}}
153 \]
154 More detailed examples are covered in section \hyperref[sec:examples]{\ref*{sec:examples}~\nameref*{sec:examples}}.
155
156 \section{Examples} \label{sec:examples}
157
158 Some basic examples of the types of braces that can be constructed using \sty{abraces}:
159 \begin{lstlisting}
160 \newcommand{\FnD}{%
161 \textrm{The quick brown fox jumped over the lazy dog}}
162 \end{lstlisting}
163
164 \newcommand{\FnD}{%
165 \textrm{The quick brown fox jumped over the lazy dog}}
166 \begin{itemize}
167 \item \lstinline!\aoverbrace{\FnD}! (traditional \lstinline!\overbrace!): \\
168 $\aoverbrace{\FnD}$
169
170 \item \lstinline!\aunderbrace{\FnD}! (traditional \lstinline!\underbrace!): \\
171 $\aunderbrace{\FnD}$
172
173 \item \lstinline!\aoverbrace[L3U1R]{\FnD}!: \\
174 $\aoverbrace[L3U1R]{\FnD}$
175
176 \item \lstinline!\aoverbrace[*{6}{0}l1D1r*{5}{0}]{\FnD}!: \\
177 $\aoverbrace[*{6}{0}l1D1r*{5}{0}]{\FnD}$
178
179 \item \lstinline~\aunderbrace[l2D1r000@{\bracecolor{blue!70!black}}l1D2r]{\FnD}~: \\
180 $\aunderbrace[l2D1r000@{\bracecolor{blue!70!black}}l1D2r]{\FnD}$
181
182 \item \lstinline!\aunderbrace[l1D2U2D1r]{\FnD}!: \\
183 $\aunderbrace[l1D2U2D1r]{\FnD}$
184
185 \item \lstinline!\aoverbrace[L1R]{\FnD}!: \\
186 $\aoverbrace[L1R]{\FnD}$
187
188 \item \lstinline!\aunderbrace[L1U3R]{\FnD}!: \\
189 $\aunderbrace[L1U3R]{\FnD}$
190
191 \item \lstinline!\aunderbrace['6,0l3D3r0,6']{\FnD}!: \\
192 $\aunderbrace['6,0l3D3r0,6']{\FnD}$
193
194 \item \lstinline!\aoverbrace[L5*{3}{01}05U50*{3}{10}5R]{\FnD}!: \\
195 $\aoverbrace[L5*{3}{01}05U50*{3}{10}5R]{\FnD}$
196
197 \item \lstinline!\aunderbrace[l1@{\hspace{5em}}2D2@{~\ldots~}1r]{\FnD}!: \\
198 $\aunderbrace[l1@{\hspace{5em}}2D2@{~\ldots~}1r]{\FnD}$
199
200 \item \lstinline~\aunderbrace[l1R@{\bracecolor{red!80!white}}L1r]{\FnD}~: \\
201 $\aunderbrace[l1R@{\bracecolor{red!80!white}}L1r]{\FnD}$
202
203 \item \lstinline~\aoverbrace[,1D!{5em},]{\FnD}~: \\
204 $\aoverbrace[,1D!{5em},]{\FnD}$
205 \end{itemize}
206
207 Some more advanced techniques of adding content to the brace cusps:
208 \begin{itemize}
209 \item \lstinline!\aoverbrace[L1U2R]{\FnD}^{\text{one-third of the way}}!: \\
210 $\aoverbrace[L1U2R]{\FnD}^{\text{one-third of the way}}$
211
212 \item \lstinline!\aoverbrace[L1U1D1U1R]{\FnD}^{\text{left} & \text{right}}!: \\
213 $\aoverbrace[L1U1D1U1R]{\FnD}^{\text{left} & \text{right}}$
214
215 \item \lstinline!\aoverbrace[L1U1D1U1R]{\FnD}! \\
216 \quad\lstinline![L1U1U1U1R]^{\text{left} & \text{middle} & \text{right}}!: \\
217 $\aoverbrace[L1U1D1U1R]{\FnD}[L*{3}{1U}1R]^{\text{left} & \text{middle} & \text{right}}$
218
219 \item
220 \newcommand{\ind}[1][1]{\hspace*{\fpeval{#1*1.5}em}}%
221 \lstinline!\newbracespec{u}! \\
222 \ind\lstinline!{@{\hspace{-.5\bracecusplen}}U@{\hspace{-.5\bracecusplen}}}! \\
223 \lstinline!\newbracespec{d}! \\
224 \ind\lstinline!{@{\hspace{-.5\bracecusplen}}D@{\hspace{-.5\bracecusplen}}}! \\
225 \lstinline!$\aunderbrace! \\
226 \ind[1]\lstinline![00l2@{\hspace{-\bracecusplen}}1r]{% \aunderbrace brace script! \\
227 \ind[2]\lstinline!\aoverbrace! \\
228 \ind[3]\lstinline![L1@{\hspace{-\bracecusplen}}1R000]% \aoverbrace brace script! \\
229 \ind[3]\lstinline!{\FnD}% stuff! \\
230 \ind[3]\lstinline![1u13]% \aoverbrace script spec! \\
231 \ind[3]\lstinline!^{2/5}% \aoverbrace upper script! \\
232 \ind\lstinline!}! \\
233 \lstinline![43d3]% \aunderbrace script spec! \\
234 \lstinline!_{3/5}$% \aunderbrace lower script!: \\
235 \newbracespec{u}{@{\hspace{-.5\bracecusplen}}U@{\hspace{-.5\bracecusplen}}}%
236 \newbracespec{d}{@{\hspace{-.5\bracecusplen}}D@{\hspace{-.5\bracecusplen}}}%
237 $\aunderbrace
238 [00l2@{\hspace{-\bracecusplen}}1r]{% \aunderbrace brace script
239 \aoverbrace
240 [L1@{\hspace{-\bracecusplen}}1R000]% \aoverbrace brace script
241 {\FnD}% stuff
242 [1u13]% \aoverbrace script spec
243 ^{2/5}% \aoverbrace upper script
244 }
245 [43d3]% \aunderbrace script spec
246 _{3/5}$% \aunderbrace lower script
247
248 \item
249 \lstinline!\newbracespec{a}{@{\hspace{-.5\bracecusplen}}D}! \\
250 \quad\lstinline!\newbracespec{z}{D@{\hspace{-.5\bracecusplen}}}! \\
251 \quad\lstinline!\aunderbrace[l1r]{\FnD}! \\
252 \quad\quad\lstinline![a1z]_{\text{\rlap{far left}} & \text{\llap{far right}}}!: \\
253 \newbracespec{a}{@{\hspace{-.5\bracecusplen}}D}%
254 \newbracespec{z}{D@{\hspace{-.5\bracecusplen}}}%
255 $\aunderbrace[l1r]{\FnD}[a1z]_{\text{\rlap{far left}} & \text{\llap{far right}}}$
256 \end{itemize}
257
258 \begin{lrbox}{\codebox}\footnotesize\lstinline!\overbrace!\end{lrbox}% Capture code in \codebox
259 Here is a real-world example where ``breaking'' a brace across lines is required to indicate a continuous grouping of objects. This example\footnote{Taken from the question \href{http://tex.stackexchange.com/q/25510/5764}{\usebox{\codebox} split across multiple lines} on the TeX StackExchange network.} constructs two open-ended \lstinline!\aoverbrace!s that ``span'' multiple lines:
260
261 \begin{multline*}
262 f(x) = a_0 + a_1 x + a_2 x^2 +
263 \aoverbrace[L1U1@{~\ldots}]{a_3 x^3 + a_4 x^4 + \dots +
264 a_{i - 1} x^{i - 1} + \quad}^
265 {\text{some text}} \\[\jot]
266 \aoverbrace[@{\ldots~}1R]{\quad a_i x^i + a_{i + 1} x^{i + 1}} +
267 \dots + a_{n - 1} x^{n - 1}
268 \end{multline*}
269
270 \begin{lstlisting}
271 \usepackage{amsmath}% http://ctan.org/pkg/amsmath
272 %...
273 \begin{multline*}
274 f(x) = a_0 + a_1 x + a_2 x^2 +
275 \aoverbrace[L1U1@{~\ldots}]{a_3 x^3 + a_4 x^4 + \dots +
276 a_{i - 1} x^{i - 1} + \quad}^
277 {\text{some text}} \\[\jot]
278 \aoverbrace[@{\ldots~}1R]{\quad a_i x^i + a_{i + 1} x^{i + 1}} +
279 \dots + a_{n - 1} x^{n - 1}
280 \end{multline*}
281 \end{lstlisting}
282
283 As a final example, consider a brace that should include a dashed component. Using \lstinline|\newbracespec| one can define your own dashed component:
284 \begin{lstlisting}
285 \newbracespec{d}{%
286 5@{\hspace{4pt}}1@{\hspace{4pt}}!{2em}@{\hspace{4pt}}1@{\hspace{4pt}}5%
287 }
288 \end{lstlisting}
289 \noindent and then use
290 \begin{lstlisting}
291 \[
292 \aunderbrace[l*{3}{d}D*{3}{d}r]{\FnD}_{\text{What happened to the cat?}}
293 \]
294 \end{lstlisting}
295 \[
296 \newbracespec{d}{1@{\hspace{4pt}}1@{\hspace{4pt}}!{1em}@{\hspace{4pt}}1@{\hspace{4pt}}1}
297 \aunderbrace[l*{3}{d}D*{3}{d}r]{\FnD}_{\text{What happened to the cat?}}
298 \]
299
300 \section{Terms of reference}
301
302 This package originated from a question on the TeX StackEchange network called \href{http://tex.stackexchange.com/q/68526/5764}{Asymmetric overbrace}. Some code was taken from the \href{http://ctan.org/pkg/mathtools}{\sty{mathtools} package}.
303
304 This material is released under and subject to the \href{https://latex-project.org/lppl/}{LaTeX Project Public Licence}.
305
306 \section{Acknowledgements}
307
308 Thanks to Frank Mittlebach who stepped in and suggested an improvement in the original way \sty{abraces} functioned. Expansions included the use of \LaTeX3 command interface.
309
310 \section{Change log}
311
312 \begin{itemize}
313 \item v2.2 (2024-08-02) Minor update
314
315 \begin{itemize}
316 \item
317 Added \href{http://ctan.org/pkg/xcolor}{\sty{xcolor}} dependency to always have \lstinline|\bracecolor| available.
318 \end{itemize}
319
320 \item v2.1 (2022-11-06) Minor update
321
322 \begin{itemize}
323 \item
324 \lstinline|\Repeat| is replaced by something more obscure (\lstinline|\Repeat@br@ces|) to avoid other package conflicts.
325 \end{itemize}
326
327 \item v2.0 (2021-03-31) Major update
328
329 \begin{itemize}
330 \item
331 The package now uses \href{http://ctan.org/pkg/xparse}{\sty{xparse}} for macro definitions.
332
333 \item
334 Included an automated way for handling elementary/default scripts. The placement of scripts can still be modified using the \lstinline|\bracescript| interface.
335
336 \item
337 The documentation was also updated to reflect the changes.
338 \end{itemize}
339
340 \item v1.0 (2012-08-31) Initial release
341 \end{itemize}
342
343 \end{document}