Skip to content
73 changes: 63 additions & 10 deletions tabu.sty
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,14 @@
\ifnum \count@>\thr@@ \let\@halignto \@empty \tabucolX@init
\def\tabu@lasttry{\m@ne\p@}\fi
\begingroup \iffalse{\fi \ifnum0=`}\fi
\toks@{}\def\tabu@stack{b}\iftabuscantokens \endlinechar=10 \obeyspaces \fi %
\tabu@collectbody \tabu@strategy %
\toks@{}\def\tabu@stack{b}\iftabuscantokens
\endlinechar=10 \catcode`\\=12 \obeyspaces
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi %
{\tabu@collectbody@forscan\tabu@strategy{}}%
{\tabu@collectbody\tabu@strategy}%
}% \tabu@setstrategy
\def\tabu@savecounters{%
\def\@elt ##1{\csname c@##1\endcsname\the\csname c@##1\endcsname}%
Expand All @@ -1278,12 +1284,7 @@
\ifx \tabu@stack\@empty
\toks@\expandafter{\expandafter\tabu@thebody\expandafter{\the\toks@ #2}%
\def\tabu@end@envir{\end{#3}}%
\iftabuscantokens
\iftabu@long \def\tabu@endenvir {\end{#3}\tabu@gobbleX}%
\else \def\tabu@endenvir {\let\endarray \@empty
\end{#3}\tabu@gobbleX}%
\fi
\else \def\tabu@endenvir {\end{#3}}\fi}%
\def\tabu@endenvir {\end{#3}}}%
\let\tabu@collectbody \tabu@endofcollect
\else\def\tabu@temp{#3}%
\ifx \tabu@temp\@empty \toks@\expandafter{\the\toks@ #2\end }%
Expand All @@ -1298,6 +1299,58 @@
\def\tabu@endofcollect #1{\ifnum0=`{}\fi
\expandafter\endgroup \the\toks@ #1%
}% \tabu@endofcollect
\catcode`\| \z@
\catcode`\\ 12
|long|def|tabu@collectbody@forscan #1#2#3\end{%
|def|tabu@collectbody@forscan@next{|tabu@collectbody@forscan{#1}}%
|def|tabu@collectbody@forscan@partial{#2#3}%
|futurelet|tabu@temp@token|tabu@collectbody@forscan@a
}%
|def|tabu@collectbody@forscan@a{%
|ifcat|tabu@temp@token e%
|expandafter|@firstoftwo
|else
|expandafter|@secondoftwo
|fi
|tabu@collectbody@forscan@aa
|tabu@collectbody@forscan@b
}%
|def|tabu@collectbody@forscan@aa #1{%
|expandafter|tabu@collectbody@forscan@next|expandafter{|tabu@collectbody@forscan@partial\end#1}%
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I document it now before I forget: here we had some \endfoo, thus it was started by some \foo. Hence there is no associated \begin. Good thing LaTeX does not have \beginfoo syntax... Thus the balancing done via \tabu@pushbegins@forscan isn't offset, and the loop terminates correctly after tabu body is collected. Definitely this won't work with \endtabu, but original surely did not either as it is checking for \end token.

}%
|def|tabu@collectbody@forscan@b #1{%
|edef|tabu@stack{|expandafter|tabu@pushbegins@forscan
|tabu@collectbody@forscan@partial\begin|relax|expandafter|@gobble|tabu@stack}%
|ifx |tabu@stack|@empty
|expandafter|@firstoftwo
|else
|expandafter|@secondoftwo
|fi
{|expandafter|tabu@collectbody@forscan@end|expandafter{|tabu@collectbody@forscan@partial}{#1}}%
{|expandafter|tabu@collectbody@forscan@continue|expandafter{|tabu@collectbody@forscan@partial}{#1}}%
}%
|def|tabu@collectbody@forscan@end #1#2{%
|toks@|expandafter{|expandafter|tabu@thebody|expandafter{|the|toks@ #1}%
|def|tabu@end@envir{|end{#2}}%
|iftabu@long |def|tabu@endenvir {|end{#2}|tabu@gobbleX}%
|else |def|tabu@endenvir {|let|endarray |@empty
|end{#2}|tabu@gobbleX}%
|fi}%
|let|tabu@collectbody@forscan|tabu@endofcollect
|tabu@collectbody@forscan@next
}%
|def|tabu@collectbody@forscan@continue #1#2{%
|def|tabu@temp{#2}%
|ifx |tabu@temp|@empty |toks@|expandafter{|the|toks@ #1\end }%
|else |ifx|tabu@temp|tabu@@spxiii |toks@|expandafter{|the|toks@ #1\end#2}%
|else |ifx|tabu@temp|tabu@X |toks@|expandafter{|the|toks@ #1\end#2}%
|else |toks@|expandafter{|the|toks@ #1\end{#2}}%
|fi|fi|fi
|tabu@collectbody@forscan@next{}%
}% \tabu@collectbody@forscan
|long|def|tabu@pushbegins@forscan #1\begin#2{|ifx|relax#2|else b|expandafter|tabu@pushbegins@forscan|fi}%
|catcode`|\ |z@
\catcode`\| 12
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check the catcode setting and resetting of the package, so i hope it is fine to set this here with no further ado.

%% The trials: switching between strategies -------------------------
\def\tabu@strategy {\relax % stops \count@ assignment !
\ifcase\count@ % case 0 = print with vertical adjustment (outer is finished)
Expand Down Expand Up @@ -2041,8 +2094,8 @@
}% \tabu@printdecimal
%% Verbatim inside X columns ----------------------------------------
\def\tabu@verbatim{%
\let\verb \tabu@verb
\let\FV@DefineCheckEnd \tabu@FV@DefineCheckEnd
% \let\verb \tabu@verb
% \let\FV@DefineCheckEnd \tabu@FV@DefineCheckEnd
}% \tabu@verbatim
\let\tabu@ltx@verb \verb
\def\tabu@verb{\@ifstar {\tabu@ltx@verb*} \tabu@ltx@verb}
Expand Down
26 changes: 26 additions & 0 deletions testfiles/t003.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{tabu}
\newenvironment{yyyyyy}{START}{END}
\input{regression-test}
\begin{document}

\START
\begin{tabu*}to\linewidth{|XX|}
% if }{ in the short verb then already not working in tabu 2.09
A short verb: \verb|$&\~{}|&
\begin{Verbatim}[commandchars={\\\{\}}]
And \textit{this} is a \textbf{\textrm{complete}}
Verbatim environment $&\~\textbraceleft\textbraceright
{\footnotesize this is smaller}
\textit{spaces are ok I hope}
\begin{yyyyyy}hello\end{yyyyyy} works
(if on multiple lines it already
does not work
outside of a tabu cell, anyway)
\normalfont\yyyyyy hello\endyyyyyy works too
\end{Verbatim}
\\
\end{tabu*}

\end{document}