From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- macros/latex/contrib/abraces/abraces-doc.pdf | Bin 0 -> 196440 bytes macros/latex/contrib/abraces/abraces-doc.tex | 214 +++++++++++++++++++++++++++ macros/latex/contrib/abraces/abraces.sty | 111 ++++++++++++++ 3 files changed, 325 insertions(+) create mode 100644 macros/latex/contrib/abraces/abraces-doc.pdf create mode 100644 macros/latex/contrib/abraces/abraces-doc.tex create mode 100644 macros/latex/contrib/abraces/abraces.sty (limited to 'macros/latex/contrib/abraces') diff --git a/macros/latex/contrib/abraces/abraces-doc.pdf b/macros/latex/contrib/abraces/abraces-doc.pdf new file mode 100644 index 0000000000..95030130fa Binary files /dev/null and b/macros/latex/contrib/abraces/abraces-doc.pdf differ diff --git a/macros/latex/contrib/abraces/abraces-doc.tex b/macros/latex/contrib/abraces/abraces-doc.tex new file mode 100644 index 0000000000..6db0fca990 --- /dev/null +++ b/macros/latex/contrib/abraces/abraces-doc.tex @@ -0,0 +1,214 @@ +% $Id: abraces-doc.tex,v 1.0 2012/08/31 00:00:00 wgrundlingh stable $ +\RequirePackage{xcolor}% http://ctan.org/pkg/xcolor (required to "overload" color package) +\documentclass{ltxdockit}[2011/03/25] +%\usepackage{xspace}% http://ctan.org/pkg/xspace (already loaded by ltxdockit) +\usepackage[overload]{abraces}% http://ctan.org/pkg/abraces +\usepackage{booktabs}% http://ctan.org/pkg/booktabs +\usepackage{shortvrb}% http://ctan.org/pkg/shortvrb +\usepackage{amsmath}% http://ctan.org/pkg/amsmath +\MakeShortVerb{\|} + +\rcsid{$Id: abraces.tex,v 1.0 2012/08/31 00:00:00 wgrundlingh stable $} +%\setcounter{secnumdepth}{2} +%\setcounter{tocdepth}{4} + +\newsavebox{\codebox}% For storing code segments in footer. +\newcommand*{\abracesctan}{http://ctan.org/pkg/abraces} + +\lstset{ + language={[LaTeX]TeX}, + morekeywords={% + aoverbrace, + aunderbrace, + color, + bracetext, + bracescript, + foxanddog, + newcolumntype, + newbracespec} +} + +\titlepage{% + title={The \sty{abraces} package}, + subtitle={Asymmetric or arbitrary braces}, + url={\abracesctan}, + author={Werner Grundlingh}, + email={latex.abraces@gmail.com}, + revision={\rcsrevision}, + date={\rcstoday}} + +\hypersetup{% + pdftitle={The abraces Package}, + pdfsubject={Asymmetric or arbitrary braces}, + pdfauthor={Werner Grundlingh}, + pdfkeywords={tex, latex, braces, overbrace, underbrace, math-mode}} + +\begin{document} + +\printtitlepage +%\tableofcontents + +\section{Introduction} \label{intro} + +The \sty{abraces}\footnote{The \sty{abraces} package: \url{http://ctan.org/pkg/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. + +\section{User interface} \label{user-interface} + +\sty{abraces} defines two counterparts to the existing braces: + +\begin{ltxsyntax} + +\cmditem{aoverbrace}[spec]{stuff} + +\cmditem{aunderbrace}[spec]{stuff} + +These create an overbrace and underbrace where \prm{spec} defines a construction pattern based on the elements in Table~\ref{tab:abrace-spec}. + +The provided 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/cust of the brace). 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. + +Other, more complex construction -- by means of the optional \prm{spec} argument -- can also be made by mixing the elements presented in Table~\ref{tab:abrace-spec}. + +\cmditem{newbracespec}{char}{spec} + +This allows the user to define a new brace specification \prm{char} the results in the (possibly complex) construction \prm{spec}. The usage is similar to that of a \lstinline!\newcolumntype! construction provided by the \sty{array}\footnote{The \sty{array} package: \url{http://ctan.org/pkg/array}} package. + +\cmditem{bracescript}{spec} + +Since the brace cusps may not fall directly at the horizontal centre of the construction, \lstinline|\bracescript| is provided that takes a similar construction-style interface to that of \prm{spec} in \lstinline|\aoverbrace| and \lstinline|\aunderbrace|. This allows the user to position the scripted text at the location(s) best-suited for presentation. + +\end{ltxsyntax} + + +\begin{table}[t] + \centering + \begin{tabular}{cl} + \toprule + \prm{spec} character & Output \\ + \midrule + |l| & $\bracelu$ \\ + |L| & $\braceld$ \\ + |r| & $\braceru$ \\ + |R| & $\bracerd$ \\ + |U| & $\braceru\bracelu$ \\ + |D| & $\bracerd\braceld$ \\ + |0| & (single) Empty fill \\ + |1|, \ldots,\verb|9| & Copies of regular fill \rule[.4ex]{2em}{1.5pt} \\ + |@{|\prm{stuff}|}| & Places \prm{stuff} into brace \\ + |!{|\prm{len}|}| & Regular fill of length \prm{len} \\ + |*{|\prm{num}|}{|\prm{stuff}|}| & Repeat \prm{stuff} a total of \prm{num} times \\ + \bottomrule + \end{tabular} + \caption{Character specifications \prm{spec} used to construct braces.} + \label{tab:abrace-spec} +\end{table} + +If the package is loaded with the \lstinline!overload! option + +\begin{lstlisting} +\usepackage[overload]{abraces} +\end{lstlisting} + +\noindent the traditional \lstinline!\overbrace! and \lstinline!\underbrace! pairs are redefined to be equivalent to \lstinline!\aoverbrace! and \lstinline!\aunderbrace!, respectively, via a straight-forward \lstinline!\let!: + +\begin{lstlisting} +\let\overbrace\aoverbrace +\let\underbrace\aunderbrace +\end{lstlisting} + +\section{Examples} + +Some examples of the types of braces that can be constructed using \sty{abraces}: + +\begin{lstlisting} +\newcommand{\foxanddog}{% + \textrm{The quick brown fox jumped over the lazy dog}} +\end{lstlisting} + +\newcommand{\foxanddog}{% + \textrm{The quick brown fox jumped over the lazy dog}} +\begin{itemize} + \item \lstinline!\aoverbrace{\foxanddog}! (traditional \lstinline!\overbrace!): \\ $\aoverbrace{\foxanddog}$ + \item \lstinline!\aunderbrace{\foxanddog}! (traditional \lstinline!\underbrace!): \\ $\aunderbrace{\foxanddog}$ + \item \lstinline!\aoverbrace[L3U1R]{\foxanddog}!: \\ $\aoverbrace[L3U1R]{\foxanddog}$ + \item \lstinline!\aoverbrace[l1D1r]{\foxanddog}!: \\ $\aoverbrace[l1D1r]{\foxanddog}$ + \item \lstinline!\aunderbrace[l2D7r]{\foxanddog}!: \\ $\aunderbrace[l2D7r]{\foxanddog}$ + \item \lstinline!\aunderbrace[l1D2U2D1r]{\foxanddog}!: \\ $\aunderbrace[l1D2U2D1r]{\foxanddog}$ + \item \lstinline!\aoverbrace[L1R]{\foxanddog}!: \\ $\aoverbrace[L1R]{\foxanddog}$ + \item \lstinline!\aunderbrace[L1U3R]{\foxanddog}!: \\ $\aunderbrace[L1U3R]{\foxanddog}$ + \item \lstinline!\aunderbrace[l6R0l3D3r0L6r]{\foxanddog}!: \\ $\aunderbrace[l6R0l3D3r0L6r]{\foxanddog}$ + \item \lstinline!\aoverbrace[L5*{3}{01}05U50*{3}{10}5R]{\foxanddog}!: \\ $\aoverbrace[L5*{3}{01}05U50*{3}{10}5R]{\foxanddog}$ + \item \lstinline!\aunderbrace[l1@{\hspace{5em}}2D2@{\hspace{3em}}1r]{\foxanddog}!: \\ $\aunderbrace[l1@{\hspace{5em}}2D2@{\hspace{3em}}1r]{\foxanddog}$ + \item \lstinline~\aunderbrace[l1R@{\color{red!80!white}}L1r]{\foxanddog}~: \\ $\aunderbrace[l1R@{\color{red!80!white}}L1r]{\foxanddog}$ + \item \lstinline~\aoverbrace[L1D!{5em}R]{\foxanddog}~: \\ $\aoverbrace[L1D!{5em}R]{\foxanddog}$ +\end{itemize} + +The next question might be how to add content to the brace cusps. Here's a possible way to insert text at the appropriate ratio, using the above construction techniques: + +\newcommand{\bracetext}[1]{% + \makebox[0pt][c]{\scriptsize#1}}% +\[ + \overbrace[L2U2D1U1R]{\foxanddog}^{% + \bracescript{L2r@{\bracetext{left}}l2D1r@{\bracetext{right}}l1R}% + }% +\] + +\begin{lstlisting} +\newcommand{\bracetext}[1]{% + \makebox[0pt][c]{\scriptsize#1}}% +\[ + \overbrace[L2U2D1U1R]{\foxanddog}^{% + \bracescript{L2r@{\bracetext{left}}l2D1r@{\bracetext{right}}l1R}% + }% +\] +\end{lstlisting} + +\begin{lrbox}{\codebox}\footnotesize\lstinline!\overbrace!\end{lrbox}% Capture code in \codebox +Another usage might include ``breaking'' a brace across lines to indicate a continuous grouping of objects. The following 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 which ``spans'' multiple lines: + +\begin{multline*} + f(x)=a_0+a_1x+a_2x^2+ + \aoverbrace[L1U1]{a_3x^3+a_4x^4+\cdots+a_{i-1}x^{i-1}+\hspace{1em}}^ + {\bracescript{L1r@{\bracetext{some text}}l1}} \\[\jot] + \aoverbrace[1R]{\hspace{1em}a_ix^i+a_{i+1}x^{i+1}}+\cdots+a_{n-1}x^{n-1} +\end{multline*} + +\begin{lstlisting} +\usepackage{amsmath}% http://ctan.org/pkg/amsmath +%... +\begin{multline*} + f(x)=a_0+a_1x+a_2x^2+ + \aoverbrace[L1U1]{a_3x^3+a_4x^4+\cdots+a_{i-1}x^{i-1}+\hspace{1em}}^ + {\bracescript{L1r@{\bracetext{some text}}l1}} \\[\jot] + \aoverbrace[1R]{\hspace{1em}a_ix^i+a_{i+1}x^{i+1}}+ + \cdots+a_{n-1}x^{n-1} +\end{multline*} +\end{lstlisting} + +As a final example, consider a brace that should include a dashed component. Using \lstinline|\newbracespec| one can define your own dashed component: + +\begin{lstlisting} +\newbracespec{d}{% + 5@{\hspace{4pt}}1@{\hspace{4pt}}!{2em}@{\hspace{4pt}}1@{\hspace{4pt}}5% +} +\end{lstlisting} + +\noindent and then use + +\begin{lstlisting} +\[ + \aunderbrace[l*{3}{d}D*{3}{d}r]{\foxanddog}_ + {\bracetext{What happened to the cat?}} +\] +\end{lstlisting} + +\newbracespec{d}{1@{\hspace{4pt}}1@{\hspace{4pt}}!{1em}@{\hspace{4pt}}1@{\hspace{4pt}}1} + +\[ \aunderbrace[l*{3}{d}D*{3}{d}r]{\foxanddog}_{\bracetext{What happened to the cat?}} \] + +\section{Terms of reference} + +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 \sty{mathtools}\footnote{The \sty{mathtools} package: \url{http://ctan.org/pkg/mathtools}} package. + +This material is released under and subject to the \href{http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html}{LaTeX Project Public Licence}. + +\end{document} \ No newline at end of file diff --git a/macros/latex/contrib/abraces/abraces.sty b/macros/latex/contrib/abraces/abraces.sty new file mode 100644 index 0000000000..768afbb3cd --- /dev/null +++ b/macros/latex/contrib/abraces/abraces.sty @@ -0,0 +1,111 @@ +\ProvidesPackage{abraces}% http://ctan.org/pkg/abraces + [2012/08/24 v1.0 Arbitrary and asymmetric braces] +\newif\if@overload +\DeclareOption{overload}{\@overloadtrue} +\ProcessOptions +\newsavebox{\bracebox}% stores content contained under/over brace + +\newcommand{\newbracespec}[2]{% Add a new brace specification based on existing ones + \@defbracecharcode{#1}{\@genbrace#2\@nnil\@genbrace} +} +% Brace components +\newcommand{\bracescript}[1]{{% Add a script above/below an over-/underbrace + \let\@@bfil\@@bunfil% Make line leaders into void/empty leaders + \let\@use@rl@se\phantom% Phantomize some brace components + \makebox[\wd\bracebox]{$\genbrace{#1}$}% Place the text in a box of width \bracebox +}} +\def\@@bunfil{\leaders\hbox{\ }\hfill}% Empty filler +\newcommand{\bracefil}[1]{% + \csname brace@char@#1'\endcsname% +} +\def\@@bfil{\leaders \vrule \@height \ht\z@ \@depth \z@ \hfill}% default brace filler +%\def\bfil{\@@bfil}% +%\def\@bLfil{\@@bfil}% left leader filler +%\def\@bRfil{\@@bfil}% right leader filler +\def\aupbracefill#1{$\m@th\setbox\z@\hbox{$\braceld$}\genbrace{#1}$} +\def\adownbracefill#1{$\m@th\setbox\z@\hbox{$\braceld$}\genbrace{#1}$} + +% Repetition structure. Reference: +% Repeat command n times? +% http://tex.stackexchange.com/q/16189/5764 +% Alternatively +% \RequirePackage{expl3}% http://ctan.org/pkg/expl3 +% \ExplSyntaxOn +% \cs_new_eq:NN \Repeat \prg_replicate:nn +% \ExplSyntaxOff + +\newcommand{\Repeat}[1]{% + \expandafter\@Repeat\expandafter{\the\numexpr #1\relax}% +} +\def\@Repeat#1{% + \ifnum#1>0 + \expandafter\@@Repeat\expandafter{\the\numexpr #1-1\expandafter\relax\expandafter}% + \else + \expandafter\@gobble + \fi +} +\def\@@Repeat#1#2{% + \@Repeat{#1}{#2}#2% +} +% Taken from mathtools package (http://ctan.org/pkg/mathtools) +\newcommand{\aunderbrace}[2][l1D1r]{% + \begin{lrbox}{\bracebox}$\displaystyle{#2}$\end{lrbox}% + \mathop{\vtop{\m@th\ialign{##\crcr + $\hfil\displaystyle{#2}\hfil$\crcr + \noalign{\kern.7\fontdimen5\textfont2\nointerlineskip}% + \aupbracefill{#1}\crcr\noalign{\kern.5\fontdimen5\textfont2}}}}\limits} +\newcommand{\aoverbrace}[2][L1U1R]{% + \begin{lrbox}{\bracebox}$\displaystyle{#2}$\end{lrbox}% + \mathop{\vbox{\m@th\ialign{##\crcr + \noalign{\kern.5\fontdimen5\textfont2}% + \adownbracefill{#1}\crcr + \noalign{\kern.7\fontdimen5\textfont2\nointerlineskip}% + $\hfil\displaystyle{#2}\hfil$\crcr}}}\limits} + +% Parsing structure. Reference: +% Parsing a macro argument character-by-character for conditional execution +% http://tex.stackexchange.com/q/33197/5764 + +\let\@use@rl@se\relax +\def\@defbracecharcode#1{% Macro to define brace character "codes" + \@namedef{brace@char@#1}% +} +\@defbracecharcode{L}{\@use@rl@se\braceld\@genbrace}% Left down +\@defbracecharcode{R}{\@use@rl@se\bracerd\@genbrace}% Right down +\@defbracecharcode{l}{\@use@rl@se\bracelu\@genbrace}% Left up +\@defbracecharcode{r}{\@use@rl@se\braceru\@genbrace}% Right up +\@defbracecharcode{U}{\@use@rl@se\braceru\@use@rl@se\bracelu\@genbrace}% Tip up +\@defbracecharcode{D}{\@use@rl@se\bracerd\@use@rl@se\braceld\@genbrace}% Tip down +\@defbracecharcode{0}{\@@bunfil\@genbrace}% Do nothing +\@defbracecharcode{1}{\@@bfil\@genbrace}% 1 filler +\@defbracecharcode{2}{\@@bfil\@@bfil\@genbrace}% 2 fillers +\@defbracecharcode{3}{\@@bfil\@@bfil\@@bfil\@genbrace}% 3 fillers +\@defbracecharcode{4}{\@@bfil\@@bfil\@@bfil\@@bfil\@genbrace}% 4 fillers +\@defbracecharcode{5}{\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@genbrace}% 5 fillers +\@defbracecharcode{6}{\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@genbrace}% 6 fillers +\@defbracecharcode{7}{\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@genbrace}% 7 fillers +\@defbracecharcode{8}{\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@genbrace}% 8 fillers +\@defbracecharcode{9}{\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@@bfil\@genbrace}% 9 fillers +\@defbracecharcode{@}{\@firstofone@go}% Insert arbitrary stuff +\@defbracecharcode{!}{\@firstofone@len}% Insert a leader of specific length +\@defbracecharcode{*}{\@repeat@num@times}% Repeat stuff a number of times + +\newcommand{\@firstofone@go}[1]{#1\@genbrace}% +\newcommand{\@firstofone@len}[1]{\hb@xt@#1{\@@bfil}\@genbrace}% +\newcommand{\@repeat@num@times}[2]{\Repeat{#1}{\@genbrace#2\@nnil}\@genbrace}% + +\newcommand{\@genbrace}[1]{% + \ifx\@nnil#1\relax\else + \@nameuse{brace@char@#1\expandafter}% + \fi% +} +\newcommand{\genbrace}[1]{% + \@genbrace#1\@nnil% +} + +% If package was loaded with \usepackage[overload]{abraces} +\if@overload + \let\overbrace\aoverbrace + \let\underbrace\aunderbrace +\fi +\endinput \ No newline at end of file -- cgit v1.2.3