diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/stackengine/stackengine.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/stackengine/stackengine.sty | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/stackengine/stackengine.sty b/Master/texmf-dist/tex/latex/stackengine/stackengine.sty new file mode 100644 index 00000000000..3c7176ec07b --- /dev/null +++ b/Master/texmf-dist/tex/latex/stackengine/stackengine.sty @@ -0,0 +1,235 @@ +\ProvidesPackage{stackengine} +[2013/06/12 v1.0 + Stacking text and objects in convenient ways] +% 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.3c 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 Steven B. Segletes. +% +% V1.0 Initial release. + +\usepackage{calc} +\usepackage{readarray} + +\newcounter{stackindex} +\newlength\Sstackgap +\newlength\Lstackgap +\newlength\boxshift +\newlength\stack@tmplength +\global\newlength\stackedboxwidth +\newsavebox\addedbox +\newsavebox\anchorbox +\newsavebox\stackedbox + +\newcommand\stackgap{\if S\stacktype\the\Sstackgap\else\the\Lstackgap\fi} + +\global\Sstackgap=3pt % SHORTSTACKING GAP BETWEEN ITEMS (SAME AS \shortstack) +\global\Lstackgap=\baselineskip % LONGSTACKING GAP BETWEEN ITEMS (def. \baselineskip) +\def\useanchorwidth{F}% T= FORCE BOX WIDTH TO ANCHOR-WIDTH +\def\quietstack{F}% T = SUPPRESS OUTPUT OF ALL COMMANDS +% (USE \usebox{\stackedbox} TO RETRIEVE) +\def\stackalignment{c}% l, c, or r for left, center or right alignment +\def\stacktype{S}% S for constant gap shortstack; + % L for constant baselineskip longstack +\def\usestackstrut{T}% + +%\stackengine{\Sstackgap or \Lstackgap or \stackgap or stacklength} +% {anchor} +% {item} +% {O or U} +% {\stackalignment or l or c or r} +% {\quietstack or T or F} +% {\useanchorwidth or T or F} +% {\stacktype or S or L} +\newcommand*\stackengine[8]{% + \sbox{\stackedbox}{% + \sbox{\anchorbox}{#2}% + \sbox{\addedbox}{#3}% + \settowidth{\stackedboxwidth}{#2}% + \if F#7% + \ifdim\wd\addedbox>\stackedboxwidth% + \settowidth{\stackedboxwidth}{#3}% + \fi% + \fi% + \setlength{\boxshift}{#1}% + \if L#8% + \if U#4% + \setlength{\boxshift}{-\boxshift}% + \fi% + \else% + \if U#4% + \setlength{\boxshift}{-\dp\anchorbox -\ht\addedbox -\boxshift}% + \else% + \setlength{\boxshift}{\ht\anchorbox +\dp\addedbox +\boxshift}% + \fi% + \fi% + \if c#5% + \hspace{.5\stackedboxwidth}% + \hspace{-.5\wd\anchorbox}% + \usebox{\anchorbox}% + \hspace{-.5\wd\anchorbox}% + \hspace{-.5\wd\addedbox}% + \raisebox{\boxshift}{#3}% + \hspace{-.5\wd\addedbox}% + \hspace{.5\stackedboxwidth}% + \else% + \if l#5% + \usebox{\anchorbox}% + \hspace{-\wd\anchorbox}% + \raisebox{\boxshift}{#3}% + \hspace{-\wd\addedbox}% + \hspace{\stackedboxwidth}% + \else% + \if r#5% + \hspace{\stackedboxwidth}% + \hspace{-\wd\anchorbox}% + \usebox{\anchorbox}% + \hspace{-\wd\addedbox}% + \raisebox{\boxshift}{#3}% + \fi% + \fi% + \fi% + }% + \if F#6\usebox{\stackedbox}\fi% +} + +\newcommand*\stackunder[3][\stackgap]{% + \stackengine{#1}{#2}{#3}{U}{\stackalignment}{\quietstack}{\useanchorwidth}% + {\stacktype}} + +\newcommand*\stackon[3][\stackgap]{% + \stackengine{#1}{#2}{#3}{O}{\stackalignment}{\quietstack}{\useanchorwidth}% + {\stacktype}} + +\newcommand*\Shortstack[2][\stackalignment]{% + \getargsC{#2}% + \setcounter{stackindex}{1}% + \sbox{\stackedbox}{\argi}% + \whiledo{\thestackindex < \narg}{% + \stepcounter{stackindex}% + \stackengine{\Sstackgap}{\csname arg\roman{stackindex}\endcsname}% + {\usebox{\stackedbox}}{O}{#1}{T}{\useanchorwidth}{S}% + }% + \if F\quietstack\usebox{\stackedbox}\fi% +} + +\newcommand*\Shortunderstack[2][\stackalignment]{% + \getargsC{#2}% + \setcounter{stackindex}{\narg}% + \sbox{\stackedbox}{\csname arg\roman{stackindex}\endcsname}% + \whiledo{\thestackindex > 1}{% + \addtocounter{stackindex}{-1}% + \stackengine{\Sstackgap}{\csname arg\roman{stackindex}\endcsname}% + {\usebox{\stackedbox}}{U}{#1}{T}{\useanchorwidth}{S}% + }% + \if F\quietstack\usebox{\stackedbox}\fi% +} + +\newcommand*\Longstack[2][\stackalignment]{% + \getargsC{#2}% + \setcounter{stackindex}{1}% + \sbox{\stackedbox}{\argi}% + \whiledo{\thestackindex < \narg}{% + \stepcounter{stackindex}% + \stackengine{\Lstackgap}{\csname arg\roman{stackindex}\endcsname}% + {\usebox{\stackedbox}}{O}{#1}{T}{\useanchorwidth}{L}% + }% + \if F\quietstack\usebox{\stackedbox}\fi% +} + +\newcommand*\Longunderstack[2][\stackalignment]{% + \getargsC{#2}% + \setcounter{stackindex}{\narg}% + \sbox{\stackedbox}{\csname arg\roman{stackindex}\endcsname}% + \whiledo{\thestackindex > 1}{% + \addtocounter{stackindex}{-1}% + \stackengine{\Lstackgap}{\csname arg\roman{stackindex}\endcsname}% + {\usebox{\stackedbox}}{U}{#1}{T}{\useanchorwidth}{L}% + }% + \if F\quietstack\usebox{\stackedbox}\fi% +} + +\newcommand*\tllap[2][\Lstackgap]{% + \stackengine{#1}{}{#2}{O}{r}{\quietstack}{T}{L}% +} + +\newcommand*\tclap[2][\Lstackgap]{% + \stackengine{#1}{}{#2}{O}{c}{\quietstack}{T}{L}% +} + +\newcommand*\trlap[2][\Lstackgap]{% + \stackengine{#1}{}{#2}{O}{l}{\quietstack}{T}{L}% +} + +\newcommand*\bllap[2][\Lstackgap]{% + \stackengine{#1}{}{#2}{U}{r}{\quietstack}{T}{L}% +} + +\newcommand*\bclap[2][\Lstackgap]{% + \stackengine{#1}{}{#2}{U}{c}{\quietstack}{T}{L}% +} + +\newcommand*\brlap[2][\Lstackgap]{% + \stackengine{#1}{}{#2}{U}{l}{\quietstack}{T}{L}% +} + +\newcommand*\stackanchor[3][\stackgap]{% + \setlength{\stack@tmplength}{#1}% + \setlength{\stack@tmplength}{.5\stack@tmplength}% + \if T\usestackstrut% + \if S\stacktype\addtolength{\stack@tmplength}% + {.5\ht\strutbox-.5\dp\strutbox}\fi% + \fi% + \stackengine{\stack@tmplength}{}{#2}{O}{\stackalignment}{T}{F}{\stacktype}% + \if T\usestackstrut% + \if S\stacktype\addtolength{\stack@tmplength}% + {-\ht\strutbox+\dp\strutbox}\fi% + \fi% + \stackengine{\stack@tmplength}{\usebox{\stackedbox}}{#3}{U}% + {\stackalignment}{\quietstack}{F}{\stacktype}% +} + +\newcommand*\belowbaseline[2][\stackgap]{% + \stackengine{#1}{}{#2}{U}{\stackalignment}{\quietstack}{F}% + {\stacktype}} + +\newcommand*\topinset[4]{\stack@inset{#1}{#2}{#3}{#4}{O}} + +\newcommand*\bottominset[4]{\stack@inset{#1}{#2}{#3}{#4}{U}} + +\newcommand*\stack@inset[5]{% + \ifthenelse{\equal{#3}{}} + {\setlength{\stack@tmplength}{0pt}}% + {\setlength{\stack@tmplength}{#3}}% + \ifthenelse{\equal{#4}{}}{\def\stack@tmp{0pt}}{\def\stack@tmp{#4}}% + \def\stack@lroffset{\rule{\stack@tmp}{0pt}}% + \addtolength{\stack@tmplength}{\heightof{#1}}% + \stackengine{-\stack@tmplength}{#2}{\stack@lroffset#1\stack@lroffset}% + {#5}{\stackalignment}{\quietstack}{\useanchorwidth}{S}% +} + +\newcommand*\savestack[2]{% + \global\edef\sv@name{\stack@macro@name{#1}}% + \@ifundefined{\sv@name content}{% + \expandafter\newsavebox\expandafter{\csname\sv@name content\endcsname}% + }{}% + \expandafter\sbox\csname\sv@name content\endcsname{#2}% + \protected@edef#1{\usebox{\csname\sv@name content\endcsname}}% +} + +% Following 3 lines thanks to Prof. Enrico Gregorio, from: +% http://tex.stackexchange.com/questions/42318/ +% removing-a-backslash-from-a-character-sequence +\begingroup\lccode`\|=`\\ +\lowercase{\endgroup\def\removebs#1{\if#1|\else#1\fi}} +\newcommand{\stack@macro@name}[1]{\expandafter\removebs\string#1} +% + +\endinput |