[latex3-commits] [git/LaTeX3-latex3-latex2e] mathcolor: cleanup and speed improvement (d0c8b43b)

Frank Mittelbach frank.mittelbach at latex-project.org
Fri Jan 7 15:43:24 CET 2022


Repository : https://github.com/latex3/latex2e
On branch  : mathcolor
Link       : https://github.com/latex3/latex2e/commit/d0c8b43b28dc5d30a7d558a2cac43970ad4d9b09

>---------------------------------------------------------------

commit d0c8b43b28dc5d30a7d558a2cac43970ad4d9b09
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date:   Fri Jan 7 15:43:24 2022 +0100

    cleanup and speed improvement


>---------------------------------------------------------------

d0c8b43b28dc5d30a7d558a2cac43970ad4d9b09
 required/graphics/mathcolor.dtx                    |  69 +++++++----
 .../graphics/testfiles/mathcolor-03.luatex.tlg     | 134 +++++++++++++++++++++
 required/graphics/testfiles/mathcolor-03.lvt       |  30 +++++
 required/graphics/testfiles/mathcolor-03.tlg       | 129 ++++++++++++++++++++
 4 files changed, 338 insertions(+), 24 deletions(-)

diff --git a/required/graphics/mathcolor.dtx b/required/graphics/mathcolor.dtx
index 39d31c18..606460e4 100644
--- a/required/graphics/mathcolor.dtx
+++ b/required/graphics/mathcolor.dtx
@@ -15,7 +15,7 @@
 %
 %    \begin{macrocode}
 \def\mathcolorversion{v1.0a}
-\def\mathcolordate{2022/01/06}
+\def\mathcolordate{2022/01/07}
 %    \end{macrocode}
 %<*driver>
 \documentclass{l3doc}
@@ -115,16 +115,16 @@
 %
 %    If you attempt to color large operators that use explicit
 %    \cs{limits}, \cs{nolimits}, or \cs{displaylimits}, then these
-%    commands should be placed next to the operator into the
-%    \meta{math material} argument, even if the actual sub or
-%    superscripts are outside and uncolored. E.g., if you write
-%    \verb/\mathcolor{red}{\int}\limits_0^1/ you get the error message
+%    limit controls need to immediately follow the operator. However,
+%    \cs{mathcolor} is written in a way that it is possible write
 %\begin{verbatim}
-%    ! Limit controls must follow a math operator.
+%     \[  \mathcolor{red}{\int}\limits_0^1 \textrm{ or }
+%         \mathcolor{red}{\int\limits}_0^1                \]
 %\end{verbatim}
-%    and you have to correct it to 
-%    \verb/\mathcolor{red}{\int\limits}_0^1/  to achieve
-% \[  \mathcolor{red}{\int\limits}_0^1  \]
+%    and achieve the same effect:
+%     \[  \mathcolor{red}{\int}\limits_0^1 \textrm{ or }
+%         \mathcolor{red}{\int\limits}_0^1                \]
+
 %
 %
 % \MaybeStop{\setlength\IndexMin{200pt}  \PrintIndex  }
@@ -223,39 +223,60 @@
 %    \begin{macrocode}
   \peek_catcode_ignore_spaces_expand:NTF \c_math_subscript_token
 %    \end{macrocode}
-%    If we found that character we call a function that handles sub or superscripts.
+%    If we found that character we call a function that handles sub or
+%    superscripts.
 %    \begin{macrocode}
     { \_@@_handle_scripts:Nw }
 %    \end{macrocode}
-%    Otherwise we peek at the next token again (spaces and \cs{relax}
-%    are already removed) to see if it is perhaps a
-%    \cs{c_math_superscript_token}.\footnote{\texttt{interface3}
-%    doesn't explicitly state if one could reuse \cs{l_peek_token}
-%    from the outer peek directly (maybe it should), in which case
-%    this should be a bit streamlined and the secondary peek avoided!}
+%    Otherwise check if this token we peeked at (which is now stored
+%    in \cs{l_peek_token} is a superscript token.
 %    \begin{macrocode}
-    { \peek_catcode:NTF \c_math_superscript_token
+    { \token_if_math_superscript:NTF \l_peek_token
 %    \end{macrocode}
 %    If found we call the sub/superscript handler.
 %    \begin{macrocode}
       { \_@@_handle_scripts:Nw }
 %    \end{macrocode}
-%    Otherwise we look for a \texttt{'} and if found remove it and
+%    Otherwise we check if it was any of the limit operation
+%    primitives. If that is the case, e.g., if we have a situation
+%    such as
+%\begin{verbatim}
+%    \mathcolor{red}{\int}\limits_1
+%\end{verbatim}
+%    we have to move it directly after the \cs{int} to ensure there
+%    is no color reset between the operator and the \cs{limits} command.
+%    \begin{macrocode}
+      { \token_case_meaning:NnTF \l_peek_token
+          {
+            \limits   { \limits }
+            \nolimits { \nolimits }
+            \displaylimits { \displaylimits }
+          }
+%    \end{macrocode}
+%    Once that is done, we have to get rid of the token we peeked at
+%    and them 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.
+%    \begin{macrocode}
+          { \_@@_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
 %    replace it by its expansion. The reason we have to do this (and
-%    not reply on the earlier peeking to expand for us is the fact
+%    not rely on the earlier peeking to expand for us is the fact
 %    that \texttt{'} is only ``math active'' and that doesn't expand
 %    under \cs{expand} or \cs{expandafter}.
 %    \begin{macrocode}
-      { \peek_meaning_remove:NTF '
-        { \_@@_handle_scripts:Nw ^\c_group_begin_token \prim at s }
+          { \peek_meaning_remove:NTF '
+            { \_@@_handle_scripts:Nw ^\c_group_begin_token \prim at s }
 %    \end{macrocode}
 %    If it is anything else we finish off which means we reset the
 %    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
-          \seq_gpop:NN \g_@@_seq \current at color
-        }
+            { \reset at color
+              \seq_gpop:NN \g_@@_seq \current at color
+            }
+          }
       }
     }
 }
diff --git a/required/graphics/testfiles/mathcolor-03.luatex.tlg b/required/graphics/testfiles/mathcolor-03.luatex.tlg
new file mode 100644
index 00000000..8948496a
--- /dev/null
+++ b/required/graphics/testfiles/mathcolor-03.luatex.tlg
@@ -0,0 +1,134 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.
+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 ....
+Completed box being shipped out [1]
+\vbox(633.0+0.0)x407.0, direction TLT
+.\glue 16.0
+.\vbox(617.0+0.0)x345.0, shifted 62.0, direction TLT
+..\vbox(12.0+0.0)x345.0, glue set 12.0fil, direction TLT
+...\glue 0.0 plus 1.0fil
+...\hbox(0.0+0.0)x345.0, direction TLT
+....\special{color push  Black}
+....\hbox(0.0+0.0)x345.0, direction TLT
+....\special{color pop}
+..\glue 25.0
+..\glue(\lineskip) 0.0
+..\vbox(550.0+0.0)x345.0, glue set 487.03665fil, direction TLT
+...\write-{}
+...\glue(\topskip) 10.0
+...\hbox(0.0+0.0)x345.0, glue set 122.9979fil, direction TLT
+....\localpar
+.....\localinterlinepenalty=0
+.....\localbrokenpenalty=0
+.....\localleftbox=null
+.....\localrightbox=null
+....\hbox(0.0+0.0)x15.0, direction TLT
+....\hbox(0.0+0.0)x207.0021, glue set 103.50105fil, direction TLT
+.....\glue 0.0 plus 1.0fil minus 1.0fil
+.....\glue 0.0 plus 1.0fil minus 1.0fil
+....\penalty 10000
+....\glue(\parfillskip) 0.0 plus 1.0fil
+....\glue(\rightskip) 0.0
+...\penalty 10000
+...\glue(\abovedisplayskip) 10.0 plus 2.0 minus 5.0
+...\glue(\lineskip) 1.0
+...\hbox(21.12231+15.789)x123.57597, shifted 110.71202, direction TLT
+....\OML/cmm/m/it/10 A
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+....\special{color push rgb 1 0 0}
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\vbox(21.12231+15.789)x10.00002, direction TLT
+.....\kern1.0 (font)
+.....\hbox(4.51111+0.0)x10.00002, glue set 3.00694fil, shifted 2.22223, direction TLT
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613, direction TLT
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 2
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.99998 (font)
+.....\hbox(13.61122+8.61124)x10.00002, direction TLT
+......\hbox(0.0+22.22246)x10.00002, shifted -13.61122, direction TLT
+.......\OMX/cmex/m/n/5 Z
+.....\kern1.66666 (font)
+.....\hbox(4.51111+0.0)x10.00002, glue set 3.00694fil, shifted -2.22223, direction TLT
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613, direction TLT
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 1
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.0 (font)
+....\special{color pop}
+....\glue(\thinmuskip) 1.66663
+....\OML/cmm/m/it/10 x
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+....\special{color push rgb 1 0 0}
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\hbox(1.0+15.00012)x14.44447, shifted -9.50006, direction TLT
+.....\OMX/cmex/m/n/5 X
+....\vbox(18.53902+0.0)x4.48613, shifted 6.00005, direction TLT
+.....\hbox(4.51111+0.0)x4.48613, direction TLT
+......\hbox(4.51111+0.0)x3.98613, direction TLT
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 2
+......\special{color pop}
+.....\kern9.5168 (font)
+.....\hbox(4.51111+0.0)x4.48613, direction TLT
+......\hbox(4.51111+0.0)x3.98613, direction TLT
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 1
+......\special{color pop}
+....\special{color pop}
+....\glue(\thinmuskip) 1.66663
+....\OML/cmm/m/it/10 x
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+....\special{color push rgb 1 0 0}
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\vbox(18.01115+12.67783)x14.44447, direction TLT
+.....\kern1.0 (font)
+.....\hbox(4.51111+0.0)x14.44447, glue set 5.22917fil, direction TLT
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613, direction TLT
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 2
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.99998 (font)
+.....\hbox(10.50006+5.50006)x14.44447, direction TLT
+......\hbox(1.0+15.00012)x14.44447, shifted -9.50006, direction TLT
+.......\OMX/cmex/m/n/5 X
+.....\kern1.66666 (font)
+.....\hbox(4.51111+0.0)x14.44447, glue set 5.22917fil, direction TLT
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613, direction TLT
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 1
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.0 (font)
+....\special{color pop}
+....\glue(\thinmuskip) 1.66663
+....\OML/cmm/m/it/10 x
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+...\penalty 0
+...\glue(\belowdisplayskip) 10.0 plus 2.0 minus 5.0
+...\glue -5.0
+...\glue 0.0 plus 1.0fil
+...\glue 0.0
+...\glue 0.0 plus 0.0001fil
+..\glue(\baselineskip) 23.55556
+..\hbox(6.44444+0.0)x345.0, direction TLT
+...\special{color push  Black}
+...\hbox(6.44444+0.0)x345.0, glue set 170.0fil, direction TLT
+....\glue 0.0 plus 1.0fil
+....\OT1/cmr/m/n/10 1
+....\glue 0.0 plus 1.0fil
+...\special{color pop}
diff --git a/required/graphics/testfiles/mathcolor-03.lvt b/required/graphics/testfiles/mathcolor-03.lvt
new file mode 100644
index 00000000..bc96a13c
--- /dev/null
+++ b/required/graphics/testfiles/mathcolor-03.lvt
@@ -0,0 +1,30 @@
+
+\documentclass{article}
+
+
+\input{test2e}
+
+\usepackage{color}
+
+\showoutput
+
+\begin{document}
+
+\START
+
+\[
+A= \mathcolor{red}{\int}\limits_1^2 x =
+   \mathcolor{red}{\sum}\nolimits_1^2 x =
+   \mathcolor{red}{\sum}\displaylimits_1^2 x =
+\]
+
+
+
+\newpage
+
+\OMIT
+\end{document}
+
+
+
+
diff --git a/required/graphics/testfiles/mathcolor-03.tlg b/required/graphics/testfiles/mathcolor-03.tlg
new file mode 100644
index 00000000..22f2f90b
--- /dev/null
+++ b/required/graphics/testfiles/mathcolor-03.tlg
@@ -0,0 +1,129 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.
+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 ....
+Completed box being shipped out [1]
+\vbox(633.0+0.0)x407.0
+.\glue 16.0
+.\vbox(617.0+0.0)x345.0, shifted 62.0
+..\vbox(12.0+0.0)x345.0, glue set 12.0fil
+...\glue 0.0 plus 1.0fil
+...\hbox(0.0+0.0)x345.0
+....\special{color push  Black}
+....\hbox(0.0+0.0)x345.0
+....\special{color pop}
+..\glue 25.0
+..\glue(\lineskip) 0.0
+..\vbox(550.0+0.0)x345.0, glue set 487.03667fil
+...\write-{}
+...\glue(\topskip) 10.0
+...\hbox(0.0+0.0)x345.0, glue set 122.9979fil
+....\hbox(0.0+0.0)x15.0
+....\hbox(0.0+0.0)x207.0021, glue set 103.50105fil
+.....\glue 0.0 plus 1.0fil minus 1.0fil
+.....\glue 0.0 plus 1.0fil minus 1.0fil
+....\penalty 10000
+....\glue(\parfillskip) 0.0 plus 1.0fil
+....\glue(\rightskip) 0.0
+...\penalty 10000
+...\glue(\abovedisplayskip) 10.0 plus 2.0 minus 5.0
+...\glue(\lineskip) 1.0
+...\hbox(21.12231+15.789)x123.57597, shifted 110.71202, display
+....\OML/cmm/m/it/10 A
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+....\special{color push rgb 1 0 0}
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\vbox(21.12231+15.789)x10.00002
+.....\kern1.0
+.....\hbox(4.51111+0.0)x10.00002, glue set 3.00694fil, shifted 2.22223
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 2
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.99998
+.....\hbox(13.61122+8.61124)x10.00002
+......\hbox(0.0+22.22246)x10.00002, shifted -13.61122
+.......\OMX/cmex/m/n/5 Z
+.....\kern1.66666
+.....\hbox(4.51111+0.0)x10.00002, glue set 3.00694fil, shifted -2.22223
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 1
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.0
+....\special{color pop}
+....\glue(\thinmuskip) 1.66663
+....\OML/cmm/m/it/10 x
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+....\special{color push rgb 1 0 0}
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\hbox(1.0+15.00012)x14.44447, shifted -9.50006
+.....\OMX/cmex/m/n/5 X
+....\vbox(18.53902+0.0)x4.48613, shifted 6.00005
+.....\hbox(4.51111+0.0)x4.48613
+......\hbox(4.51111+0.0)x3.98613
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 2
+......\special{color pop}
+.....\kern9.5168
+.....\hbox(4.51111+0.0)x4.48613
+......\hbox(4.51111+0.0)x3.98613
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 1
+......\special{color pop}
+....\special{color pop}
+....\glue(\thinmuskip) 1.66663
+....\OML/cmm/m/it/10 x
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+....\special{color push rgb 1 0 0}
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\vbox(18.01115+12.67783)x14.44447
+.....\kern1.0
+.....\hbox(4.51111+0.0)x14.44447, glue set 5.22917fil
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 2
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.99998
+.....\hbox(10.50006+5.50006)x14.44447
+......\hbox(1.0+15.00012)x14.44447, shifted -9.50006
+.......\OMX/cmex/m/n/5 X
+.....\kern1.66666
+.....\hbox(4.51111+0.0)x14.44447, glue set 5.22917fil
+......\glue 0.0 plus 1.0fil minus 1.0fil
+......\hbox(4.51111+0.0)x3.98613
+.......\special{color push  Black}
+.......\OT1/cmr/m/n/7 1
+......\special{color pop}
+......\glue 0.0 plus 1.0fil minus 1.0fil
+.....\kern1.0
+....\special{color pop}
+....\glue(\thinmuskip) 1.66663
+....\OML/cmm/m/it/10 x
+....\glue(\thickmuskip) 2.77771 plus 2.77771
+....\OT1/cmr/m/n/10 =
+...\penalty 0
+...\glue(\belowdisplayskip) 10.0 plus 2.0 minus 5.0
+...\glue -5.0
+...\glue 0.0 plus 1.0fil
+...\glue 0.0
+...\glue 0.0 plus 0.0001fil
+..\glue(\baselineskip) 23.55556
+..\hbox(6.44444+0.0)x345.0
+...\special{color push  Black}
+...\hbox(6.44444+0.0)x345.0, glue set 170.0fil
+....\glue 0.0 plus 1.0fil
+....\OT1/cmr/m/n/10 1
+....\glue 0.0 plus 1.0fil
+...\special{color pop}





More information about the latex3-commits mailing list.