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

Marcel Fabian Krüger tex at 2krueger.de
Thu Nov 24 14:29:01 CET 2022


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

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

commit 1c19327dbfec5e75e9ac142033f61db67d4f662c
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


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

1c19327dbfec5e75e9ac142033f61db67d4f662c
 required/latex-lab/documentmetadata-support.dtx | 22 +++++-
 required/latex-lab/latex-lab-mathtrigger.dtx    | 91 +++++++++++++++++++++++++
 required/latex-lab/latex-lab.ins                |  1 +
 3 files changed, 113 insertions(+), 1 deletion(-)

diff --git a/required/latex-lab/documentmetadata-support.dtx b/required/latex-lab/documentmetadata-support.dtx
index 23053a48..9ff7563c 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,10 @@
              }
           }
 %    \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}
+        \RequirePackage{pdfmanagement-mathtrigger}
         \g_@@_testphase_tl
         \RequirePackage{pdfmanagement-firstaid}
       }
@@ -270,6 +282,9 @@
 %FMi \clist_new:N \g_@@_firstaidoff_clist
 %FMi \tl_new:N \g_@@_testphase_tl
 % UFi should the definition move to here?
+\tl_new:N \g_@@_mathtrigger_tl
+\tl_gset:Nn \g_@@_mathtrigger_tl {new}
+
 \keys_define:nn { document / metadata }
   {
     backend .choices:nn =
@@ -297,6 +312,11 @@
         \pdfmanagement_add:nnn {Catalog} {Lang}{(#1)}
         \AddToDocumentProperties[document]{lang}{#1}
       }
+      , mathtrigger .choices:nn =
+      {new,compat,legacy}
+      {
+        \tl_gset_eq:NN \g_@@_mathtrigger_tl \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..3c0e3a62
--- /dev/null
+++ b/required/latex-lab/latex-lab-mathtrigger.dtx
@@ -0,0 +1,91 @@
+% \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>
+%    \end{macrocode}
+%
+% 
+%    \begin{macrocode}
+\tl_if_exist:NPN \Ustartmath
+  {
+    \cs_new_:Nn \mathtrigger_start_inline_math: \Ustartmath
+    \cs_new_:Nn \mathtrigger_stop_inline_math: \Ustopmath
+    \cs_new_:Nn \mathtrigger_start_display_math: \Ustartdisplaymath
+    \cs_new_: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
+
+\tl_case:Nn \g__pdfmanagement_mathtrigger
+  {
+    {new} { \char_set_catcode_active:N \$ }
+    {compat} { \hook_gput_code:nnn {begindocument/after} {mathtrigger} { \char_set_catcode_active:N \$ } }
+    {legacy} {}
+  }
+%    \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.