From 5c080945d173a7b1f59e45af275fbc681489fe04 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 28 Feb 2011 00:25:39 +0000 Subject: collcell (27feb11) git-svn-id: svn://tug.org/texlive/trunk@21539 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/collcell/collcell.sty | 208 +++++++++++++++++----- 1 file changed, 168 insertions(+), 40 deletions(-) (limited to 'Master/texmf-dist/tex/latex/collcell') diff --git a/Master/texmf-dist/tex/latex/collcell/collcell.sty b/Master/texmf-dist/tex/latex/collcell/collcell.sty index 9429e396daa..a6376ae53bd 100644 --- a/Master/texmf-dist/tex/latex/collcell/collcell.sty +++ b/Master/texmf-dist/tex/latex/collcell/collcell.sty @@ -25,54 +25,82 @@ %% This work consists of the files collcell.dtx, collcell.ins %% and the derived file collcell.sty. %% -%%^^A $Id: collcell.dtx 2135 2011-02-05 13:45:59Z martin $ +%%^^A $Id: collcell.dtx 2188 2011-02-27 14:22:06Z martin $ \ProvidesPackage{collcell} - [2011/02/05 v0.1a Collect the content of a tabular cell] -\newtoks\collect@cell@toks + [2011/02/27 v0.5 Collect the content of a tabular cell] +\RequirePackage{array} +\def\collcell@beforeuser{\ignorespaces} +\def\collcell@afteruser{\unskip} + +\newif\if@collcell@verb +\newif\if@collcell@robustcr +\@collcell@robustcrtrue +\DeclareOption{verb}{\@collcell@verbtrue} +\DeclareOption{noverb}{\@collcell@verbfalse} +\DeclareOption{robustcr}{\@collcell@robustcrtrue}% +\DeclareOption{norobustcr}{\@collcell@robustcrfalse}% +\ProcessOptions\relax +\if@collcell@verb + \RequirePackage{tabularx} + \def\collcell@beforeuser{% + \let\collcell@savedverb\verb + \let\verb\TX@verb + \let\TX@vwarn\collcell@vwarn + \ignorespaces + }% + \def\collcell@afteruser{\unskip\let\verb\collcell@savedverb}% + \def\collcell@vwarn{% + \PackageWarning{collcell}{\noexpand\verb may be unreliable inside a collected cell}% + }% +\fi +\if@collcell@robustcr + \RequirePackage{etoolbox} + \robustify\@arraycr +\fi +\let\collect@cell@toks\@temptokena +\newcount\collect@cell@count \newenvironment{collectcell}{}{} \def\collectcell#1#2\ignorespaces{% + \begingroup + \collect@cell@count\z@ \collect@cell@toks{}% \let\collect@cell@spaces\empty \def\collect@cell@end{% - \expandafter\scantokens\expandafter - {\expandafter#1\expandafter{\the\collect@cell@toks}}% + \expandafter\endgroup + \expandafter\collcell@beforeuser + \expandafter\ccell@swap\expandafter{\the\collect@cell@toks}{#1}% + \collcell@afteruser }% - \def\collect@cell@next{\collect@cell@look}% - \collect@cell@next + \collect@cell@look#2% } +\def\ccell@swap#1#2{#2{#1}} \def\endcollectcell{\@gobble{endcollectcell}} \def\collect@cell@look{% \futurelet\collect@cell@lettoken\collect@cell@look@ } -\begingroup -\def\:{\collect@cell@eatspace} -\expandafter\gdef\: {\collect@cell@look} -\endgroup +\@firstofone{\def\collect@cell@eatspace} {\collect@cell@look} \def\collect@cell@look@{% - \ifx\collect@cell@lettoken\@sptoken - \edef\collect@cell@spaces{\collect@cell@spaces\space}% - \def\collect@cell@next{\collect@cell@eatspace}% - \else - \ifx\collect@cell@lettoken\bgroup - \def\collect@cell@next{\collect@cell@group}% - \else - \def\collect@cell@next{\collect@cell@arg}% - \fi - \fi - \collect@cell@next + \cc@case + \@sptoken{% + \edef\collect@cell@spaces{\collect@cell@spaces\space}% + \collect@cell@eatspace + }% + \bgroup{\collect@cell@group}% + \default{\collect@cell@arg}% + \endcc@case } \def\collect@cell@group#1{% \begingroup - \def\@tempa{#1}% + \edef\@tempa{\unexpanded{#1}}% \def\@tempb{\bgroup}% \ifx\@tempa\@tempb \endgroup - \def\collect@cell@next{\collect@cell@arg\bgroup}% + \collect@cell@addarg{#1}% \else \endgroup - \def\collect@cell@next{\collect@cell@arg{{#1}}}% + \collect@cell@addarg{{#1}}% \fi - \collect@cell@next + \collect@cell@look } \def\collect@cell@addarg#1{% \expandafter\expandafter\expandafter\collect@cell@toks @@ -80,22 +108,122 @@ {\expandafter\the\expandafter\collect@cell@toks\collect@cell@spaces#1}% \let\collect@cell@spaces\empty } -\def\collect@cell@arg#1{% - \ifx\collect@cell@lettoken\\% - \def\collect@cell@next{\collect@cell@end#1}% +\def\collect@cell@addcc#1{% + \collect@cell@addarg{#1}% + \begingroup + \collect@cell@toks{}% + \collect@cell@look +} +\def\collect@cell@checkcsname#1\endcsname{% + \begingroup + \expandafter\ccell@swap\expandafter + {\expandafter,\@currenvir,endtabular,endtabular*,array,tabularx,}% + {\in@{,#1,}}% + \ifin@ + \endgroup + \expandafter\@firstoftwo \else - \ifx\collect@cell@lettoken\unskip - \def\collect@cell@next{% - \@ifnextchar\endcollectcell - {\collect@cell@end#1}% - {\collect@cell@addarg{#1}\collect@cell@look}% - }% - \else - \collect@cell@addarg{#1}% - \def\collect@cell@next{\collect@cell@look}% - \fi + \endgroup + \expandafter\@secondoftwo \fi - \collect@cell@next + {\collect@cell@cr\\\csname#1\endcsname}% + {\collect@cell@addarg{\csname#1\endcsname}\collect@cell@look}% +} +\def\collect@cell@checkend#1{% + \begingroup + \def\@tempa{#1}% + \ifx\@tempa\@currenvir + \endgroup + \expandafter\@firstoftwo + \else + \endgroup + \expandafter\@secondoftwo + \fi + {\collect@cell@cr\\\end{#1}}% + {\collect@cell@addarg{\end{#1}}\collect@cell@look}% +} +\def\cc@iftoken#1{% + \ifx#1\collect@cell@lettoken + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi +} +\def\cc@case{% + \begingroup + \let\default= \collect@cell@lettoken + \cc@@case +} +\def\cc@@case#1{% + \ifx#1\collect@cell@lettoken + \expandafter\cc@@truecase + \else + \expandafter\cc@@falsecase + \fi +} +\def\cc@@truecase#1#2\endcc@case{\endgroup#1} +\def\cc@@falsecase#1{\cc@@case} +\newcommand*\ccunskip{} +\protected\def\ccunskip{\unskip} +\newcommand*\cci{} +\protected\def\cci{} +\def\collect@cell@cr{% + \iffalse{\fi + \let\collcell@realcr\cr + \def\cr{% + \expandafter + \collect@cell@look + \collcell@realcr + }% + \iffalse}\fi +} +\def\collect@cell@arg#1{% + \cc@case + \\{\collect@cell@cr#1}% + \end{\collect@cell@checkend}% + \csname{\collect@cell@checkcsname}% + \unskip{% + \let\collect@cell@spaces\empty + %\collect@cell@addarg{#1}% do not include the \unskip + \collect@cell@look% + }% + \@sharp{% + \expandafter\collect@cell@addarg\expandafter{#1}% + \collect@cell@look + }% + \collectcell{% + \advance\collect@cell@count by \@ne + \collect@cell@addcc% + }% + \endcollectcell{% + \ifnum\collect@cell@count=\z@ + \expandafter\collect@cell@end + \else + \expandafter\endgroup + \expandafter\collect@cell@addarg\expandafter + {\expandafter{\the\collect@cell@toks}}% + \advance\collect@cell@count by \m@ne% + \expandafter\collect@cell@look + \fi + }% + \cci{% + \collect@cell@look + }% + \default{% + \expandafter\ccell@swap\expandafter + {\csname endtabular*\endcsname\endtabular\endarray}{\in@{#1}}% + \ifin@ + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi + {\collect@cell@cr\\#1}% + {% + \collect@cell@addarg{#1}% + \collect@cell@look + }% + }% + \endcc@case } \endinput -- cgit v1.2.3