summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2011-09-05 23:28:46 +0000
committerKarl Berry <karl@freefriends.org>2011-09-05 23:28:46 +0000
commitb75ddb92b4bc5135cdf583ff71bd1dc29ba48ba6 (patch)
tree949199f8550a7d762b667964b02b608d83b4fa8d /Master/texmf-dist
parentbe746844a55d323ecd877e3d621544c8ad8b32e4 (diff)
adjustbox (5sep11)
git-svn-id: svn://tug.org/texlive/trunk@23831 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/latex/adjustbox/adjustbox.pdfbin258720 -> 261650 bytes
-rw-r--r--Master/texmf-dist/source/latex/adjustbox/adjustbox.dtx114
-rw-r--r--Master/texmf-dist/tex/latex/adjustbox/adjustbox.sty41
-rw-r--r--Master/texmf-dist/tex/latex/adjustbox/collectbox.sty591
4 files changed, 726 insertions, 20 deletions
diff --git a/Master/texmf-dist/doc/latex/adjustbox/adjustbox.pdf b/Master/texmf-dist/doc/latex/adjustbox/adjustbox.pdf
index e9183e92c75..1bd8a934f56 100644
--- a/Master/texmf-dist/doc/latex/adjustbox/adjustbox.pdf
+++ b/Master/texmf-dist/doc/latex/adjustbox/adjustbox.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/adjustbox/adjustbox.dtx b/Master/texmf-dist/source/latex/adjustbox/adjustbox.dtx
index aa7094a397a..855ad15f342 100644
--- a/Master/texmf-dist/source/latex/adjustbox/adjustbox.dtx
+++ b/Master/texmf-dist/source/latex/adjustbox/adjustbox.dtx
@@ -187,6 +187,7 @@
% \changes{v0.4}{2011/07/xx}{Added pdftex driver}
% \changes{v0.5}{2011/08/13}{Added more macros and keys}
% \changes{v0.5a}{2011/08/21}{Fixed \Key{left} and \Key{right} keys. Fixed \Key{valign}'='t}
+% \changes{v0.6}{2011/09/04}{Added tabular support.}
%
% \GetFileInfo{adjustbox.dtx}
%
@@ -1143,7 +1144,10 @@
% \end{example}
%
% \subsection{Minipage or other inner Environment}
-% The following keys will overwrite each other and only defined for \env{adjustbox} but do not apply for \Macro\includegraphics.
+% The following keys set the way the content is processed before it is stored it in a box.
+% These keys will overwrite each other and only the latest used key will take effect.
+% Because they affect the inner content directly their order relative to other, normal keys is not meaningful.
+% Also they are only defined for \env{adjustbox} but do not apply for \Macro\includegraphics.
% Because they are therefore only used inside a mandatory argument and never in an optional these keys allow for optional bracket arguments.
%
% \DescribeKey{minipage}'='<width>
@@ -1178,10 +1182,35 @@
% \end{examplecode}
% \end{examples}
%
+% \DescribeKey{tabular}'='[<position>]{<column specification>}
+% \DescribeKey{tabular*}'='[<position>]{<width>}{<column specification>}
+% \DescribeKey{array}'='[<position>]{<column specification>}
+% Places the content in a \env{tabular}, \env{tabular*} or \env{array} environment, respectively.
+% These keys require different implementations for macro (\Macro\adjustbox) and environment mode (\env{adjustbox} environment) in order to insert
+% the end code correctly. Note that the environment mode is more efficient and fully stable, while the macro mode requires the last row to end with
+% an explicit |\\| (which can be followed by \Macro\hline or any other macro which uses \Macro\noalign internally). In macro mode the |\\| is internally redefined
+% to check for the closing brace. While this was successful tested for normal usages it might still cause issues with unusual or complicated cases.
+%
+% \begin{examples}
+% \begin{examplecode}
+% \adjustbox{tabular=lll}{%
+% \hline
+% A & B & C \\\hline
+% a & b & c \\\hline
+% }
+% \end{examplecode}
+% \begin{examplecode}
+% \begin{adjustbox}{tabular=lll}
+% A & B & C \\
+% a & b & c
+% \end{adjustbox}
+% \end{examplecode}
+% \end{examples}
+%
+%
% \DescribeKey{innerenv}'='<environment name>
% \DescribeKey{innerenv}'='{<environment name>}<environment options>
-% Wraps the inner content in the given \meta{environment} before it is stored as horizontal box. Only one inner environment can be used
-% and further uses of this key will overwrite previous ones as well as any \Key{minipage} and \Key{innercode} key.
+% Wraps the inner content in the given \meta{environment} before it is stored as horizontal box.
% It should be kept in mind that there is some internal code between the begin of the environment and the content. For this reason
% a \env{tabular}, \env{innerenv} or similar environment will not work here, because that code will be taken as part of the first cell.
%
@@ -1194,8 +1223,7 @@
%
%
% \DescribeKey{innercode}'='{<begin code>}{<end code>}
-% Places the given code before and after the inner content before it is stored as horizontal box. Only one set of inner code can be used
-% and further uses of this key will overwrite previous ones as well as any \Key{minipage} and \Key{innerenv} key.
+% Places the given code before and after the inner content before it is stored as horizontal box.
%
% \begin{example}
% \begin{examplecode}
@@ -1250,7 +1278,7 @@
% \subsection{Package header, options and dependencies}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macrocode}
-\ProvidesPackage{adjustbox}[2011/08/21 v0.5a Adjusting TeX boxes (trim, clip, ...)]
+\ProvidesPackage{adjustbox}[2011/09/04 v0.6 Adjusting TeX boxes (trim, clip, ...)]
% \end{macrocode}
%
% \begin{macrocode}
@@ -1284,7 +1312,7 @@
%
% \begin{macrocode}
\RequirePackage{graphicx}[1999/02/16]
-\RequirePackage{collectbox}[2011/08/11]
+\RequirePackage{collectbox}[2011/08/22]
% \end{macrocode}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -2606,6 +2634,69 @@
% \end{key}
%
%
+% \begin{key}{adjbox}{tabular}
+% \begin{macrocode}
+\define@key{adjbox}{tabular}{%
+ \@ifnextchar[{%
+ \adjbox@tabular{tabular}%
+ }{%
+ \adjbox@tabular{tabular}{{#1}}\@nnil%
+ \remove@to@nnil
+ }#1\@nnil
+}
+% \end{macrocode}
+% \end{key}
+%
+%
+% \begin{macro}{\adjbox@tabular}
+% \begin{macrocode}
+\def\adjbox@tabular#1#2\@nnil{%
+ \ifcollectboxenv
+ \adjbox@innerenv{#1}{#2}\@nnil
+ \else
+ \def\adjbox@collectbox##1{\collectbox@tab{#1}{#2}{}{##1}{}}%
+ \fi
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{key}{adjbox}{tabular*}
+% \begin{macrocode}
+\define@key{adjbox}{tabular*}{%
+ \adjbox@tabular{tabular*}#1\@nnil
+}
+% \end{macrocode}
+% \end{key}
+%
+%
+% \begin{key}{adjbox}{array}
+% \begin{macrocode}
+\define@key{adjbox}{array}{%
+ \@ifnextchar[{%
+ \adjbox@array%
+ }{%
+ \adjbox@array{{#1}}\@nnil%
+ \remove@to@nnil
+ }#1\@nnil
+}
+% \end{macrocode}
+% \end{key}
+%
+%
+% \begin{macro}{\adjbox@array}
+% \begin{macrocode}
+\def\adjbox@array#1\@nnil{%
+ \ifcollectboxenv
+ \adjbox@innercode{\(\begin{array}#1}{\end{array}\)}%
+ \else
+ \def\adjbox@collectbox##1{\collectbox@tab{array}{#1}{\(}{##1}{\)}}%
+ \fi
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
% \begin{key}{adjbox}{innerenv}
% \begin{macrocode}
\define@key{adjbox}{innerenv}{%
@@ -2636,13 +2727,6 @@
% \end{macrocode}
% \end{key}
%
-% \begin{macro}{\adjbox@innerenv}
-% \begin{macrocode}
-\def\adjbox@innerenv#1#2\@nnil{%
- \def\adjbox@collectbox##1{\collectbox@{\begin{#1}#2}{##1}{\end{#1}}}%
-}%
-% \end{macrocode}
-% \end{macro}
%
% \begin{macro}{\adjbox@innercode}
% \begin{macrocode}
@@ -2785,7 +2869,7 @@
}
% \end{macrocode}
% \end{macro}
-%
+
% \iffalse
%</adjustbox>
% \fi
diff --git a/Master/texmf-dist/tex/latex/adjustbox/adjustbox.sty b/Master/texmf-dist/tex/latex/adjustbox/adjustbox.sty
index 97e2d82fca6..c3b14b2fc59 100644
--- a/Master/texmf-dist/tex/latex/adjustbox/adjustbox.sty
+++ b/Master/texmf-dist/tex/latex/adjustbox/adjustbox.sty
@@ -27,7 +27,7 @@
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\ProvidesPackage{adjustbox}[2011/08/21 v0.5a Adjusting TeX boxes (trim, clip, ...)]
+\ProvidesPackage{adjustbox}[2011/09/04 v0.6 Adjusting TeX boxes (trim, clip, ...)]
\RequirePackage{xkeyval}
\def\adjbox@defaultunit{bp}
@@ -55,7 +55,7 @@
\input{adjcalc.sty}
\disable@keys{adjbox}{patch,export,PGF,minimal}
\RequirePackage{graphicx}[1999/02/16]
-\RequirePackage{collectbox}[2011/08/11]
+\RequirePackage{collectbox}[2011/08/22]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\define@key{adjbox}{viewport}{%
@@ -741,6 +741,39 @@
\remove@to@nnil
}#1\@nnil
}
+\define@key{adjbox}{tabular}{%
+ \@ifnextchar[{%
+ \adjbox@tabular{tabular}%
+ }{%
+ \adjbox@tabular{tabular}{{#1}}\@nnil%
+ \remove@to@nnil
+ }#1\@nnil
+}
+\def\adjbox@tabular#1#2\@nnil{%
+ \ifcollectboxenv
+ \adjbox@innerenv{#1}{#2}\@nnil
+ \else
+ \def\adjbox@collectbox##1{\collectbox@tab{#1}{#2}{}{##1}{}}%
+ \fi
+}
+\define@key{adjbox}{tabular*}{%
+ \adjbox@tabular{tabular*}#1\@nnil
+}
+\define@key{adjbox}{array}{%
+ \@ifnextchar[{%
+ \adjbox@array%
+ }{%
+ \adjbox@array{{#1}}\@nnil%
+ \remove@to@nnil
+ }#1\@nnil
+}
+\def\adjbox@array#1\@nnil{%
+ \ifcollectboxenv
+ \adjbox@innercode{\(\begin{array}#1}{\end{array}\)}%
+ \else
+ \def\adjbox@collectbox##1{\collectbox@tab{array}{#1}{\(}{##1}{\)}}%
+ \fi
+}
\define@key{adjbox}{innerenv}{%
\@ifnextchar\bgroup{%
\adjbox@innerenv
@@ -755,9 +788,6 @@
\define@key{adjbox}{innercode}{%
\adjbox@innercode#1{}{}%
}
-\def\adjbox@innerenv#1#2\@nnil{%
- \def\adjbox@collectbox##1{\collectbox@{\begin{#1}#2}{##1}{\end{#1}}}%
-}%
\def\adjbox@innercode#1#2{%
\def\adjbox@collectbox##1{\collectbox@{#1}{##1}{#2}}%
}%
@@ -831,6 +861,7 @@
\def\adjbox@bgimage#1#2#3\@nnil{%
\adjbox@Gin@add{\@collectbox{\@bgimagebox{#1}{#2}}}%
}
+
\endinput
%%
%% End of file `adjustbox.sty'.
diff --git a/Master/texmf-dist/tex/latex/adjustbox/collectbox.sty b/Master/texmf-dist/tex/latex/adjustbox/collectbox.sty
new file mode 100644
index 00000000000..ba407935275
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/adjustbox/collectbox.sty
@@ -0,0 +1,591 @@
+% \begin{macrocode}
+\NeedsTeXFormat{LaTeX2e}[1999/12/01]
+\ProvidesPackage{collectbox}[2011/08/23 v0.4 Collect macro arguments as boxes]
+% \end{macrocode}
+%
+% \begin{macro}{\collectedbox}
+% Box register used to store collected box.
+% \begin{macrocode}
+\newsavebox\collectedbox
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\collectbox}
+% User level interface. Scans for potential star and optional arguments.
+% \begin{macrocode}
+\newcommand*\collectbox{%
+ \@ifstar
+ {\collectbox@a{{\BOXCONTENT}}}%
+ {\collectbox@a{}}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@a}
+% \begin{macrocode}
+\long\def\collectbox@a#1{%
+ \@ifnextchar[%
+ {\collectbox@b{#1}}%
+ {\collectbox@b{#1}[]}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@b}
+% \begin{macrocode}
+\long\def\collectbox@b#1[#2]#3{%
+ \@ifnextchar[%
+ {\collectbox@c{#2}{#3#1}}%
+ {\collectbox@c{#2}{#3#1}[]}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@c}
+% \begin{macrocode}
+\long\def\collectbox@c#1#2[#3]{%
+ \collectbox@{#1}{#2}{#3}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\collect@box}
+% The box primitive used. Might be locally redefined to \Macro\vbox if required.
+% \begin{macrocode}
+\let\collect@box\hbox
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\collectbox@mode}
+%
+% \begin{macrocode}
+\let\collectbox@mode\leavevmode
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\collectbox@}
+% The box is saved using |\setbox|. Color is supported by using |\collectbox@setgroup|.
+% A brace group is then opened using |\bgroup| which will replace the opening brace of the
+% ``argument''. The end code is installed in this group using |\aftergroup|.
+% The opening brace written by the user is then removed by assigning it as token to a dummy variable.
+% If no |{| or |\bgroup| follows the next token is taken as sole content.
+% \begin{macrocode}
+\newcommand\collectbox@[3]{%
+ \begingroup
+ \collectbox@mode
+ \@temptokena{#3\collectbox@end#2\endgroup}%
+ \setbox\collectedbox\collect@box\bgroup
+ \collectbox@setgroup
+ #1\bgroup
+ \aftergroup\the
+ \aftergroup\@temptokena
+ \collectbox@bgroup
+}
+\let\collectbox@macro\collectbox@
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\collectbox@env}
+% \begin{macrocode}
+\newcommand\collectbox@env[3]{%
+ \collectbox@mode
+ \def\collectboxenvend{#3\collectbox@end#2\collectbox@currenvir}%
+ \setbox\collectedbox\collect@box\bgroup
+ \collectbox@setgroup
+ \collectbox@reset
+ \ignorespaces
+ #1%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@currenenvir}
+% \begin{macrocode}
+\def\collectbox@currenvir{%
+ \edef\@currenvir{\@currenvir}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@bgroup}
+% \begin{macrocode}
+\def\collectbox@macro@bgroup{%
+ \@ifnextchar\bgroup
+ {\let\@let@token=}%
+ {\collectbox@arg}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\collectbox@env@bgroup}
+% \begin{macrocode}
+\def\collectbox@env@bgroup{%
+ \collectbox@reset
+ \ignorespaces
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\let\collectbox@bgroup\collectbox@macro@bgroup
+% \end{macrocode}
+%
+%
+% \begin{macro}{\collectbox@setgroup}
+% Used at the very begin of the stored box.
+% \begin{macrocode}
+\def\collectbox@setgroup{%
+ \color@setgroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@endgroup}
+% Used at the very end of the stored box.
+% \begin{macrocode}
+\def\collectbox@endgroup{%
+ \collectbox@endcode
+ \color@endgroup
+}
+\let\collectbox@endcode\relax
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\@collectbox}
+% Simpler and quicker version of \Macro\collectbox.
+% \begin{macrocode}
+\newcommand\@collectbox[1]{%
+ \begingroup
+ \collectbox@mode
+ \@temptokena{\collectbox@end#1\endgroup}%
+ \setbox\collectedbox\collect@box\bgroup
+ \collectbox@setgroup\bgroup
+ \aftergroup\the
+ \aftergroup\@temptokena
+ \collectbox@bgroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@arg}
+% Supports |\collectbox{<code>}\somemacro| in addition to
+% |\collectbox{<code>}{\somemacro}|. The first following token is read and the inner brace group is closed
+% to trigger the |\aftergroup| code.
+% \begin{macrocode}
+\def\collectbox@arg#1{%
+ #1\egroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@end}
+% The color group is first closed, followed by the closing brace of the |\setbox| command.
+% The user dimension macros are then defined.
+% Direct after this code the users code is processed and concluded with a |\endgroup|.
+% \begin{macrocode}
+\def\collectbox@end{%
+ \collectbox@endgroup
+ \egroup
+ \collectbox@protecteddef\BOXCONTENT{\usebox\collectedbox}%
+ \collectbox@protecteddef\width{\wd\collectedbox}%
+ \collectbox@protecteddef\height{\ht\collectedbox}%
+ \collectbox@protecteddef\depth{\dp\collectedbox}%
+ \collectbox@protecteddef\totalheight{\@ovri}%
+ \totalheight\height
+ \advance\totalheight\depth
+ \ifcollectboxenv
+ \collectbox@reset
+ \collectbox@currenvir
+ \fi
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@reset}
+% \begin{macrocode}
+\def\collectbox@reset{%
+ \let\collectbox@endcode\relax
+ \let\collectbox@bgroup\collectbox@macro@bgroup
+ \let\collectbox@\collectbox@macro
+ \collectboxenvfalse
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@protecteddef}
+% \begin{macrocode}
+\begingroup
+\expandafter\ifx\csname protected\endcsname\relax
+ \let\collectbox@protecteddef\def%
+\else
+ \gdef\collectbox@protecteddef{\protected\def}%
+\fi
+\endgroup
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@code}
+% Global storage macro for user code.
+% \begin{macrocode}
+\let\collectbox@code\empty
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxto}
+% User level interface. Reads box register and checks for optional argument.
+% \begin{macrocode}
+\newcommand\collectboxto[1]{%
+ \@ifnextchar[%
+ {\collectboxto@a{#1}}%
+ {\collectboxto@a{#1}[]}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxto@a}
+% Reads first optional and next mandatory arguments.
+% \begin{macrocode}
+\long\def\collectboxto@a#1[#2]#3{%
+ \@ifnextchar[%
+ {\collectboxto@b{#1}{#2}{#3}}%
+ {\collectboxto@b{#1}{#2}{#3}[]}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxto@b}
+% Reads second optional argument.
+% \begin{macrocode}
+\long\def\collectboxto@b#1#2#3[#4]{%
+ \collectboxto@{#1}{#2}{#3}{#4}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxto@}[4]{box register}{code at begin}{code}{code at end}
+% Installs code and starts to collect the box.
+% \begin{macrocode}
+\newcommand\collectboxto@[4]{%
+ \collectbox@mode
+ \setbox#1\collect@box\bgroup
+ \def\collectbox@code{#4\collectbox@endgroup\egroup#3}%
+ \collectbox@setgroup#2\bgroup
+ \aftergroup\collectbox@code
+ \collectbox@bgroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\@collectboxto}
+% Collects the next brace group as hbox into box register |#1| and executes token |#2| afterwards.
+% \begin{macrocode}
+\newcommand\@collectboxto[2]{%
+ \collectbox@mode
+ \setbox#1\collect@box\bgroup
+ \def\collectbox@code{\collectbox@endgroup\egroup#2}%
+ \collectbox@setgroup\bgroup
+ \aftergroup\collectbox@code
+ \collectbox@bgroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\nocollectbox@}[3]{<code at begin>}{<code>}{<code at end>}
+% Turns a brace group into \Macro\hbox{<code at begin><content><code at end>}<code>.
+% \begin{macrocode}
+\newcommand\nocollectbox@[3]{%
+ \collectbox@mode
+ \collect@box\bgroup
+ \def\collectbox@code{#3\egroup#2}%
+ #1\bgroup
+ \aftergroup\collectbox@code
+ \collectbox@bgroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\nocollectbox@to}[4]{<length>}{<code at begin>}{<code>}{<code at end>}
+% Turns a brace group into \Macro\hbox' to '<length>{<code at begin><content><code at end>}<code>.
+% \begin{macrocode}
+\newcommand\nocollectbox@to[4]{%
+ \collectbox@mode
+ \collect@box to #1\bgroup
+ \def\collectbox@code{#4\egroup#3}%
+ #2\bgroup
+ \aftergroup\collectbox@code
+ \collectbox@bgroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxcheckenv}
+% Checks if current macro is used as environment given by |#1|.
+% If so the |bgroup| eating macro is redefined.
+% A suitable end-macro is provided if non exists. All of this is done inside
+% a group to keep thing local.
+% The \Macro\@currenvir macro is redefined to contain \Macro\empty so that
+% macros with the same name can be used inside the environment without collisions.
+% This requires an extra internal group so that this change is reverted before the
+% \Macro\end macro.
+% \begin{macrocode}
+\newcommand*\collectboxcheckenv[1]{%
+ \begingroup
+ \def\@tempa{#1}%
+ \expandafter\endgroup
+ \ifx\@currenvir\@tempa
+ \@collectboxisenv{#1}%
+ \fi
+}
+\def\@collectboxisenv#1{%
+ \noindent
+ \collectboxenvtrue
+ \edef\@currenvir{\@currenvir\noexpand\empty}%
+ \let\collectbox@bgroup\collectbox@env@bgroup
+ \let\collectbox@endcode\collectbox@env@endcode
+ \let\collectbox@\collectbox@env
+ \expandafter\ifx\csname end#1\endcsname\relax
+ \expandafter\let\csname end#1\endcsname\collectbox@envend
+ \fi
+}
+\newif\ifcollectboxenv
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@env@endcode}
+% \begin{macrocode}
+\def\collectbox@env@endcode{\ifhmode\unskip\fi}%
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@envend}
+% \begin{macrocode}
+\def\collectbox@envend{\collectboxenvend}%
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxenvend}
+% \begin{macrocode}
+\def\collectboxenvend{%
+ \egroup
+ \collectbox@currenvir
+}%
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Tabular collection}
+%
+% \begin{macro}{\collectboxtabular}
+% \begin{macrocode}
+\newcommand\collectboxtabular[3][c]{%
+ \collectbox@tab{tabular}{[#1]{#2}}{}{#3}{}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxtabularstar}
+% \begin{macrocode}
+\newcommand\collectboxtabularstar[4][c]{%
+ \collectbox@tab{tabular*}{[#1]{#2}{#3}}{}{#4}{}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectboxarray}
+% \begin{macrocode}
+\newcommand\collectboxarray[2]{%
+ \collectbox@tab{array}{{#1}}{\(}{#2}{\)}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@checkarray}
+% \begin{macrocode}
+\def\collectbox@checkarray{%
+\@ifpackageloaded{array}{%
+ \let\collectbox@realarraycr\@arraycr
+ \def\collectbox@setarraycr{%
+ \let\@arraycr\collebox@cr
+ \def\ialign{\let\@arraycr\collectbox@realarraycr \everycr {}\tabskip \z@skip \halign}%
+ }%
+}{%
+ \let\collectbox@realarraycr\@tabularcr
+ \def\collectbox@setarraycr{%
+ \let\@tabularcr\collebox@cr
+ \def\ialign{\let\noexpand\@tabularcr\noexpand\collectbox@realarraycr \everycr {}\tabskip \z@skip \halign}%
+ }%
+}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\collectbox@checkarray
+\AtBeginDocument{\collectbox@checkarray}%
+% \end{macrocode}
+%
+% \begin{macro}{\collectbox@dorealarraycr}
+% \begin{macrocode}
+\def\collectbox@dorealarraycr{%
+ \expandafter\collectbox@realarraycr\collectbox@aftercrstuff
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\let\collectbox@aftercrstuff\empty
+% \end{macrocode}
+%
+% \begin{macro}{\collectbox@tab}
+% \begin{macrocode}
+\def\collectbox@tab#1#2#3#4#5{%
+ \begingroup
+ \collectbox@mode
+ \def\collectbox@codeafter{#4\endgroup}%
+ \def\collectbox@endtabenv{\end{#1}#5\collectbox@end}%
+ \def\collectbox@dotab{#3\begin{#1}#2}%
+ \setbox\collectedbox\collect@box\bgroup
+ \collectbox@setgroup
+ \collectbox@setarraycr
+ \afterassignment\collectbox@dotab
+ \let\@let@token=%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collebox@cr}
+% \begin{macrocode}
+\def\collebox@cr{%
+ \@ifstar\collebox@@cr\collebox@@cr%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collebox@@cr}
+% \begin{macrocode}
+\def\collebox@@cr{%
+ \@ifnextchar[%
+ \collebox@@cr@opt
+ {\collebox@@@cr{}}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collebox@@cr@opt}
+% \begin{macrocode}
+\def\collebox@@cr@opt[#1]{%
+ \collebox@@@cr{[#1]}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collebox@@@cr}
+% \begin{macrocode}
+\def\collebox@@@cr#1{%
+ \def\collectbox@aftercrstuff{#1}%
+ \expandafter\collebox@@@@cr
+ \romannumeral-`0%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collebox@@@@cr}
+% \begin{macrocode}
+\def\collebox@@@@cr{%
+ \@ifnextchar\egroup{\collectbox@dorealarraycr\collectbox@aftertab}{%
+ \ifx\@let@token\noalign
+ \expandafter\collectbox@handlenoalign
+ \else
+ \expandafter\collectbox@dorealarraycr
+ \fi
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@handlenoalign}
+% \begin{macrocode}
+\def\collectbox@handlenoalign#1#2{%
+ \collectbox@dorealarraycr
+ \noalign{\bgroup\aftergroup\collectbox@afternoalign#2}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@handlenextnoalign}
+% \begin{macrocode}
+\def\collectbox@handlenextnoalign#1#2{%
+ \egroup
+ \noalign{\bgroup\aftergroup\collectbox@afternoalign#2}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@afternoalign}
+% \begin{macrocode}
+\def\collectbox@afternoalign{%
+ \expandafter\collectbox@@afternoalign
+ \romannumeral-`0%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@@afternoalign}
+% \begin{macrocode}
+\def\collectbox@@afternoalign{%
+ \@ifnextchar\egroup{\egroup\collectbox@aftertab}{%
+ \ifx\@let@token\noalign
+ \expandafter\collectbox@handlenextnoalign
+ \else
+ \expandafter\egroup
+ \fi
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\collectbox@aftertab}
+% \begin{macrocode}
+\def\collectbox@aftertab{%
+ \collectbox@endtabenv
+ \afterassignment\collectbox@codeafter
+ \let\@let@token=%
+}
+% \end{macrocode}
+% \end{macro}
+%