[latex3-commits] [latex3/latex2e] develop: Support trailing opt. args. in >{...} despite a master counter oddity (786f6b75)
github at latex-project.org
github at latex-project.org
Sat Oct 12 12:49:02 CEST 2024
Repository : https://github.com/latex3/latex2e
On branch : develop
Link : https://github.com/latex3/latex2e/commit/786f6b7552a23c4773a88d21ba28a7c9bad52954
>---------------------------------------------------------------
commit 786f6b7552a23c4773a88d21ba28a7c9bad52954
Author: Joseph Wright <joseph at texdev.net>
Date: Sat Oct 12 10:37:14 2024 +0100
Support trailing opt. args. in >{...} despite a master counter oddity
Idea here is from David: likely we are dealing with a TeX bug or at least
some very odd behaviour of the master counter, but the low-energy path
is to avoid the issue.
>---------------------------------------------------------------
786f6b7552a23c4773a88d21ba28a7c9bad52954
required/tools/array.dtx | 38 +++++++++++++++++++++++++++++++-------
required/tools/changes.txt | 6 ++++++
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/required/tools/array.dtx b/required/tools/array.dtx
index c75bcd93..bacef419 100644
--- a/required/tools/array.dtx
+++ b/required/tools/array.dtx
@@ -39,7 +39,7 @@
% \begin{macrocode}
%<+package>\NeedsTeXFormat{LaTeX2e}[2024/06/01]
%<+package>\ProvidesPackage{array}
-%<+package> [2024/09/17 v2.6f Tabular extension package (FMi)]
+%<+package> [2024/10/12 v2.6g Tabular extension package (FMi)]
%
% \fi
%
@@ -1373,6 +1373,7 @@ Bug reports can be opened (category \texttt{#1}) at\\%
% \begin{macro}{\insert at column}
% \begin{macro}{\@sharp}
% \begin{macro}{\textonly at unskip}
+% \begin{macro}{\@protected at firstofone}
% We now define the macro =\insert at column= which will do
% this work for us.
% \begin{macrocode}
@@ -1388,11 +1389,29 @@ Bug reports can be opened (category \texttt{#1}) at\\%
% Here, we assume that the \textsf{count} register
% =\@tempcnta= has saved the value $=\count@= - 1$.
%
-% We end with \cs{relax} to stop any parsing for optional
-% arguments out of \verb=>{...}= at this point.
+% To keep \TeX{} happy if there is a look ahead in the tabular preamble
+% which uses the Appendix~D trick (for example anything with a trailing
+% optional argument defined by \pkg{ltcmd}), we wrap everything here in
+% a protected version of \cs{@firstofone}. \TeX{} otherwise can get
+% confused about the value of the master counter, and we get some
+% strange errors. (Quite possibly the underlying issue is a \TeX{}
+% bug, but rather than try to fix in 2024 we accept it's there and
+% work-around.) As an example, without this approach, something
+% like
+% \begin{verbatim}
+%\NewDocumentCommand\foo{o}{x}
+%\begin{tabular}{>{\foo}l}
+% Foo
+%\end{tabular}
+% \end{verbatim}
+% will fail; that can be fixed by adding a \cs{relax} after the \cs{@tempcnta},
+% but that then leads to issues if you are collecting whole cells (tagging code
+% or \\pkg{collcell}), where you can no longer alter the meaning of \cs{cr}
+% as the master counter goes wrong.
% \changes{v2.6f}{2024/09/13}{Stop parsing for optional argument (gh/1468)}
+% \changes{v2.6g}{2024/10/12}{Further work to support optional args in preamble (gh/1468)}
% \begin{macrocode}
- \the at toks \the \@tempcnta \relax
+ \@protected at firstofone { \the at toks \the \@tempcnta \ignorespaces }
% \end{macrocode}
% Next follows the =#= sign which specifies the place
% where the text of the column shall be inserted. To avoid
@@ -1401,13 +1420,13 @@ Bug reports can be opened (category \texttt{#1}) at\\%
% =\@sharp= which is temporarily occupied with
% =\relax= during the build-up of the preamble.
% To remove unwanted spaces before and after the column text, we set
-% an =\ignorespaces= in front and a =\unskip= afterwards.
+% an =\ignorespaces= in front (see above) and a =\unskip= afterwards.
% \changes{v2.0e}{1991/02/07}{Added \{\} around \cs{@sharp} for new ftsel}
% \changes{v2.0h}{1992/06/22}{Removed \{\} again in favour of
% \cs{d at llarbegin}}
% \changes{v2.6b}{2024/04/08}{Do not \cs{unskip} if in math mode (gh/1323)}
% \begin{macrocode}
- \ignorespaces \@sharp \textonly at unskip
+ \@sharp \textonly at unskip
% \end{macrocode}
% Then the second \textsf{token} register follows whose number should
% be saved in =\count@=.
@@ -1432,10 +1451,15 @@ Bug reports can be opened (category \texttt{#1}) at\\%
% \begin{macrocode}
\protected\def\textonly at unskip{\ifhmode\unskip\fi}
% \end{macrocode}
+% \changes{v2.6g}{2024/10/12}{Further work to support optional args in preamble (gh/1468)}
+% We need an engine-protected function that is just \cs{@firstofone}:
+% \begin{macrocode}
+\protected\def\@protected at firstofone#1{#1}
+% \end{macrocode}
+% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
-%
%
% \begin{macro}{\insert at pcolumn}
% Handling pcolumn-cells needs slightly different handling when
diff --git a/required/tools/changes.txt b/required/tools/changes.txt
index 61e4bcdb..5dc28980 100644
--- a/required/tools/changes.txt
+++ b/required/tools/changes.txt
@@ -5,6 +5,12 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
=======================================================================
+2024-10-12 Joseph Wright <Joseph.Wright at latex-project.org>
+
+ * array.dtx (section{The insertion of declarations ...}):
+ Further work on handling optional arguments in the argument
+ of >{...} to work around a master counter oddity (gh/1468)
+
2024-09-18 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
* array.dtx (section{The insertion of declarations ...}):
More information about the latex3-commits
mailing list.