[latex3-commits] [git/LaTeX3-latex3-latex3] main: Replace ad-hoc constructions with token_create_safe method (16bb7aba1)

Marcel Fabian Krüger tex at 2krueger.de
Mon Nov 15 15:40:40 CET 2021


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/16bb7aba1b4ffe8726b41dcfaab657eb2465ffe0

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

commit 16bb7aba1b4ffe8726b41dcfaab657eb2465ffe0
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Nov 13 21:40:40 2021 +0100

    Replace ad-hoc constructions with token_create_safe method


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

16bb7aba1b4ffe8726b41dcfaab657eb2465ffe0
 l3kernel/l3bootstrap.dtx |  7 -------
 l3kernel/l3luatex.dtx    | 30 ++++++++++++++++++++++++++++--
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/l3kernel/l3bootstrap.dtx b/l3kernel/l3bootstrap.dtx
index 7cf40957e..381473373 100644
--- a/l3kernel/l3bootstrap.dtx
+++ b/l3kernel/l3bootstrap.dtx
@@ -189,18 +189,11 @@
 %    \end{macrocode}
 %   For \LuaTeX{} we make sure the basic support is loaded:
 %   this is only necessary in plain.
-%
-%   Additionally we just ensure that \TeX{} has seen the csnames \cs{prg_return_true:}
-%   and \cs{prg_return_false:} before the Lua code builds these tokens.
 %    \begin{macrocode}
     \begingroup\expandafter\expandafter\expandafter\endgroup
     \expandafter\ifx\csname newcatcodetable\endcsname\relax
       \input{ltluatex}%
     \fi
-    \begingroup\edef\ignored{%
-      \expandafter\noexpand\csname prg_return_true:\endcsname
-      \expandafter\noexpand\csname prg_return_false:\endcsname
-    }\endgroup
     \directlua{require("expl3")}%
 %    \end{macrocode}
 %   As the user might be making a custom format, no assumption is made about
diff --git a/l3kernel/l3luatex.dtx b/l3kernel/l3luatex.dtx
index 36ddf3995..4a3e32f9d 100644
--- a/l3kernel/l3luatex.dtx
+++ b/l3kernel/l3luatex.dtx
@@ -371,9 +371,35 @@ local scan_string  = token.scan_string
 local scan_keyword = token.scan_keyword
 local put_next     = token.put_next
 local token_create = token.create
+%    \end{macrocode}
+%
+%   Since token.create only returns useful values after the tokens
+%   has been added to TeX's hash table, we define a variant which
+%   defines it first if necessary.
+%    \begin{macrocode}
+local token_create_safe
+do
+  local is_defined = token.is_defined
+  local set_char   = token.set_char
+  local runtoks    = tex.runtoks
+  local let_token  = token_create'let'
+
+  function token_create_safe(s)
+    local orig_token = token_create(s)
+    if is_defined(s, true) then
+      return orig_token
+    end
+    set_char(s, 0)
+    local new_token = token_create(s)
+    runtoks(function()
+      put_next(let_token, new_token, orig_token)
+    end)
+    return new_token
+  end
+end
 
-local true_tok     = token_create'prg_return_true:'
-local false_tok    = token_create'prg_return_false:'
+local true_tok     = token_create_safe'prg_return_true:'
+local false_tok    = token_create_safe'prg_return_false:'
 %    \end{macrocode}
 %
 %    \begin{macrocode}





More information about the latex3-commits mailing list.