From 6e92ac8e9a5a30fab197863fa37b96c35110257f Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 22 Jan 2019 16:46:45 +0100 Subject: [PATCH 01/10] Collecting body with a catcode 12 backslash --- tabu.sty | 73 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/tabu.sty b/tabu.sty index e62cacf..ec5dd9b 100644 --- a/tabu.sty +++ b/tabu.sty @@ -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}% @@ -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 }% @@ -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}% +}% +|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 %% The trials: switching between strategies ------------------------- \def\tabu@strategy {\relax % stops \count@ assignment ! \ifcase\count@ % case 0 = print with vertical adjustment (outer is finished) @@ -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} From a5a19999ce989f16739408a1ca93032429543877 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 22 Jan 2019 17:30:12 +0100 Subject: [PATCH 02/10] Add a (passing) test file for issue #3 I don't know how one makes up .lvt type of validating file. new file: testfiles/t003.lvt --- testfiles/t003.lvt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 testfiles/t003.lvt diff --git a/testfiles/t003.lvt b/testfiles/t003.lvt new file mode 100644 index 0000000..0383910 --- /dev/null +++ b/testfiles/t003.lvt @@ -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} From 43f7f4ae2decf832b27f9f1a213feda19db8e2d4 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 22 Jan 2019 21:49:29 +0100 Subject: [PATCH 03/10] Add missing \noexpand, suppress \tabu@verbatim and \tabu@rescan Use \scantokens directly as it needs now no extra preliminaries. --- tabu.sty | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tabu.sty b/tabu.sty index ec5dd9b..4787201 100644 --- a/tabu.sty +++ b/tabu.sty @@ -114,7 +114,6 @@ \def\tabu@everyrowfalse{\global\let\iftabu@everyrow \iffalse} \newif \iftabu@long \newif \iftabuscantokens -\def\tabu@rescan {\tabu@verbatim \scantokens } %% Utilities (for internal usage) ----------------------------------- \def\tabu@gobblespace #1 {#1} \def\tabu@gobbletoken #1#2{#1} @@ -959,7 +958,7 @@ \NC@list{\NC@do \tabu@rewritemulticolumn}% \expandafter\@gobbletwo % gobbles \multispan{#1} \tabu@multicolumnORI{#1}{\tabu@rewritemulticolumn #2}% - {\iftabuscantokens \tabu@rescan \else \expandafter\@firstofone \fi + {\iftabuscantokens \scantokens \else \expandafter\@firstofone \fi {#3}}% }% \tabu@multic@lumn %% The X column(s): rewriting process ----------------------------- @@ -1305,19 +1304,17 @@ |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|tabu@temp@token e% - |expandafter|@firstoftwo + |ifcat|noexpand|tabu@temp@token e% + |expandafter|tabu@collectbody@forscan@aa |else - |expandafter|@secondoftwo + |expandafter|tabu@collectbody@forscan@b |fi - |tabu@collectbody@forscan@aa - |tabu@collectbody@forscan@b -}% +}% \tabu@collectbody@forscan@a |def|tabu@collectbody@forscan@aa #1{% |expandafter|tabu@collectbody@forscan@next|expandafter{|tabu@collectbody@forscan@partial\end#1}% -}% +}% \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}% @@ -1328,7 +1325,7 @@ |fi {|expandafter|tabu@collectbody@forscan@end|expandafter{|tabu@collectbody@forscan@partial}{#1}}% {|expandafter|tabu@collectbody@forscan@continue|expandafter{|tabu@collectbody@forscan@partial}{#1}}% -}% +}% \tabu@collectbody@forscan@b |def|tabu@collectbody@forscan@end #1#2{% |toks@|expandafter{|expandafter|tabu@thebody|expandafter{|the|toks@ #1}% |def|tabu@end@envir{|end{#2}}% @@ -1338,7 +1335,7 @@ |fi}% |let|tabu@collectbody@forscan|tabu@endofcollect |tabu@collectbody@forscan@next -}% +}% \tabu@collectbody@forscan@end |def|tabu@collectbody@forscan@continue #1#2{% |def|tabu@temp{#2}% |ifx |tabu@temp|@empty |toks@|expandafter{|the|toks@ #1\end }% @@ -1347,7 +1344,7 @@ |else |toks@|expandafter{|the|toks@ #1\end{#2}}% |fi|fi|fi |tabu@collectbody@forscan@next{}% -}% \tabu@collectbody@forscan +}% \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 @@ -1390,7 +1387,7 @@ \def\tabu@shorttrial {\setbox\tabu@box \hbox\bgroup \tabu@seteverycr \ifx \tabu@savecounters\relax \else \let\tabu@savecounters \relax \tabu@clckpt \fi - $\iftabuscantokens \tabu@rescan \else \expandafter\@secondoftwo \fi + $\iftabuscantokens \scantokens \else \expandafter\@secondoftwo \fi \expandafter{\expandafter \tabuthepreamble \the\tabu@thebody \csname tabu@adl@endtrial\endcsname @@ -1399,7 +1396,7 @@ \def\tabu@longtrial {\setbox\tabu@box \hbox\bgroup \tabu@seteverycr \ifx \tabu@savecounters\relax \else \let\tabu@savecounters \relax \tabu@clckpt \fi - \iftabuscantokens \tabu@rescan \else \expandafter\@secondoftwo \fi + \iftabuscantokens \scantokens \else \expandafter\@secondoftwo \fi \expandafter{\expandafter \tabuthepreamble \the\tabu@thebody \tabuendlongtrial}\egroup % got \tabu@box @@ -1422,7 +1419,7 @@ \else \expandafter\@secondoftwo \fi {\expandafter \tabu@closetrialsgroup \expandafter - \tabu@rescan \expandafter{% + \scantokens \expandafter{% \expandafter\tabuthepreamble \the\expandafter\tabu@thebody \iftabu@long \else \endarray \fi}} From e1966605d782fa4f2b49227e4865ccd0a9c59aca Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 22 Jan 2019 21:52:00 +0100 Subject: [PATCH 04/10] Suppress now unneeded hack into fancyvrb and \verb code --- tabu.sty | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/tabu.sty b/tabu.sty index 4787201..dbea9ed 100644 --- a/tabu.sty +++ b/tabu.sty @@ -2090,34 +2090,6 @@ \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% - \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}} \def\tabu@FV@ListProcessLine #1{% \hbox {%to \hsize{% \kern\leftmargin @@ -2590,8 +2562,6 @@ ifHy@hyperfootnotes\else iffalse\fi\endcsname \let\tabu@footnotetext \tabu@Hy@ftntext \let\tabu@xfootnote \tabu@Hy@xfootnote \fi - \ifdefined\FV@DefineCheckEnd% - \tabu@fancyvrb \fi \ifdefined\color % \let\tabu@color \color \def\tabu@leavevmodecolor ##1{% From b28293cc7d32215966e2cf70012c9ee2d35c313d Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 22 Jan 2019 22:31:25 +0100 Subject: [PATCH 05/10] Extend #3 test file MEMO: we can't have environment spread across multiple lines inside alltt-type Verbatim as fancyvrb scopes each input line --- testfiles/t003.lvt | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/testfiles/t003.lvt b/testfiles/t003.lvt index 0383910..af43afd 100644 --- a/testfiles/t003.lvt +++ b/testfiles/t003.lvt @@ -8,17 +8,31 @@ \START \begin{tabu*}to\linewidth{|XX|} % if }{ in the short verb then already not working in tabu 2.09 -A short verb: \verb|$&\~{}|& +A short verb: \verb|$&\~{}|&\\ \begin{Verbatim}[commandchars={\\\{\}}] And \textit{this} is a \textbf{\textrm{complete}} -Verbatim environment $&\~\textbraceleft\textbraceright +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 +\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*} From 03fea8ba47d1525a82448d59c0ef43b19a7decd9 Mon Sep 17 00:00:00 2001 From: jfbu Date: Wed, 23 Jan 2019 19:12:33 +0100 Subject: [PATCH 06/10] Add "TABU-FIXED (issue #3)" tags, re-use \tabu@rescan in source code But \tabu@rescan is now \let to \scantokens --- tabu.sty | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tabu.sty b/tabu.sty index dbea9ed..018b8e9 100644 --- a/tabu.sty +++ b/tabu.sty @@ -114,6 +114,10 @@ \def\tabu@everyrowfalse{\global\let\iftabu@everyrow \iffalse} \newif \iftabu@long \newif \iftabuscantokens +%% 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} @@ -958,7 +962,7 @@ \NC@list{\NC@do \tabu@rewritemulticolumn}% \expandafter\@gobbletwo % gobbles \multispan{#1} \tabu@multicolumnORI{#1}{\tabu@rewritemulticolumn #2}% - {\iftabuscantokens \scantokens \else \expandafter\@firstofone \fi + {\iftabuscantokens \tabu@rescan \else \expandafter\@firstofone \fi {#3}}% }% \tabu@multic@lumn %% The X column(s): rewriting process ----------------------------- @@ -1249,6 +1253,8 @@ \ifnum \count@>\thr@@ \let\@halignto \@empty \tabucolX@init \def\tabu@lasttry{\m@ne\p@}\fi \begingroup \iffalse{\fi \ifnum0=`}\fi +%% 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 @@ -1278,6 +1284,8 @@ \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 @@ -1298,6 +1306,8 @@ \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{% @@ -1387,7 +1397,7 @@ \def\tabu@shorttrial {\setbox\tabu@box \hbox\bgroup \tabu@seteverycr \ifx \tabu@savecounters\relax \else \let\tabu@savecounters \relax \tabu@clckpt \fi - $\iftabuscantokens \scantokens \else \expandafter\@secondoftwo \fi + $\iftabuscantokens \tabu@rescan \else \expandafter\@secondoftwo \fi \expandafter{\expandafter \tabuthepreamble \the\tabu@thebody \csname tabu@adl@endtrial\endcsname @@ -1396,7 +1406,7 @@ \def\tabu@longtrial {\setbox\tabu@box \hbox\bgroup \tabu@seteverycr \ifx \tabu@savecounters\relax \else \let\tabu@savecounters \relax \tabu@clckpt \fi - \iftabuscantokens \scantokens \else \expandafter\@secondoftwo \fi + \iftabuscantokens \tabu@rescan \else \expandafter\@secondoftwo \fi \expandafter{\expandafter \tabuthepreamble \the\tabu@thebody \tabuendlongtrial}\egroup % got \tabu@box @@ -1419,7 +1429,7 @@ \else \expandafter\@secondoftwo \fi {\expandafter \tabu@closetrialsgroup \expandafter - \scantokens \expandafter{% + \tabu@rescan \expandafter{% \expandafter\tabuthepreamble \the\expandafter\tabu@thebody \iftabu@long \else \endarray \fi}} @@ -2090,6 +2100,9 @@ \fi\fi }% \tabu@printdecimal %% Verbatim inside X columns ---------------------------------------- +%% 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 @@ -2562,6 +2575,10 @@ ifHy@hyperfootnotes\else iffalse\fi\endcsname \let\tabu@footnotetext \tabu@Hy@ftntext \let\tabu@xfootnote \tabu@Hy@xfootnote \fi +%% TABU-FIXED (issue #3) +%% REMOVED \tabu@fancyvrb +%% \ifdefined\FV@DefineCheckEnd% +%% \tabu@fancyvrb \fi \ifdefined\color % \let\tabu@color \color \def\tabu@leavevmodecolor ##1{% From 71a834675c82d69e3cc77b0f3af0b66f98640610 Mon Sep 17 00:00:00 2001 From: jfbu Date: Wed, 23 Jan 2019 19:58:38 +0100 Subject: [PATCH 07/10] Fix a stray space in added code --- tabu.sty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabu.sty b/tabu.sty index 018b8e9..7928038 100644 --- a/tabu.sty +++ b/tabu.sty @@ -1348,7 +1348,7 @@ }% \tabu@collectbody@forscan@end |def|tabu@collectbody@forscan@continue #1#2{% |def|tabu@temp{#2}% - |ifx |tabu@temp|@empty |toks@|expandafter{|the|toks@ #1\end }% + |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}}% From 535c96d4aaa1d24088455a11fa6673c71c117397 Mon Sep 17 00:00:00 2001 From: jfbu Date: Wed, 23 Jan 2019 20:32:07 +0100 Subject: [PATCH 08/10] Refactor some of the added code via \unexpanded\expandafter --- tabu.sty | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tabu.sty b/tabu.sty index 7928038..3334175 100644 --- a/tabu.sty +++ b/tabu.sty @@ -1329,29 +1329,32 @@ |edef|tabu@stack{|expandafter|tabu@pushbegins@forscan |tabu@collectbody@forscan@partial\begin|relax|expandafter|@gobble|tabu@stack}% |ifx |tabu@stack|@empty - |expandafter|@firstoftwo + |expandafter|tabu@collectbody@forscan@end |else - |expandafter|@secondoftwo + |expandafter|tabu@collectbody@forscan@continue |fi - {|expandafter|tabu@collectbody@forscan@end|expandafter{|tabu@collectbody@forscan@partial}{#1}}% - {|expandafter|tabu@collectbody@forscan@continue|expandafter{|tabu@collectbody@forscan@partial}{#1}}% + {#1}% }% \tabu@collectbody@forscan@b -|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}% +|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{#2}|tabu@gobbleX}% + |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#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}}% +|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 From f705b5a44e848005c23365d1d13578dcb1b1d4dd Mon Sep 17 00:00:00 2001 From: jfbu Date: Wed, 23 Jan 2019 22:28:10 +0100 Subject: [PATCH 09/10] Use a \toks to fix in code added in this PR the collecting of # in body This does not fix #6, but only corrects an error in this series of using macros to store partially corrected data. Switching to \toks2 also allows to avoid \unexpanded\expandafter formulation. --- tabu.sty | 12 +++++------- testfiles/t003.lvt | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tabu.sty b/tabu.sty index 3334175..84a3956 100644 --- a/tabu.sty +++ b/tabu.sty @@ -1312,7 +1312,7 @@ \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}% + |toks|tw@{#2#3}% |futurelet|tabu@temp@token|tabu@collectbody@forscan@a }% \tabu@collectbody@forscan |def|tabu@collectbody@forscan@a{% @@ -1323,11 +1323,11 @@ |fi }% \tabu@collectbody@forscan@a |def|tabu@collectbody@forscan@aa #1{% - |expandafter|tabu@collectbody@forscan@next|expandafter{|tabu@collectbody@forscan@partial\end#1}% + |expandafter|tabu@collectbody@forscan@next|expandafter{|the|toks|tw@\end#1}% }% \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}% + |the|toks|tw@\begin|relax|expandafter|@gobble|tabu@stack}% |ifx |tabu@stack|@empty |expandafter|tabu@collectbody@forscan@end |else @@ -1336,9 +1336,7 @@ {#1}% }% \tabu@collectbody@forscan@b |def|tabu@collectbody@forscan@end #1{% - |edef|tabu@@temp{|tabu@thebody{|the|toks@ - |unexpanded|expandafter{|tabu@collectbody@forscan@partial}}% - }% + |edef|tabu@@temp{|tabu@thebody{|the|toks@|the|toks|tw@}}% |toks@|expandafter{|tabu@@temp |def|tabu@end@envir{|end{#1}}% |iftabu@long |def|tabu@endenvir {|end{#1}|tabu@gobbleX}% @@ -1349,7 +1347,7 @@ |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}}% + |edef|tabu@@temp{|the|toks@|the|toks|tw@\end}% |def|tabu@temp{#1}% |ifx |tabu@temp|@empty |toks@|expandafter{|tabu@@temp}% |else |ifx|tabu@temp|tabu@@spxiii |toks@|expandafter{|tabu@@temp#1}% diff --git a/testfiles/t003.lvt b/testfiles/t003.lvt index af43afd..0350bd3 100644 --- a/testfiles/t003.lvt +++ b/testfiles/t003.lvt @@ -8,7 +8,7 @@ \START \begin{tabu*}to\linewidth{|XX|} % if }{ in the short verb then already not working in tabu 2.09 -A short verb: \verb|$&\~{}|&\\ +A short verb: \verb|$&\~{}#|&\\ \begin{Verbatim}[commandchars={\\\{\}}] And \textit{this} is a \textbf{\textrm{complete}} Verbatim environment $&~\textbraceleft\textbraceright @@ -17,7 +17,7 @@ Verbatim environment $&~\textbraceleft\textbraceright \normalfont\yyyyyy\begin{yyyyyy}hello\end{yyyyyy}hello\endyyyyyy \def\foo{foo}\meaning\foo \meaning\foo (ok as each line is\ -scoped by fancyvrb) +scoped by fancyvrb) # \begin{Large}AA{\footnotesize{}BB}CC\end{Large} \begin{Large}AA\begin{footnotesize}BB\end{footnotesize}CC\end{Large} \end{Verbatim} @@ -30,7 +30,7 @@ Verbatim environment $&~\textbraceleft\textbraceright \normalfont\yyyyyy\begin{yyyyyy}hello\end{yyyyyy}hello\endyyyyyy \def\foo{foo}\meaning\foo \meaning\foo (ok as each line is\ -scoped by fancyvrb) +scoped by fancyvrb) # \begin{Large}AA{\footnotesize{}BB}CC\end{Large} \begin{Large}AA\begin{footnotesize}BB\end{footnotesize}CC\end{Large} \end{Verbatim} From a5dd0a2a8e0196db010efc37eee6b524c2e155d5 Mon Sep 17 00:00:00 2001 From: jfbu Date: Thu, 24 Jan 2019 08:34:12 +0100 Subject: [PATCH 10/10] Revert a change done at 6e92ac8e9a to \tabu@collectbody Indeed, \tabu@collectbody is called also from \tabu@quick and \tabu@nestedmeasure, hence unconditionally removing from it some code executed under \iftabuscantokens regime was possibly a bad idea. Untested. --- tabu.sty | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tabu.sty b/tabu.sty index 84a3956..f048000 100644 --- a/tabu.sty +++ b/tabu.sty @@ -1291,7 +1291,12 @@ \ifx \tabu@stack\@empty \toks@\expandafter{\expandafter\tabu@thebody\expandafter{\the\toks@ #2}% \def\tabu@end@envir{\end{#3}}% - \def\tabu@endenvir {\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}% \let\tabu@collectbody \tabu@endofcollect \else\def\tabu@temp{#3}% \ifx \tabu@temp\@empty \toks@\expandafter{\the\toks@ #2\end }%