From b1506c8083c5d55aa8dc1350a0ca1aea924be4b4 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 3 Sep 2020 15:28:14 +0100 Subject: [PATCH] mdwtab.dtx: Fix nested `*' column-type to work correctly. This is a little unpleasant. --- mdwtab.dtx | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/mdwtab.dtx b/mdwtab.dtx index 15e2988..03e7866 100644 --- a/mdwtab.dtx +++ b/mdwtab.dtx @@ -44,7 +44,7 @@ %<+color> [2003/08/24 1.10 Fix for people who can't spell] % \end{meta-comment} % -% \CheckSum{3402} +% \CheckSum{3421} %% \CharacterTable %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z @@ -2725,16 +2725,30 @@ \coldef ##1#2{\tabcoltype{#1}{#2}} % \end{macrocode} % -% And \lit{*}, which repeats a preamble spec. This is really easy, and not -% at all like the original one. +% And \lit{*}, which repeats a preamble spec. The tricky part is ensuring +% that nested \lit{*} specs work correctly: we must save the loop counter, in +% |\count 0|, obviously, but \emph{also} the |\iterate| macro built which +% |\loop| modifies internally. Usually you'd use grouping to fix this, but +% if we introduce a group level then we won't update the preamble registers +% correctly. Instead, queue up tokens to restore the values in \TeX's input +% list. % % \begin{macrocode} \coldef *#1#2{% - \count@#1% - \loop\ifnum\count@>0\relax% - \tab@doreadpream{#2}% - \advance\count@\m@ne% - \repeat% + \toks\tw@\expandafter{\iterate}% + \toks@{% + \count@#1% + \loop\ifnum\count@>0\relax% + \tab@doreadpream{#2}% + \advance\count@\m@ne% + \repeat% + }% + \edef\@tempa{% + \the\toks@% + \def\noexpand\iterate{\the\toks\tw@}% + \count@\the\count@% + }% + \@tempa% } % \end{macrocode} % -- 2.11.0