Skip to content
118 changes: 79 additions & 39 deletions tabu.sty
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@
\def\tabu@everyrowfalse{\global\let\iftabu@everyrow \iffalse}
\newif \iftabu@long
\newif \iftabuscantokens
\def\tabu@rescan {\tabu@verbatim \scantokens }
%% TABU-FIXED (issue #3)
%% REMOVED \tabu@verbatim
%% \def\tabu@rescan {\tabu@verbatim \scantokens }
\let\tabu@rescan \scantokens
%% Utilities (for internal usage) -----------------------------------
\def\tabu@gobblespace #1 {#1}
\def\tabu@gobbletoken #1#2{#1}
Expand Down Expand Up @@ -1250,8 +1253,16 @@
\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 %
%% TABU-FIXED (issue #3)
%% tabu* now collects body with a catcode 12 backslash
\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 @@ -1273,17 +1284,14 @@
\fi
}% \tabu@Xinit
%% Collecting the environment body ----------------------------------
%% TABU-FIXED (issue #3)
%% this macro now only for non-scantokens type of body collecting
\long\def\tabu@collectbody #1#2\end #3{%
\edef\tabu@stack{\tabu@pushbegins #2\begin\end\expandafter\@gobble\tabu@stack}%
\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 +1306,61 @@
\def\tabu@endofcollect #1{\ifnum0=`{}\fi
\expandafter\endgroup \the\toks@ #1%
}% \tabu@endofcollect
%% TABU-FIXED (issue #3)
%% collects body with a catcode 12 backslash for later scantokenization
\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
}% \tabu@collectbody@forscan
|def|tabu@collectbody@forscan@a{%
|ifcat|noexpand|tabu@temp@token e%
|expandafter|tabu@collectbody@forscan@aa
|else
|expandafter|tabu@collectbody@forscan@b
|fi
}% \tabu@collectbody@forscan@a
|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.

}% \tabu@collectbody@forscan@aa
|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|tabu@collectbody@forscan@end
|else
|expandafter|tabu@collectbody@forscan@continue
|fi
{#1}%
}% \tabu@collectbody@forscan@b
|def|tabu@collectbody@forscan@end #1{%
|edef|tabu@@temp{|tabu@thebody{|the|toks@
|unexpanded|expandafter{|tabu@collectbody@forscan@partial}}%
}%
|toks@|expandafter{|tabu@@temp
|def|tabu@end@envir{|end{#1}}%
|iftabu@long |def|tabu@endenvir {|end{#1}|tabu@gobbleX}%
|else |def|tabu@endenvir {|let|endarray |@empty
|end{#1}|tabu@gobbleX}%
|fi}%
|let|tabu@collectbody@forscan|tabu@endofcollect
|tabu@collectbody@forscan@next
}% \tabu@collectbody@forscan@end
|def|tabu@collectbody@forscan@continue #1{%
|edef|tabu@@temp{|the|toks@|unexpanded|expandafter{|tabu@collectbody@forscan@partial\end}}%
|def|tabu@temp{#1}%
|ifx |tabu@temp|@empty |toks@|expandafter{|tabu@@temp}%
|else |ifx|tabu@temp|tabu@@spxiii |toks@|expandafter{|tabu@@temp#1}%
|else |ifx|tabu@temp|tabu@X |toks@|expandafter{|tabu@@temp#1}%
|else |toks@|expandafter{|tabu@@temp{#1}}%
|fi|fi|fi
|tabu@collectbody@forscan@next{}%
}% \tabu@collectbody@forscan@continue
|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 @@ -2040,34 +2103,9 @@
\fi\fi
}% \tabu@printdecimal
%% Verbatim inside X columns ----------------------------------------
\def\tabu@verbatim{%
\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}
\def\tabu@fancyvrb {%
\def\tabu@FV@DefineCheckEnd ##1{%
\def\tabu@FV@DefineCheckEnd{%
##1% <original definition (if fancyvrb is loaded)>
\let\FV@CheckEnd \tabu@FV@CheckEnd
\let\FV@@CheckEnd \tabu@FV@@CheckEnd
\let\FV@@@CheckEnd \tabu@FV@@@CheckEnd
\edef\FV@EndScanning{%
\def\noexpand\next{\noexpand\end{\FV@EnvironName}}%
\global\let\noexpand\FV@EnvironName\relax
\noexpand\next}%
\xdef\FV@EnvironName{\detokenize\expandafter{\FV@EnvironName}}}%
}\expandafter\tabu@FV@DefineCheckEnd\expandafter{\FV@DefineCheckEnd}
}% \tabu@fancyvrb
\def\tabu@FV@CheckEnd #1{\expandafter\FV@@CheckEnd \detokenize{#1\end{}}\@nil}
\edef\tabu@FV@@@CheckEnd {\detokenize{\end{}}}
\begingroup
\catcode`\[1 \catcode`\]2
\@makeother\{ \@makeother\}
\edef\x[\endgroup
\def\noexpand\tabu@FV@@CheckEnd ##1\detokenize[\end{]##2\detokenize[}]##3%
]\x \@nil{\def\@tempa{#2}\def\@tempb{#3}}
%% TABU-FIXED (issue #3)
%% REMOVED \tabu@verbatim, \tabu@verb, \tabu@FV@DefineCheckEnd, ...
%% REMOVED \tabu@fancyvrb, \tabu@FV@CheckEnd, etc...
\def\tabu@FV@ListProcessLine #1{%
\hbox {%to \hsize{%
\kern\leftmargin
Expand Down Expand Up @@ -2540,8 +2578,10 @@
ifHy@hyperfootnotes\else iffalse\fi\endcsname
\let\tabu@footnotetext \tabu@Hy@ftntext
\let\tabu@xfootnote \tabu@Hy@xfootnote \fi
\ifdefined\FV@DefineCheckEnd% <fancyvrb>
\tabu@fancyvrb \fi
%% TABU-FIXED (issue #3)
%% REMOVED \tabu@fancyvrb
%% \ifdefined\FV@DefineCheckEnd% <fancyvrb>
%% \tabu@fancyvrb \fi
\ifdefined\color % <color / xcolor>
\let\tabu@color \color
\def\tabu@leavevmodecolor ##1{%
Expand Down
40 changes: 40 additions & 0 deletions testfiles/t003.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\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}
\normalfont\yyyyyy\begin{yyyyyy}hello\end{yyyyyy}hello\endyyyyyy
\def\foo{foo}\meaning\foo
\meaning\foo (ok as each line is\
scoped by fancyvrb)
\begin{Large}AA{\footnotesize{}BB}CC\end{Large}
\begin{Large}AA\begin{footnotesize}BB\end{footnotesize}CC\end{Large}
\end{Verbatim}
&
\begin{Verbatim}
And \textit{this} is a \textbf{\textrm{complete}}
Verbatim environment $&~\textbraceleft\textbraceright
{\footnotesize this is smaller}
\textit{spaces are ok I hope}
\normalfont\yyyyyy\begin{yyyyyy}hello\end{yyyyyy}hello\endyyyyyy
\def\foo{foo}\meaning\foo
\meaning\foo (ok as each line is\
scoped by fancyvrb)
\begin{Large}AA{\footnotesize{}BB}CC\end{Large}
\begin{Large}AA\begin{footnotesize}BB\end{footnotesize}CC\end{Large}
\end{Verbatim}
\\
\end{tabu*}

\end{document}