[latex3-commits] [git/LaTeX3-latex3-latex2e] mathcolor: Restrict \mathcolor to math mode (8ba77795)
Frank Mittelbach
frank.mittelbach at latex-project.org
Fri Jan 28 23:28:26 CET 2022
Repository : https://github.com/latex3/latex2e
On branch : mathcolor
Link : https://github.com/latex3/latex2e/commit/8ba777959af1fc646b1081c5a279241f1ce2d39f
>---------------------------------------------------------------
commit 8ba777959af1fc646b1081c5a279241f1ce2d39f
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date: Fri Jan 28 23:28:26 2022 +0100
Restrict \mathcolor to math mode
>---------------------------------------------------------------
8ba777959af1fc646b1081c5a279241f1ce2d39f
base/doc/ltnews35.tex | 1 +
required/graphics/changes.txt | 2 +-
required/graphics/mathcolor.dtx | 15 +++++++++++---
required/graphics/testfiles/mathcolor-04.lvt | 24 ++++++++++++++++++++++
.../graphics/testfiles/mathcolor-04.tlg | 4 ++--
5 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/base/doc/ltnews35.tex b/base/doc/ltnews35.tex
index 98a796df..4c1b910b 100644
--- a/base/doc/ltnews35.tex
+++ b/base/doc/ltnews35.tex
@@ -550,6 +550,7 @@ spacing. Thus, the above example can now be written as
\begin{verbatim}
\[ X = \mathcolor{red}{\sum}_{i=1}^n x_i \]
\end{verbatim}
+This command is \emph{only} allowed in formulas.
For details and further examples, see \file{mathcolor.pdf}.
diff --git a/required/graphics/changes.txt b/required/graphics/changes.txt
index 72a106c3..5ec10ab1 100644
--- a/required/graphics/changes.txt
+++ b/required/graphics/changes.txt
@@ -8,7 +8,7 @@ are not part of the distribution.
* mathcolor.dtx:
Support \mathcolor to correctly color parts of formulas without
- spacing problems.
+ spacing problems. This command is *only* supported in math mode.
================================================================================
All changes above are only part of the development branch for the next release.
diff --git a/required/graphics/mathcolor.dtx b/required/graphics/mathcolor.dtx
index 6ed53f8f..cd2ab199 100644
--- a/required/graphics/mathcolor.dtx
+++ b/required/graphics/mathcolor.dtx
@@ -14,8 +14,8 @@
%%% From File: mathcolor.dtx
%
% \begin{macrocode}
-\def\mathcolorversion{v1.0a}
-\def\mathcolordate{2022/01/07}
+\def\mathcolorversion{v1.0b}
+\def\mathcolordate{2022/01/28}
% \end{macrocode}
%<*driver>
\documentclass{l3doc}
@@ -165,7 +165,16 @@
% \begin{macrocode}
\DeclareDocumentCommand \mathcolor { o m m } {
% \end{macrocode}
-% First action is to save the current color value on a stack
+% The \cs{mathcolor} is only supported in math mode because in text
+% mode it has problems scanning away a space after it, for example.
+% We therefore raise an error if it executes
+% anywhere else. The \LaTeXe{} error command is a
+% bit strangely named, because in the kernel it is only used for
+% math alphabets, but the message it gives is fine.
+% \begin{macrocode}
+ \mode_if_math:F { \non at alpherr {\mathcolor\space} }
+% \end{macrocode}
+% First real action is to save the current color value on a stack
% (needed if the command is nested or contains some further color
% changes with \cs{color} inside).
% \begin{macrocode}
diff --git a/required/graphics/testfiles/mathcolor-04.lvt b/required/graphics/testfiles/mathcolor-04.lvt
new file mode 100644
index 00000000..c17b98c0
--- /dev/null
+++ b/required/graphics/testfiles/mathcolor-04.lvt
@@ -0,0 +1,24 @@
+
+\documentclass{article}
+
+
+\input{test2e}
+
+\usepackage{color}
+
+
+\begin{document}
+
+\START
+
+% this should give an error, that it then tries typesetting and
+% usually manages to do something if the argument is not generating
+% further errors is a side-effect and helps you to carry on.
+
+ \mathcolor{red}{x}
+
+\END
+
+
+
+
diff --git a/base/testfiles/github-0501.tlg b/required/graphics/testfiles/mathcolor-04.tlg
similarity index 81%
copy from base/testfiles/github-0501.tlg
copy to required/graphics/testfiles/mathcolor-04.tlg
index ee87539b..e0a88557 100644
--- a/base/testfiles/github-0501.tlg
+++ b/required/graphics/testfiles/mathcolor-04.tlg
@@ -1,9 +1,9 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
-! LaTeX Error: \mathit allowed only in math mode.
+! LaTeX Error: \mathcolor allowed only in math mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
-l. ...\mathit{x}
+l. ... \mathcolor{red}{x}
You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
More information about the latex3-commits
mailing list.