[latex3-commits] [git/LaTeX3-latex3-latex2e] everymath: Ue only one bool for all collection tracking (0f171f19)

Joseph Wright joseph.wright at morningstar2.co.uk
Mon Dec 12 07:26:46 CET 2022


Repository : https://github.com/latex3/latex2e
On branch  : everymath
Link       : https://github.com/latex3/latex2e/commit/0f171f190635ca380efc969c3113a35b1252e8e3

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

commit 0f171f190635ca380efc969c3113a35b1252e8e3
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Mon Dec 12 06:26:46 2022 +0000

    Ue only one bool for all collection tracking
    
    Changing how \(...\) is handled allows us to
    view grabbing as a simple yes/no.
    
    The boolean here would now be easy to expose
    if that is the desired plan.


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

0f171f190635ca380efc969c3113a35b1252e8e3
 required/latex-lab/latex-lab-mathcapture.dtx | 75 ++++++++++++++++------------
 1 file changed, 43 insertions(+), 32 deletions(-)

diff --git a/required/latex-lab/latex-lab-mathcapture.dtx b/required/latex-lab/latex-lab-mathcapture.dtx
index c98bf307..f5de4c77 100644
--- a/required/latex-lab/latex-lab-mathcapture.dtx
+++ b/required/latex-lab/latex-lab-mathcapture.dtx
@@ -124,10 +124,10 @@
 %
 % \subsection{Content grabbing}
 %
-% \begin{macro}{\@@_grab_inline_dollar:w}
+% \begin{macro}{\@@_grab_dollar:w}
 %   Grab up to a single |$|, for inline math mode.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_grab_inline_dollar:w % $
+\cs_new_protected:Npn \@@_grab_dollar:w % $
   #1 $
   {
     \@@_process:n {#1} % $
@@ -147,6 +147,18 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_grab_inline:w}
+%   Collect inline math content and deal with the need to move to math mode.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_grab_inline:w % \(
+  #1 \)
+  {
+    \@@_process:n {#1}
+    $ #1 $
+    \bool_set_false:N \l_@@_collected_bool
+  }
+%    \end{macrocode}
+% \end{macro}
 % \begin{macro}{\@@_grab_eqn:w}
 %   For the most common use of \cs{[}/\cs{]}: turn into an environment.
 %    \begin{macrocode}
@@ -158,31 +170,6 @@
 %
 % \subsection{Document commands}
 %
-% \begin{macro}{\(, \)}
-%   Here, we need to add the boolean around the structure; we also need to
-%   ensure that the conditional is finished before the |$| activates. To do
-%   that, we switch to an \pkg{expl3} structure for ease. There's no downside
-%   here to engine-protected, so we also simplify the setup a little.
-%    \begin{macrocode}
-\cs_gset_protected:Npn \( % \)
-  {
-    \bool_set_true:N \l_@@_cmd_bool
-    \mode_if_math:TF
-      { \@badmath }
-      { $ }
-  } % \(
-\cs_gset_protected:Npn \) %
-  {
-    \mode_if_math:TF
-      { $ }
-      { \@badmath }
-    \bool_set_false:N \l_@@_cmd_bool
-  }
-\cs_undefine:c { ( \c_space_tl }
-\cs_undefine:c { ) \c_space_tl }
-%    \end{macrocode}
-% \end{macro}
-%
 % \begin{macro}
 %   {\equation, \@@_equation_begin:, \equation*, \@@_equation_star_begin:}
 % \begin{macro}
@@ -216,6 +203,34 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}{\(, \)}
+%  If math mode has not been collected, we need to  do that; otherwise, worry
+%  about whether we are in math mode or not. The closing command here can only
+%  occur inside a collected math block: otherwise it will be simply used as
+%  a delimiter.
+%    \begin{macrocode}
+\cs_gset_protected:Npn \( % \)
+  {
+    \bool_if:NTF \l_@@_collected_bool
+      {
+        \mode_if_math:TF
+          { \@badmath }
+          { $ }
+      }
+      {
+        \bool_set_true:N \l_@@_collected_bool
+        \@@_grab_inline:w
+      }
+  } % \(
+\cs_gset_protected:Npn \)
+  {
+    \mode_if_math:TF
+      { $ }
+      { \@badmath }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\[, \]}
 %   Again, we need to watch for when \pkg{amsmath} is loaded after this code.
 %   The flag usage here is to cover the case where \cs{[}/\cs{]} is nested
@@ -235,8 +250,6 @@
           { \end{ equation* } }
           { \@badmath }
       }
-    \cs_undefine:c { [ \c_space_tl }
-    \cs_undefine:c { ] \c_space_tl }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -275,9 +288,7 @@
     \bool_if:NF \l_@@_collected_bool
       {
         \bool_set_true:N \l_@@_collected_bool
-        \bool_if:NTF \l_@@_cmd_bool
-          { \@@_grab_inline_cmd:w }
-          { \@@_grab_inline_dollar:w }
+        \@@_grab_dollar:w
       }
   }
 \exp_args:No \tex_everydisplay:D





More information about the latex3-commits mailing list.