diff options
author | Karl Berry <karl@freefriends.org> | 2016-10-05 21:16:43 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-10-05 21:16:43 +0000 |
commit | 3a791c3ce1d5a2f61d7e82669b386db5b86f6a52 (patch) | |
tree | 5b53609baf43492cddac7790775b12854cec6ed2 /Master/texmf-dist/tex/latex/tabstackengine | |
parent | a8ef7b0b48c3a8fc592bf4b632c9d23f5a115293 (diff) |
tabstackengine (5oct16)
git-svn-id: svn://tug.org/texlive/trunk@42214 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/tabstackengine')
-rw-r--r-- | Master/texmf-dist/tex/latex/tabstackengine/tabstackengine.sty | 342 |
1 files changed, 167 insertions, 175 deletions
diff --git a/Master/texmf-dist/tex/latex/tabstackengine/tabstackengine.sty b/Master/texmf-dist/tex/latex/tabstackengine/tabstackengine.sty index 94a5428de67..589e3e93795 100644 --- a/Master/texmf-dist/tex/latex/tabstackengine/tabstackengine.sty +++ b/Master/texmf-dist/tex/latex/tabstackengine/tabstackengine.sty @@ -1,6 +1,4 @@ -\def\tabstackengineversionnumber{V1.10} -% -% tabstackengine initial release +\def\tabstackengineversionnumber{V2.00} % % THIS MATERIAL IS SUBJECT TO THE LaTeX Project Public License % @@ -13,110 +11,119 @@ % This removes need to brace unary negatives at lead of cell. % -Corrected bug of trailing \frac, noted in V1.00, by adding a % \relax to definition of \@postTAB in \readTABrow. -% +% V2.00 -Incorporate listofitems package methodology for parsing, requiring +% some package rewrite, primarily macro \@readMANYrows. +% -Fixed bug in \ensureTABstackMath that had automatically returned to +% \TABstackText mode. +% -Added \Matrixstack macro (equivalent to \tabbedVectorstack) +% -Added \TABstackTextstyle, \TABstackMathstyle, and \clearTABstyle +% to allow things like fontsize, \displaystyle, etc. to be set inside +% a stack, by default. +% -Converted \newlength\maxTAB@width to a \xdef\maxTABwd. Introduced +% \TABwd{}, \TABht{}, and \TABdp{} for obtaining widths of columns +% and heights/depths of rows. +% -\TABstrut now defined at time of parsing, rather than reconstructed after +% the fact. This will prevent any confusions if the math/text stack mode +% settings change. +% -Employed a \toks based approach to parsing the argument, rather than the +% previous \protected@edef approach. The prior approach suffered problems +% when \\ was redefined, as in, for example, \centering or \raggedright. \ProvidesPackage{tabstackengine} -[2014/02/19 (\tabstackengineversionnumber) tabbed stacking] -\RequirePackage[usestackEOL]{stackengine}[2013-10-15] -\RequirePackage{calc} - -\newtoggle{@doneTABreads} -\newcounter{TAB@stackindex} -\newcounter{TABcellindex@} -\newlength\maxTAB@width - -\newcommand\setstackTAB[1]{% - \ifstrempty{#1}{\def\TAB@char{ }}{\def\TAB@char{#1}}% - \expandafter\define@processTABrow\expandafter{\TAB@char}% -} +[2016/10/04 (\tabstackengineversionnumber) tabbed stacking] +\RequirePackage{stackengine}[2016-10-04] +\RequirePackage{listofitems} +\RequirePackage{etoolbox} -\newcommand\define@processTABrow[1]{% - \def\@processTABrow##1#1##2||{% - \def\@preTAB{##1}% - \def\@postTAB{##2}% +\newcounter{TABrowindex@} +\newcounter{TABcolindex@} +\newcounter{TABalignmentindex@} +\newtoggle{fixed@TABwidth} +\newtoks\TABcelltoks +\newtoks\TABcoltoks +\newtoks\LstrutTABtoks +\newtoks\RstrutTABtoks + +\def\getTABcelltoks[#1,#2]{% + \TABcelltoks=\expandafter\expandafter\expandafter{\TABcellRaw[#1,#2]}} + +\def\@getstruttedTABcelltoks[#1,#2]{% + \getTABcelltoks[#1,#2]% + \edef\TABstack@rownum{#1}%\ + \LstrutTABtoks=\expandafter{\expandafter\TAB@strutL\expandafter{\TABstack@rownum}}% + \RstrutTABtoks=\expandafter{\expandafter\TAB@strutR\expandafter{\TABstack@rownum}}% + \prepend@toksto\TABcelltoks\LstrutTABtoks% + \append@toksto\TABcelltoks\RstrutTABtoks} + +\def\prepend@toksto#1#2{#1=\expandafter\expandafter\expandafter% + {\expandafter\the\expandafter#2\the#1}} + +\def\append@toksto#1#2{#1=\expandafter\expandafter\expandafter% + {\expandafter\the\expandafter#1\the#2}} + +\newcommand\setstackTAB[1]{\ifstrempty{#1}{\def\TAB@char{ }}{\def\TAB@char{#1}}} + +\newcommand\readTABstack[1]{% + \expandafter\expandafter\expandafter\setsepchar\expandafter\expandafter% + \expandafter{\expandafter\SEP@char\expandafter/\TAB@char}% + \readlist*\TABcellRaw{#1}% + \edef\TABstack@rows{\TABcellRawlen}% + \edef\TABstack@cols{\listlen\TABcellRaw[1]}% + \def\maxTABwd{0pt}% + \setcounter{TABrowindex@}{0}% + \whileboolexpr{test {\ifnumless{\theTABrowindex@}{\TABstack@rows}}}{% ROW LOOP + \def\@accumulatedTAB{}% + \stepcounter{TABrowindex@}% + \setcounter{TABcolindex@}{0}% + \whileboolexpr{test {\ifnumless{\theTABcolindex@}{\TABstack@cols}}}{% COL LOOP + \stepcounter{TABcolindex@}% + \ifnum\value{TABrowindex@}=1\relax\csxdef{col\theTABcolindex@ TAB@wd}{0pt}\fi% + \getTABcelltoks[\theTABrowindex@,\theTABcolindex@]% + \expandafter\g@addto@macro\expandafter\@accumulatedTAB\expandafter{% + \the\TABcelltoks{}}% + \setbox0=\hbox{\stack@delim\TAB@delim{% + \TAB@strutL{0}\the\TABcelltoks\TAB@strutR{0}}\stack@delim}% + \ifdim\wd0>\csuse{col\theTABcolindex@ TAB@wd}\relax% + \csxdef{col\theTABcolindex@ TAB@wd}{\the\wd0}% + \ifdim\wd0>\maxTABwd\relax\xdef\maxTABwd{\the\wd0}\fi\fi% + \csxdef{col\theTABcolindex@ TAB@stackalignment}{c}% DEFAULT, LATER CHANGED }% -} -\setstackTAB{&} - -\newcommand\readTABrow[2]{% - \edef\row@ID{#1}% - \togglefalse{@doneTABreads}% - \edef\@postTAB{\unexpanded{#2\relax}\expandonce{\TAB@char}}% - \setcounter{TABcellindex@}{0}% - \whileboolexpr{ test {\nottoggle{@doneTABreads}}}{% - \stepcounter{TABcellindex@}% - \expandafter\@processTABrow\@postTAB||% - \global\csedef{TABX\row@ID X\roman{TABcellindex@}}{\expandonce\@preTAB}% - \setbox0=\hbox{% - \stack@delim\TABcell{\row@ID}{\theTABcellindex@}\stack@delim}% - \ifdim\wd0>\maxTAB@width\setlength{\maxTAB@width}{\the\wd0}\fi% - \expandafter\ifstrempty\expandafter{\@postTAB}{% - \toggletrue{@doneTABreads}% - }{}% + \setbox0=\hbox{\stack@delim\TAB@delim{\@accumulatedTAB}\stack@delim}% + \csxdef{row\theTABrowindex@ TAB@ht}{\the\ht0}% + \csxdef{row\theTABrowindex@ TAB@dp}{\the\dp0}% }% - \expandafter\xdef\csname \row@ID TABcells\endcsname{\arabic{TABcellindex@}}% - \find@TABstrut{#1}% } -\newcommand\find@TABstrut[1]{% - \def\@accumulatedTAB{}% - \setcounter{TABcellindex@}{0}% - \expandafter\protected@edef\csname @#1TABtextblob\endcsname{}% - \whileboolexpr{test {\ifnumless{\theTABcellindex@}{\TABcells{#1}}}}{% - \stepcounter{TABcellindex@}% - \protected@edef\@accumulatedTAB{% - \@accumulatedTAB\TABcell{#1}{\theTABcellindex@}}% - }% - \global\csedef{@#1TABtextblob}{\expandonce\@accumulatedTAB}% -} +\newcommand\TABwd[1]{\csuse{col#1TAB@wd}} +\newcommand\TABht[1]{\csuse{row#1TAB@ht}} +\newcommand\TABdp[1]{\csuse{row#1TAB@dp}} +\newcommand\TABstrut[1]{\ifnum#1<1\relax{}\else% + \protect\rule[-\TABdp{#1}]{0pt}{\dimexpr\TABdp{#1}+\TABht{#1}\relax}\fi} -\def\p@Tstrut#1{\protect\TABstrut{#1}} +\newcommand\TABcell[2]{\stack@delim\TAB@delim{\TABcellRaw[#1,#2]}\stack@delim} -\newcommand\TABunaryLeft{% - \def\TAB@strutLeftA{}% - \def\TAB@strutRightA{\p@Tstrut{i}}% - \def\TAB@strutLeftB{}% - \def\TAB@strutRightB{\p@Tstrut{ii}}% - \def\TAB@strutLeftC{}% - \def\TAB@strutRightC{\p@Tstrut{\TAB@prefix}}% -} -\let\TABbinaryRight\TABunaryLeft - -\newcommand\TABunaryRight{% - \def\TAB@strutLeftA{\p@Tstrut{i}}% - \def\TAB@strutRightA{}% - \def\TAB@strutLeftB{\p@Tstrut{ii}}% - \def\TAB@strutRightB{}% - \def\TAB@strutLeftC{\p@Tstrut{\TAB@prefix}}% - \def\TAB@strutRightC{}% -} -\let\TABbinaryLeft\TABunaryRight +\newcommand\TABcellBox[3][\relax]{\ifx\relax#1\relax% + \TABcellBoxaux{\csuse{col#3TAB@stackalignment}}{#2}{#3}\else + \TABcellBoxaux{#1}{#2}{#3}\fi} -\newcommand\TABbinary{% - \def\TAB@strutLeftA{{}}% - \def\TAB@strutRightA{\p@Tstrut{i}}% - \def\TAB@strutLeftB{{}}% - \def\TAB@strutRightB{\p@Tstrut{ii}}% - \def\TAB@strutLeftC{{}}% - \def\TAB@strutRightC{\p@Tstrut{\TAB@prefix}}% -} -\TABunaryLeft - -\newcommand\TAB@delim[1]{#1}% -\newcommand\TABstackMath{% - \renewcommand\TAB@delim[1]{\ensuremath{##1}}% -} -\newcommand\TABstackText{% - \renewcommand\TAB@delim[1]{##1}% -} +\newcommand\TABcellBoxaux[3]{\makebox[\TABwd{#3}][#1]{\stack@delim% + \TAB@delim{\TAB@strutL{#2}\TABcellRaw[#2,#3]\TAB@strutR{#2}}\stack@delim}} -\newcommand\TABcell[2]{\TAB@delim{% - \ignorespaces\csname TABX#1X\romannumeral#2\endcsname\unskip}} +\newcommand\TABcells[1]{\listlen\TABcellRaw[#1]} -\newcommand\TABcells[1]{\csname #1TABcells\endcsname} +\newcommand\TABunaryLeft{\def\TAB@strutL##1{}% + \def\TAB@strutR##1{\TABstrut{##1}}} +\newcommand\TABunaryRight{\def\TAB@strutL##1{\TABstrut{##1}}% + \def\TAB@strutR##1{}} +\newcommand\TABbinary{\def\TAB@strutL##1{{}}% + \def\TAB@strutR##1{\TABstrut{##1}}} +\let\TABbinaryRight\TABunaryLeft +\let\TABbinaryLeft\TABunaryRight -% NOTE THAT THE STRUT IS NOT YET TYPESET, SINCE WE DO NOT YET KNOW -% WHETHER \@#1textblob IS TO BE INVOKED IN MATH MODE OR NOT -\newcommand\TABstrut[1]{\vphantom{\csname @#1TABtextblob\endcsname}} +\newcommand\TABstackMath{\renewcommand\TAB@delim[1]{\ensuremath{\TAB@mathstyle##1}}} +\newcommand\TABstackText{\renewcommand\TAB@delim[1]{\TAB@textstyle##1}} +\newcommand\TABstackMathstyle[1]{\renewcommand\TAB@mathstyle{#1}} +\newcommand\TABstackTextstyle[1]{\renewcommand\TAB@textstyle{#1}} +\newcommand\clearTABstyle{\renewcommand\TAB@textstyle{}\renewcommand\TAB@mathstyle{}} \newcommand\tabbedShortstack[2][\stackalignment]{% \@TAB@stack{#1}{#2}{D}{\Shortstack}} @@ -172,6 +179,8 @@ \newcommand\tabularVectorstack[2]{% \ensureTABstackMath{\@TAB@stack{}{#2}{#1}{\Vectorstack}}} +\let\Matrixstack\tabbedVectorstack% ADDED V2.00 + \newcommand\parenMatrixstack[2][\stackalignment]{% \ensureTABstackMath{\left(\@TAB@stack{#1}{#2}{D}{\Vectorstack}\right)}} @@ -185,49 +194,32 @@ \ensureTABstackMath{\left|\@TAB@stack{#1}{#2}{D}{\Vectorstack}\right|}} \newcommand\@TAB@stack[4]{% - \setlength{\maxTAB@width}{0pt}% - \let\sv@stackalignment\stackalignment% + \readTABstack{#2}% + \bgroup% \edef\stackalignment{#1}% - \@readMANYrows{#2}% - \edef\TAB@narg{\narg}% - \setcounter{TAB@stackindex}{0}% - \whileboolexpr{test {\ifnumless{\theTAB@stackindex}{\TAB@narg}}}{% - \stepcounter{TAB@stackindex}% - \edef\TAB@prefix{\roman{TAB@stackindex}}% - \protected@edef\TABrow@data{\csname arg\TAB@prefix\endcsname}% - \def\@tmp{\readTABrow{\TAB@prefix}}% - \expandafter\@tmp\expandafter{\TABrow@data}% - }% -% - \setcounter{TABcellindex@}{0}% - \whileboolexpr{test {\ifnumless{\theTABcellindex@}{\TABcells{i}}}}{% - \def\col@stack{% - \TAB@strutLeftA% - \TABcell{i}{\theTABcellindex@}% - \TAB@strutRightA% -}% - \stepcounter{TABcellindex@}% - \@getTABalignment{#3}{\theTABcellindex@}% - \ifboolexpr{% - test {\ifnumgreater{\theTABcellindex@}{1}}% - }{\add@TAB@gap{#3}{\theTABcellindex@}}{}% - \setcounter{TAB@stackindex}{1}% - \whileboolexpr{test {\ifnumless{\theTAB@stackindex}{\TAB@narg}}}{% - \stepcounter{TAB@stackindex}% - \edef\TAB@prefix{\roman{TAB@stackindex}}% - \protected@edef\col@stack{\col@stack\SEP@char% - \TAB@strutLeftC% - \TABcell{\TAB@prefix}{\theTABcellindex@}% - \TAB@strutRightC% - }% + \setcounter{TABcolindex@}{0}% + \whileboolexpr{test {\ifnumless{\theTABcolindex@}{\TABstack@cols}}}{% COL LOOP + \stepcounter{TABcolindex@}% + \@getstruttedTABcelltoks[1,\theTABcolindex@]% + \TABcoltoks=\expandafter{\expandafter\TAB@delim\expandafter{\the\TABcelltoks}}% + \@getTABalignment{#3}{\theTABcolindex@}% + \ifboolexpr{test {\ifnumgreater{\theTABcolindex@}{1}}}% + {\add@TAB@gap{#3}{\theTABcolindex@}}{}% + \setcounter{TABrowindex@}{1}% + \whileboolexpr{test {\ifnumless{\theTABrowindex@}{\TABstack@rows}}}{% ROW LOOP + \stepcounter{TABrowindex@}% + \@getstruttedTABcelltoks[\theTABrowindex@,\theTABcolindex@]% + \TABcoltoks=\expandafter\expandafter\expandafter\expandafter\expandafter% + \expandafter\expandafter{\expandafter\expandafter\expandafter% + \the\expandafter\expandafter\expandafter\TABcoltoks\expandafter% + \SEP@char\expandafter\TAB@delim\expandafter{\the\TABcelltoks}}% }% \iftoggle{fixed@TABwidth}% - {\makebox[\the\maxTAB@width][\stackalignment]{% - \expandafter#4\expandafter{\col@stack}}}% - {\expandafter#4\expandafter{\col@stack}}% + {\makebox[\maxTABwd][\stackalignment]{% + \expandafter#4\expandafter{\the\TABcoltoks}}}% + {\expandafter#4\expandafter{\the\TABcoltoks}}% }% - \let\stackalignment\sv@stackalignment% -} +\egroup} \newcommand\tabbedstackon[3][\stackgap]{% \@TABstackonunder{#1}{#2}{#3}{D}{\stackon}} @@ -257,60 +249,52 @@ \@TABstackonunder{#1}{#3}{#4}{#2}{\stackanchor}} \newcommand\@TABstackonunder[5]{% - \setlength{\maxTAB@width}{0pt}% - \let\sv@stackalignment\stackalignment% - \readTABrow{i}{#2}% - \readTABrow{ii}{#3}% - \setcounter{TABcellindex@}{0}% - \whileboolexpr{test {\ifnumless{\theTABcellindex@}{\TABcells{i}}}}{% - \stepcounter{TABcellindex@}% - \@getTABalignment{#4}{\theTABcellindex@}% - \ifboolexpr{% - test {\ifnumgreater{\theTABcellindex@}{1}}% - }{\add@TAB@gap{#4}{\theTABcellindex@}}{}% + \def\TAB@tmp{#2}% + \expandafter\g@addto@macro\expandafter\TAB@tmp\expandafter{\SEP@char#3}% + \readTABstack{\TAB@tmp}% + \bgroup% + \setcounter{TABcolindex@}{0}% + \whileboolexpr{test {\ifnumless{\theTABcolindex@}{\TABstack@cols}}}{% COL LOOP + \stepcounter{TABcolindex@}% + \@getTABalignment{#4}{\theTABcolindex@}% + \ifboolexpr{test {\ifnumgreater{\theTABcolindex@}{1}}% + }{\add@TAB@gap{#4}{\theTABcolindex@}}{}% \iftoggle{fixed@TABwidth}% - {\makebox[\the\maxTAB@width][\stackalignment]{% - #5[#1]{\TAB@strutLeftA\TABcell{i}{\theTABcellindex@}\TAB@strutRightA}% - {\TAB@strutLeftB\TABcell{ii}{\theTABcellindex@}\TAB@strutRightB}}}% - {#5[#1]{\TAB@strutLeftA\TABcell{i}{\theTABcellindex@}\TAB@strutRightA}% - {\TAB@strutLeftB\TABcell{ii}{\theTABcellindex@}\TAB@strutRightB}}% + {\makebox[\maxTABwd][\stackalignment]{% + #5[#1]% + {\TAB@delim{\TAB@strutL{1}\TABcellRaw[1,\theTABcolindex@]\TAB@strutR{1}}}% + {\TAB@delim{\TAB@strutL{2}\TABcellRaw[2,\theTABcolindex@]\TAB@strutR{2}}}}}% + {#5[#1]% + {\TAB@delim{\TAB@strutL{1}\TABcellRaw[1,\theTABcolindex@]\TAB@strutR{1}}}% + {\TAB@delim{\TAB@strutL{1}\TABcellRaw[2,\theTABcolindex@]\TAB@strutR{2}}}}% }% - \let\stackalignment\sv@stackalignment% -} +\egroup} \newcommand\@getTABalignment[2]{% - \ifstrequal{#1}{D}{}{% T, DO NOTHING (USE \stackalignment) + \ifstrequal{#1}{D}{}{% T, DO NOTHING (USE \stackalignment) \ifstrequal{#1}{A}{% \ifnumequal{1}{#2}{% - \def\stackalignment{r}}{% A, 1st ELEMENT, SET TO r + \def\stackalignment{r}}{% A, 1st ELEMENT, SET TO r \if l\stackalignment% - \def\stackalignment{r}\else% A, SWITCH l TO r - \def\stackalignment{l}\fi}}{% A, SWITCH r TO l - \set@tabularcellalignment{#1}{#2}% tabular, READ #2 location + \def\stackalignment{r}\else% A, SWITCH l TO r + \def\stackalignment{l}\fi}}{% A, SWITCH r TO l + \set@tabularcellalignment{#1}{#2}% tabular, READ #2 location }% }% + \csxdef{col\theTABcolindex@ TAB@stackalignment}{\stackalignment}% } -\def\tabbed@gap{0pt} -\def\align@gap{1em} -\def\tabular@gap{\tabcolsep} - \newcommand\setstacktabbedgap[1]{\def\tabbed@gap{#1}} \newcommand\setstackaligngap[1]{\def\align@gap{#1}} \newcommand\setstacktabulargap[1]{\def\tabular@gap{#1}} \newcommand\add@TAB@gap[2]{% \ifstrequal{#1}{D}{\hspace{\tabbed@gap}}{% - \ifstrequal{#1}{A}{% - \if r\stackalignment\hspace{\align@gap}\fi% - }{% - \hspace{\tabular@gap}% - }% + \ifstrequal{#1}{A}% + {\if r\stackalignment\hspace{\align@gap}\fi}{\hspace{\tabular@gap}}% }% } -\newcounter{TABalignmentindex@} - \newcommand\set@tabularcellalignment[2]{% \setcounter{TABalignmentindex@}{1}% \edef\tabular@settings{#1.}% @@ -328,13 +312,21 @@ \def\@getnextTABchar#1#2\\{\gdef\@nextTABchar{#1}} - -\newtoggle{fixed@TABwidth} \newcommand\fixTABwidth[1]{% - \if T#1\toggletrue{fixed@TABwidth}\else\togglefalse{fixed@TABwidth}\fi% -} -\fixTABwidth{F} - -\newcommand\ensureTABstackMath[1]{\TABstackMath#1\TABstackText} + \if T#1\toggletrue{fixed@TABwidth}\else\togglefalse{fixed@TABwidth}\fi} + +\newcommand\ensureTABstackMath[1]{% + \let\sv@TABmode\TAB@delim\TABstackMath#1\let\TAB@delim\sv@TABmode} + +\setstackEOL{\\}% DEFAULT ROW SEP +\setstackTAB{&}% DEFAULT COL SEP +\def\TAB@mathstyle{}% NOTHING ADDED TO DEFAULT TAB MATH STYLE +\def\TAB@textstyle{}% NOTHING ADDED TO DEFAULT TAB TEXT STYLE +\def\TAB@delim{}\TABstackText% INITIALIZE DEFAULT TO TEXT TABSTACKING +\TABunaryLeft% NO DEFAULT EMPTY {} GROUP AT LEFT END OF EACH CELL +\def\tabbed@gap{0pt}% DEFAULT TABBED COL GAP +\def\align@gap{1em}% DEFAULT ALIGN COL GAP +\def\tabular@gap{\tabcolsep}% DEFAULT TABULAR COL GAP +\fixTABwidth{F}% DEFAULT NON-FIXED WIDTH COLUMNS \endinput |