[latex3-commits] [git/LaTeX3-latex3-latex2e] gh901: fix for #901 (4e104c77)
Frank Mittelbach
frank.mittelbach at latex-project.org
Mon Jul 25 11:00:03 CEST 2022
Repository : https://github.com/latex3/latex2e
On branch : gh901
Link : https://github.com/latex3/latex2e/commit/4e104c7791b8aec397e4c351355e82f9c68f5c40
>---------------------------------------------------------------
commit 4e104c7791b8aec397e4c351355e82f9c68f5c40
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date: Mon Jul 25 11:00:03 2022 +0200
fix for #901
>---------------------------------------------------------------
4e104c7791b8aec397e4c351355e82f9c68f5c40
base/doc/ltnews36.tex | 31 ++++++++--
required/graphics/changes.txt | 6 ++
required/graphics/mathcolor.dtx | 69 +++++++++++++++++-----
required/graphics/testfiles/github-0901.lvt | 58 ++++++++++++++++++
.../graphics/testfiles/github-0901.tlg | 3 +-
5 files changed, 144 insertions(+), 23 deletions(-)
diff --git a/base/doc/ltnews36.tex b/base/doc/ltnews36.tex
index df72bc1d..88f2b855 100644
--- a/base/doc/ltnews36.tex
+++ b/base/doc/ltnews36.tex
@@ -143,8 +143,11 @@
\section{Introduction}
+\emph{to be written}
+
\section{New or improved commands}
+
\section{Code improvements}
\subsection{Support for slanted small caps in the EC-fonts }
@@ -168,20 +171,36 @@ will give the expected result: {\fontfamily{cmr}
\subsection{EC sans serif at small sizes}
+
The EC (T1 encoded Computer Modern) sans serif fonts have errors at
-small sizes. (The medium weight is bolder and wider than the bold
-extended) The default \texttt{.fd} file has been adjusted to use a
-scaled 8pt font.
+small sizes: the medium weight is bolder and wider than the bold
+extended. This makes them unusable at these small sizes. The default
+\texttt{.fd} file has therefore been adjusted to use a scaled down 8pt
+font instead.
%
\githubissue{879}
\section{Bug fixes}
+
\section{Changes to packages in the \pkg{amsmath} category}
+
\section{Changes to packages in the \pkg{graphics} category}
+\subsection{Fix a \cs{mathcolor} bug}
+
+The \cs{mathcolor} command intorduced in \cite{36:ltnews35} needs to
+scan for following sub and superscripts, but if it did so at the end
+of an alignment cell, e.g., in a \texttt{array} environment, the
+\texttt{\&} was evaluated too early causing some internal errors. This
+is now properly guarded for.
+%
+\githubissue{901}
+
+
+
\section{Changes to packages in the \pkg{tools} category}
@@ -211,9 +230,9 @@ scaled 8pt font.
% \emph{\LaTeXe{} news 33}.\\
% \url{https://latex-project.org/news/latex2e-news/ltnews33.pdf}
-%\bibitem{36:ltnews34} \LaTeX{} Project Team:
-% \emph{\LaTeXe{} news 34}.\\
-% \url{https://latex-project.org/news/latex2e-news/ltnews34.pdf}
+\bibitem{36:ltnews35} \LaTeX{} Project Team:
+ \emph{\LaTeXe{} news 35}.\\
+ \url{https://latex-project.org/news/latex2e-news/ltnews35.pdf}
%
%\bibitem{36:ltfilehook-doc} Frank Mittelbach, Phelype Oleinik, \LaTeX{}~Project~Team:
% \emph{The \texttt{\upshape ltfilehook} documentation}.\\
diff --git a/required/graphics/changes.txt b/required/graphics/changes.txt
index 616f5623..313d3d42 100644
--- a/required/graphics/changes.txt
+++ b/required/graphics/changes.txt
@@ -8,6 +8,12 @@ are not part of the distribution.
All changes above are only part of the development branch for the next release.
================================================================================
+2022-07-25 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
+
+ * mathcolor.dtx (section{The Implementation}):
+ Avoid ending an alignment cell prematurely when hitting an
+ & during scanning (gh/901)
+
#########################
# 2022-06-01 Release
#########################
diff --git a/required/graphics/mathcolor.dtx b/required/graphics/mathcolor.dtx
index 2341e71e..89408482 100644
--- a/required/graphics/mathcolor.dtx
+++ b/required/graphics/mathcolor.dtx
@@ -14,8 +14,8 @@
%%% From File: mathcolor.dtx
%
% \begin{macrocode}
-\def\mathcolorversion{v1.0b}
-\def\mathcolordate{2022/01/28}
+\def\mathcolorversion{v1.0c}
+\def\mathcolordate{2022/07/25}
% \end{macrocode}
%<*driver>
\documentclass{l3doc}
@@ -223,11 +223,36 @@
% \cs{mathop} in which case the sub and superscripts may be
% attached as \cs{limits} instead of after the material. All cases
% need separate treatment.
+% And we need to watch out for an upcoming \verb=&= and avoid
+% prematurely triggering the end of an alignment cell.
+% \changes{v1.0c}{2022/07/25}{Avoid ending an alignment cell
+% prematurely when hitting an \texttt{\&} during
+% scanning (gh/901)}
% \begin{macrocode}
\cs_new_protected:Npn \@@_scan_for_scripts:w {
% \end{macrocode}
-% We therefore first parse for a \cs{c_math_subscript_token}
-% ignoring (dropping) any spaces and \cs{relax} as \TeX{} would
+% To avoid problems hitting on \verb=&= we start with a
+% \cs{group_align_safe_begin:}. That has to be ended with
+% \cs{group_align_safe_end:} when the
+% danger (aka scanning) is over, which, due to the branching below, happens at
+% four different points, i.e., when the \cs{mathcolor} is
+% \begin{enumerate}
+% \item
+% followed by a \enquote{normal} token;
+% \item
+% followed by a braced sub/superscript;
+% \item
+% followed by an unbraced sub/superscript;
+% \item
+% followed by one of the \cs{limit}s primitives.
+% \end{enumerate}
+% In each case we have to end the align save group and we mark the
+% points below in the code for easy reference.
+% \begin{macrocode}
+ \group_align_safe_begin:
+% \end{macrocode}
+% We first parse for a \cs{c_math_subscript_token}
+% ignoring (and dropping) any spaces and \cs{relax} as \TeX{} would
% do. We do this with expansion so that hidden sub or superscripts
% in macros are still found as long as the macros are expandable.
% \begin{macrocode}
@@ -236,7 +261,7 @@
% If we found that character we call a function that handles sub or
% superscripts.
% \begin{macrocode}
- { \@@_handle_scripts:Nw }
+ { \@@_handle_scripts:Nw }
% \end{macrocode}
% Otherwise check if this token we peeked at (which is now stored
% in \cs{l_peek_token} is a superscript token.
@@ -266,11 +291,16 @@
% Once that is done, we have to get rid of the token we peeked at
% and then restart scanning for sub or superscripts. Given that
% \cs{@@_scan_for_scripts:w} expands while scanning the simplest
-% solution is to add \cs{use_none:n} in front of the peeked at token.
+% solution is to add \cs{use_none:n} in front of the peeked at
+% token.
+%
+% Here we end the align save group and
+% \cs{@@_scan_for_scripts:w} will start a new one.
% \begin{macrocode}
- { \@@_scan_for_scripts:w \use_none:n }
+ { \group_align_safe_end: % case 4
+ \@@_scan_for_scripts:w \use_none:n }
% \end{macrocode}
-% If it was one of these we look for a \texttt{'} and if found remove it and
+% If it was not one of these we look for a \texttt{'} and if found remove it and
% replace it by its expansion. The reason we have to do this (and
% not rely on the earlier peeking to expand for us is the fact
% that \texttt{'} is only ``math active'' and that doesn't expand
@@ -283,7 +313,8 @@
% color (because we prevented that before to happen automatically
% after the next group) and pop the color stack setting \cs{current at color}.
% \begin{macrocode}
- { \reset at color
+ { \group_align_safe_end: % case 1
+ \reset at color
\seq_gpop:NN \g_@@_seq \current at color
}
}
@@ -341,19 +372,27 @@
% already supplied the outer one already. In that case we drop
% it. Otherwise we have an unbraced single token sub or superscript
% which means we are missing a closing \verb=}= at the end and need
-% to account for that: this is done in \cs{_@@_handle_unbraced_script:N}.
+% to account for that: this is done in
+% \cs{_@@_handle_unbraced_script:N}.
+%
+% After scanning for a brace all scanning is done, so here are the
+% other two points where we have to end the align save group (in
+% the true and false case).
% \begin{macrocode}
\@@_peek_catcode_ignore_filler_expand:NTF \c_group_begin_token
- { \peek_catcode_remove:NT \c_group_begin_token { } }
- { \@@_handle_unbraced_script:N }
- }% \end{macrocode}
+ { \group_align_safe_end: % case 2
+ \peek_catcode_remove:NT \c_group_begin_token { } }
+ { \@@_handle_unbraced_script:N }
+ }
+% \end{macrocode}
% \end{macro}
-
-
+%
+%
% \begin{macro}{\@@_handle_unbraced_script:N}
% All we have to do here is to add the final closing brace.
% \begin{macrocode}
\cs_new_protected:Npn \@@_handle_unbraced_script:N #1 {
+ \group_align_safe_end: % case 3
#1 \c_group_end_token }
% \end{macrocode}
% \end{macro}
diff --git a/required/graphics/testfiles/github-0901.lvt b/required/graphics/testfiles/github-0901.lvt
new file mode 100644
index 00000000..f2201f68
--- /dev/null
+++ b/required/graphics/testfiles/github-0901.lvt
@@ -0,0 +1,58 @@
+
+\documentclass{article}
+
+\input{test2e}
+
+\usepackage{color}
+
+
+\begin{document}
+
+\START
+
+% scanning ahead should not raise parsing errors when hitting an &
+% not should avoiding this generate failures.
+
+\typeout{this test should not generate any errors}
+
+\[
+\begin{array}{ccc}
+ a\mathcolor{red}{1}& b
+\end{array}
+\]
+
+\[
+\begin{array}{ccc}
+ a\mathcolor{red}{2} & b \\ bad case
+\end{array}
+\]
+
+\[
+\begin{array}{ccc}
+ a\mathcolor{red}{3}^x& b \\ ?? case
+\end{array}
+\]
+
+\[
+\begin{array}{ccc}
+ a\mathcolor{red}{4}_x & b \\ ?? case
+\end{array}
+\]
+
+\[
+\begin{array}{ccc}
+ a\mathcolor{red}{5} _x & b \\ ?? case
+\end{array}
+\]
+
+\[
+\begin{array}{ccc}
+ a\mathcolor{red}{6} _x^z & b \\ ?? case
+\end{array}
+\]
+
+\END
+
+
+
+
diff --git a/base/testfiles/tlb2049.tlg b/required/graphics/testfiles/github-0901.tlg
similarity index 88%
copy from base/testfiles/tlb2049.tlg
copy to required/graphics/testfiles/github-0901.tlg
index f2680325..f6046953 100644
--- a/base/testfiles/tlb2049.tlg
+++ b/required/graphics/testfiles/github-0901.tlg
@@ -1,8 +1,7 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
+this test should not generate any errors
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <7> on input line ....
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <5> on input line ....
-[1
-] (tlb2049.aux)
More information about the latex3-commits
mailing list.