[latex3-commits] [git/LaTeX3-latex3-latex2e] dollar-active: Add mathtrigger to latex-lab to make $ active (e1e89cbd)

Marcel Fabian Krüger tex at 2krueger.de
Thu Nov 24 17:54:03 CET 2022


Repository : https://github.com/latex3/latex2e
On branch  : dollar-active
Link       : https://github.com/latex3/latex2e/commit/e1e89cbd47ca1bd5f778b3b7f77f9483f332c61a

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

commit e1e89cbd47ca1bd5f778b3b7f77f9483f332c61a
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Thu Nov 24 14:29:01 2022 +0100

    Add mathtrigger to latex-lab to make $ active


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

e1e89cbd47ca1bd5f778b3b7f77f9483f332c61a
 required/latex-lab/documentmetadata-support.dtx | 26 ++++++-
 required/latex-lab/latex-lab-mathtrigger.dtx    | 93 +++++++++++++++++++++++++
 required/latex-lab/latex-lab.ins                |  1 +
 3 files changed, 119 insertions(+), 1 deletion(-)

diff --git a/required/latex-lab/documentmetadata-support.dtx b/required/latex-lab/documentmetadata-support.dtx
index 23053a48..5dfecc2e 100644
--- a/required/latex-lab/documentmetadata-support.dtx
+++ b/required/latex-lab/documentmetadata-support.dtx
@@ -87,6 +87,7 @@
 % \DescribeMkey{colorprofiles}
 % \DescribeMkey{debug}
 % \DescribeMkey{lang}
+% \DescribeMkey{mathtrigger}
 % \DescribeMkey{pdfstandard}
 % \DescribeMkey{pdfversion}
 % \DescribeMkey{testphase}
@@ -152,6 +153,16 @@
 %       related to them. More information can be found in the documentation of
 %       \pkg{pdfmanagement-firstaid}.
 %    \end{description}
+%
+%    \item[\texttt{mathtrigger}] This key specifies the behavior of |$| in the document.
+%       It takes one of three values:
+%     \begin{description}
+%     \item[\texttt{new}] is the default and makes |$| an active character. This is strongly recommended since
+%       it allows to insert hooks at the end of math blocks.
+%     \item[\texttt{compat}] is similar to \texttt{new} but only takes effect at |\begin{document}|, thereby
+%       reducing compatibility issues in package code.
+%     \item[\texttt{legacy}] keeps |$| defined as in documents which do not use \cs{DocumentMetadata}.
+%    \end{description}
 % \end{description}
 %
 % \bibliographystyle{plain}
@@ -251,9 +262,14 @@
              }
           }
 %    \end{macrocode}
-% Load more modules, the testphase code and the firstaid code. The code is only
+% Load more modules, the mathtrigger code, the testphase code and the firstaid code. The code is only
 % loaded in the first \cs{DocumentMetadata} call!
 %    \begin{macrocode}
+        \file_if_exist_input:nF {latex-lab-mathtrigger.ltx}
+        {
+          \msg_warning:nnn{meta}{latex-lab-pkg-missing}{latex-lab-mathtrigger}
+           \AddToDocumentProperties [document]{testphase/#1}{missing}
+        }
         \g_@@_testphase_tl
         \RequirePackage{pdfmanagement-firstaid}
       }
@@ -270,6 +286,9 @@
 %FMi \clist_new:N \g_@@_firstaidoff_clist
 %FMi \tl_new:N \g_@@_testphase_tl
 % UFi should the definition move to here?
+\str_new:N \g_@@_mathtrigger_str
+\str_gset:Nn \g_@@_mathtrigger_str {new}
+
 \keys_define:nn { document / metadata }
   {
     backend .choices:nn =
@@ -297,6 +316,11 @@
         \pdfmanagement_add:nnn {Catalog} {Lang}{(#1)}
         \AddToDocumentProperties[document]{lang}{#1}
       }
+      , mathtrigger .choices:nn =
+      {new,compat,legacy}
+      {
+        \str_gset:NV \g_@@_mathtrigger_str \l_keys_choice_tl
+      }
     %,xmpmeta .bool_gset:N = \g_pdfmeta_xmp_bool %see pdfmeta unused and undefined for now!
     % this uses internal command from pdfmeta, it should probably move there ...
     ,pdfstandard .code:n =
diff --git a/required/latex-lab/latex-lab-mathtrigger.dtx b/required/latex-lab/latex-lab-mathtrigger.dtx
new file mode 100644
index 00000000..6d3a1fcb
--- /dev/null
+++ b/required/latex-lab/latex-lab-mathtrigger.dtx
@@ -0,0 +1,93 @@
+% \iffalse meta-comment
+%
+%% File: latex-lab-testphase.dtx
+% Copyright (C) 2021-2022 The LaTeX Project
+%
+% It may be distributed and/or modified under the conditions of the
+% LaTeX Project Public License (LPPL), either version 1.3c of this
+% license or (at your option) any later version.  The latest version
+% of this license is in the file
+%
+%    https://www.latex-project.org/lppl.txt
+%
+%
+% The development version of the bundle can be found below
+%
+%    https://github.com/latex3/latex2e/required/latex-lab
+%
+% for those people who are interested or want to report an issue.
+%
+%<*driver>
+\documentclass{l3doc}
+\EnableCrossrefs
+\CodelineIndex
+\begin{document}
+\DocInput{latex-lab-mathtrigger.dtx}
+\end{document}
+%</driver>
+%
+% \fi
+%
+
+% \title{The \texttt{latex-lab-mathtrigger} code\thanks{}}
+% \author{Marcel Krüger \LaTeX{} Project}
+%
+% \maketitle
+%
+%
+% \begin{abstract}
+% \end{abstract}
+%
+% \section{Introduction}
+%
+%    This code implements a small change to make make the |$| sign active and add
+%    hooks to it. It can operate in three levels which are controlled though
+%    \cs{DocumentMetadata}.
+%
+% \StopEventually{\setlength\IndexMin{200pt}  \PrintIndex  }
+%
+%
+% \section{The Implementation}
+%    \begin{macrocode}
+%<@@=mathtrigger>
+\ExplSyntaxOn
+%    \end{macrocode}
+%
+% 
+%    \begin{macrocode}
+\tl_if_exist:NTF \Ustartmath
+  {
+    \cs_new_eq:NN \mathtrigger_start_inline_math: \Ustartmath
+    \cs_new_eq:NN \mathtrigger_stop_inline_math: \Ustopmath
+    \cs_new_eq:NN \mathtrigger_start_display_math: \Ustartdisplaymath
+    \cs_new_eq:NN \mathtrigger_stop_display_math: \Ustopdisplaymath
+  }
+  {
+    \cs_new_protected:Npn \mathtrigger_start_inline_math: { $ \scan_stop: }
+    \cs_new_protected:Npn \mathtrigger_stop_inline_math: { $ \scan_stop: }
+    \cs_new_protected:Npn \mathtrigger_start_display_math: { $$ }
+    \cs_new_protected:Npn \mathtrigger_stop_display_math: { $$ }
+  }
+
+\cs_new_protected:Npn \@@_trigger_shift:w
+  {
+    \peek_meaning_remove:NTF \@@_trigger_shift:w
+    {
+      \mode_if_math:TF { \mathtrigger_stop_display_math: } { \mathtrigger_start_display_math: }
+    } {
+      \mode_if_math:TF { \mathtrigger_stop_inline_math: } { \mathtrigger_start_inline_math: }
+    }
+  }
+
+\char_set_active_eq:NN \$ \@@_trigger_shift:w
+
+\str_case:Nn \g__pdfmanagement_mathtrigger_str
+  {
+    {new} { \char_set_catcode_active:N \$ }
+    {compat} { \hook_gput_code:nnn {begindocument/after} {mathtrigger} { \char_set_catcode_active:N \$ } }
+    {legacy} {}
+  }
+\ExplSyntaxOff
+%    \end{macrocode}
+% \Finale
+%
diff --git a/required/latex-lab/latex-lab.ins b/required/latex-lab/latex-lab.ins
index bc668a71..f8da3800 100644
--- a/required/latex-lab/latex-lab.ins
+++ b/required/latex-lab/latex-lab.ins
@@ -77,6 +77,7 @@ where one can also log issues in case there are any.
 \generate{\file{latex-lab-testphase-new-or.sty}{\from{latex-lab-new-or.dtx}{code}}}
 \generate{\file{latex-lab-footmisc.ltx}{\from{latex-lab-footnotes.dtx}{footmisc}}}
 \generate{\file{latex-lab-footnotes.ltx}{\from{latex-lab-footnotes.dtx}{kernel}}}
+\generate{\file{latex-lab-mathtrigger.ltx}{\from{latex-lab-mathtrigger.dtx}{code}}}
 
 
 \endbatchfile





More information about the latex3-commits mailing list.