texlive[69341] Master/texmf-dist: pyluatex (6jan24)

commits+karl at tug.org commits+karl at tug.org
Sun Jan 7 22:28:53 CET 2024


Revision: 69341
          https://tug.org/svn/texlive?view=revision&revision=69341
Author:   karl
Date:     2024-01-07 22:28:53 +0100 (Sun, 07 Jan 2024)
Log Message:
-----------
pyluatex (6jan24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/data-visualization.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-external.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-custom-env.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-example.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/sessions.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-example.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-listings.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-minted.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex
    trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py
    trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
    trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md	2024-01-07 21:28:53 UTC (rev 69341)
@@ -35,7 +35,7 @@
 
 2\. Compile using LuaLaTeX (shell escape is required)
 ```
-lualatex -shell-escape example.tex
+lualatex --shell-escape example.tex
 ```
 
 **Note:** PyLuaTeX starts Python 3 using the command `python3` by default.
@@ -53,7 +53,7 @@
 
 ## License
 [LPPL 1.3c](http://www.latex-project.org/lppl.txt) for LaTeX code and
-[MIT license](https://opensource.org/licenses/MIT) for Python and Lua code.
+[MIT license](https://opensource.org/licenses/MIT) for Python and Lua code and other files.
 
 ## Further Information
 Author: Tobias Enderle

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/data-visualization.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/data-visualization.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/data-visualization.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-external.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-external.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-external.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-custom-env.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-custom-env.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-custom-env.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-example.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-example.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/readme-example.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c
@@ -57,7 +57,7 @@
 \maketitle
 
 PyLuaTeX allows you to run and typeset Python code in an interactive console
-or read–eval–print loop (REPL) fashion. Very much like in an interactive python session,
+or read–eval–print loop (REPL) fashion. Very much like in an interactive Python session,
 code is prefixed with \verb|>>>| (or \verb|...| in case of multi-line commands)
 and the results are added to the output buffer automatically.
 

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/sessions.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/sessions.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/sessions.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-example.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-example.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-example.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-listings.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-listings.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-listings.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-minted.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-minted.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/typesetting-minted.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex	2024-01-07 21:28:53 UTC (rev 69341)
@@ -15,7 +15,7 @@
 \usepackage{url}
 \title{The \emph{pyluatex} package}
 \author{Tobias Enderle\\\url{https://github.com/tndrle/PyLuaTeX}}
-\date{v0.6.1 (2023/02/15)}
+\date{v0.6.2 (2024/01/07)}
 \begin{document}
 \maketitle
 \raggedright
@@ -57,7 +57,7 @@
 \item  Compile using Lua\LaTeX{} (shell escape is required)
 \begin{tcblisting}{breakable,listing only,
     size=fbox,colframe=black!8,boxrule=3pt,colback=black!8}
-lualatex -shell-escape example.tex
+lualatex --shell-escape example.tex
 \end{tcblisting}
 \end{enumerate}
 \textbf{Note:} PyLuaTeX starts Python 3 using the command \inlcode|python3| by default.
@@ -122,7 +122,8 @@
 \item \inlcode|shutdown|\\[0.5ex]
   Specifies when the Python process is shut down. (default: \inlcode|veryveryend|)\\[0.5ex]
   \textit{Options:} \inlcode|veryveryend|, \inlcode|veryenddocument|, \inlcode|off|\\[0.5ex]
-  PyLuaTeX uses the hooks of the package \textit{atveryend} to shut down the Python interpreter when the compilation is done. With the option \inlcode|veryveryend|, Python is shut down in the \inlcode|\AtVeryVeryEnd| hook. With the option \inlcode|veryenddocument|, Python is shut down in the \inlcode|\AtVeryEndDocument| hook. With the option \inlcode|off|, Python is not shut down explicitly. However, the Python process will shut down when the LuaTeX process finishes even if \inlcode|off| is selected. Using \inlcode|off| on Windows might lead to problems with SyncTeX, though.\\[0.5ex]
+  PyLuaTeX shuts down the Python interpreter when the compilation is done. With the option \inlcode|veryveryend|, Python is shut down in the \inlcode|enddocument/end| hook. With the option \inlcode|veryenddocument|, Python is shut down in the \inlcode|enddocument/afteraux| hook. With the option \inlcode|off|, Python is not shut down explicitly. However, the Python process will shut down when the LuaTeX process finishes even if \inlcode|off| is selected. Using \inlcode|off| on Windows might lead to problems with SyncTeX, though.\\[0.5ex]
+  Before v0.6.2, PyLuaTeX used the hooks \inlcode|\AtVeryVeryEnd| and \inlcode|\AtVeryEndDocument| of the package \textit{atveryend}. The new hooks \inlcode|enddocument/end| and \inlcode|enddocument/afteraux| are equivalent to those of the \textit{atveryend} package.\\[0.5ex]
   \textit{Example:} \inlcode|\usepackage[shutdown=veryenddocument]{pyluatex}|
 \item \inlcode|verbose|\\[0.5ex]
   If this option is set, Python input and output is written to the \LaTeX{} log file.\\[0.5ex]
@@ -285,5 +286,5 @@
 
 \section{License}
 LPPL 1.3c\footnote{\url{http://www.latex-project.org/lppl.txt}} for \LaTeX{} code and
-MIT license\footnote{\url{https://opensource.org/licenses/MIT}} for Python and Lua code.
+MIT license\footnote{\url{https://opensource.org/licenses/MIT}} for Python and Lua code and other files.
 \end{document}

Modified: trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,7 +1,7 @@
 """
 MIT License
 
-Copyright (c) 2021-2023 Tobias Enderle
+Copyright (c) 2021-2024 Tobias Enderle
 
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),

Modified: trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,7 +1,7 @@
 --[[
 MIT License
 
-Copyright (c) 2021-2023 Tobias Enderle
+Copyright (c) 2021-2024 Tobias Enderle
 
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),
@@ -22,7 +22,7 @@
 IN THE SOFTWARE.
 --]]
 
-require("lualibs-util-jsn")
+require("lualibs")
 local socket = require("socket")
 
 pyluatex = pyluatex or {
@@ -31,8 +31,6 @@
     session = "default"
 }
 
-local dir_sep = package.config:sub(1,1)
-
 -- status.filename: path to pyluatex.sty
 local folder = file.pathpart(file.collapsepath(status.filename, true))
 local tcp = nil
@@ -40,15 +38,13 @@
 local env_end = nil
 local env_lines = nil
 local parent_env = nil
-local env_repl_mode = false
-local env_success = true
 
 local last_code = nil
 local last_output = nil
 
 local function get_tex_file_folder()
-    for k, v in ipairs(arg) do
-        if not v:find("^%-") then
+    for _, v in ipairs(arg) do
+        if v:sub(1, 1) ~= "-" then
             local path = file.collapsepath(v, true)
             if lfs.isfile(path) then
                 return file.pathpart(path)
@@ -63,27 +59,26 @@
     return nil
 end
 
-local function trim(s)
-    return (s:gsub("^%s*(.-)%s*$", "%1"))
+local function show_err(message)
+    tex.sprint("\\PackageError{PyLuaTeX}{" .. message .. "}{}")
 end
 
-local function err_cmd(message)
-    return "\\PackageError{PyLuaTeX}{" .. message .. "}{}"
+local function not_empty(str)
+    return str ~= nil and str ~= ""
 end
 
 function pyluatex.start(executable, local_imports)
     local script = file.join(folder, "pyluatex-interpreter.py")
-    local is_windows = dir_sep ~= "/"
 
     local cmd = ""
     if local_imports then
         local tex_file_folder = get_tex_file_folder()
         if tex_file_folder ~= nil then
-            cmd = " \"" .. tex_file_folder .. "\""
+            cmd = ' "' .. tex_file_folder .. '"'
         end
     end
-    cmd = executable .. " \"" .. script .. "\"" .. cmd
-    if is_windows then
+    cmd = executable .. ' "' .. script .. '"' .. cmd
+    if os.type == "windows" then
         cmd = "start /B " .. cmd
     else
         cmd = cmd .. " &"
@@ -92,8 +87,8 @@
     local port = f:read("*l")
     f:close()
 
-    function err(message)
-        tex.sprint(err_cmd("Python backend could not be started (" .. message .. ")"))
+    local function err(message)
+        show_err("Python backend could not be started (" .. message .. ")")
     end
 
     if port == nil then
@@ -100,7 +95,7 @@
         err("executable: " .. executable)
         return
     end
-    port = trim(port)
+    port = port:fullstrip()
     if port:match("^%d+$") == nil then
         err("invalid TCP port: " .. port)
         return
@@ -121,26 +116,6 @@
     return utilities.json.tolua(output)
 end
 
-local function log_input(code)
-    texio.write_nl("PyLuaTeX input for session \"" .. pyluatex.session .. "\": " .. code)
-end
-
-local function log_output(code)
-    texio.write_nl("PyLuaTeX output: " .. code)
-end
-
-local function split_lines(str)
-    if str:sub(-1) ~= "\n" then
-        str = str .. "\n"
-    end
-
-    local t = {}
-    for s in str:gmatch("(.-)\r?\n") do
-        table.insert(t, s)
-    end
-    return t
-end
-
 function pyluatex.execute(code, auto_print, write, repl_mode, store)
     local full_code
     if auto_print then
@@ -149,63 +124,49 @@
         full_code = code
     end
 
-    if pyluatex.verbose then log_input(full_code) end
-
-    local resp = request(
-        {
-            session = pyluatex.session,
-            code = full_code,
-            repl_mode = repl_mode,
-            ignore_errors = pyluatex.ignore_errors
-        }
-    )
-    local output_lines = split_lines(resp.output)
+    local resp = request({
+        session = pyluatex.session,
+        code = full_code,
+        repl_mode = repl_mode,
+        ignore_errors = pyluatex.ignore_errors
+    })
+    local code_lines = code:splitlines()
+    local output_lines = resp.output:splitlines()
     if store then
-        last_code = split_lines(code)
+        last_code = code_lines
         last_output = output_lines
     end
 
+    if pyluatex.verbose or not resp.success then
+        texio.write_nl('PyLuaTeX input for session "' .. pyluatex.session ..
+            '": ' .. full_code)
+        texio.write_nl("PyLuaTeX output: " .. resp.output)
+    end
+
     if resp.success or pyluatex.ignore_errors then
-        if pyluatex.verbose or not resp.success then log_output(resp.output) end
-
-        if write then
-            tex.print(output_lines)
-        end
+        if write then tex.print(output_lines) end
     else
-        if not pyluatex.verbose then log_input(full_code) end
-        log_output(resp.output)
-        if write then
-            tex.sprint(err_cmd("Python error (see above)"))
-        end
+        show_err("Python error (see above)")
     end
 
-    if resp.log_msg ~= "" then texio.write(resp.log_msg) end
-
-    return resp.success
+    if not_empty(resp.log_msg) then texio.write(resp.log_msg) end
 end
 
-function pyluatex.print_env()
-    if last_output ~= nil and (env_success or pyluatex.ignore_errors) then
-        tex.print(last_output)
-    end
+function pyluatex.execute_env(write, repl_mode)
+    local code = table.concat(env_lines, "\n")
+    pyluatex.execute(code, false, write, repl_mode, true)
 end
 
 local function record_line(line)
-    local s, e = line:find(env_end, 1, true)
+    local s = line:find(env_end)
     if s ~= nil then
         luatexbase.remove_from_callback("process_input_buffer", "pyluatex_record_line")
-        local code_in_line = line:sub(1, s - 1)
-        if trim(code_in_line):len() > 0 then
+        local code = line:sub(1, s - 1)
+        if code:strip():len() > 0 then
             -- only include this line if it contains non-whitespace characters
-            table.insert(env_lines, code_in_line)
+            table.insert(env_lines, code)
         end
-        local code = table.concat(env_lines, "\n")
-        env_success = pyluatex.execute(code, false, false, env_repl_mode, true)
-        if env_success or pyluatex.ignore_errors then
-            return line:sub(s)
-        else
-            return env_end .. err_cmd("Python error (see above)") .. line:sub(e + 1)
-        end
+        return line:sub(s)
     else
         table.insert(env_lines, line)
         return ""
@@ -212,14 +173,13 @@
     end
 end
 
-function pyluatex.record_env(name, repl_mode)
+function pyluatex.record_env(name)
     if parent_env ~= nil then
         name = parent_env
         parent_env = nil
     end
-    env_end = "\\end{" .. name .. "}"
+    env_end = "\\end%s*{" .. name:escapedpattern() .. "}"
     env_lines = {}
-    env_repl_mode = repl_mode
     luatexbase.add_to_callback("process_input_buffer", record_line, "pyluatex_record_line")
 end
 
@@ -236,13 +196,13 @@
         f:close()
         -- ignore trailing new line if present
         if code:sub(-2) == "\r\n" then
-            code = code:sub(0, -3)
+            code = code:sub(1, -3)
         elseif code:sub(-1) == "\n" then
-            code = code:sub(0, -2)
+            code = code:sub(1, -2)
         end
         pyluatex.execute(code, false, write, repl_mode, true)
     else
-        tex.sprint(err_cmd("File not found: " .. path))
+        show_err("File not found: " .. path)
     end
 end
 
@@ -255,26 +215,24 @@
 end
 
 local function parse_bool(name, value)
+    value = value:fullstrip()
     if value == "true" then
         return true
     elseif value == "false" then
         return false
     else
-        tex.sprint(
-            err_cmd("Invalid value '" .. value .. "' for option " .. name)
-        )
+        show_err('Invalid value "' .. value .. '" for option "' .. name .. '"')
     end
 end
 
 function pyluatex.set_option(name, value)
-    name = trim(name)
-    value = trim(value)
+    name = name:fullstrip()
     if name == "ignoreerrors" then
         pyluatex.ignore_errors = parse_bool(name, value)
     elseif name == "verbose" then
         pyluatex.verbose = parse_bool(name, value)
     else
-        tex.sprint(err_cmd("Unknown option '" .. name .. "'"))
+        show_err('Unknown option "' .. name .. '"')
     end
 end
 

Modified: trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty	2024-01-07 21:28:40 UTC (rev 69340)
+++ trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty	2024-01-07 21:28:53 UTC (rev 69341)
@@ -1,4 +1,4 @@
-%% Copyright 2021-2023 Tobias Enderle
+%% Copyright 2021-2024 Tobias Enderle
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3c
@@ -9,15 +9,15 @@
 %% version 2005/12/01 or later.
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2023/02/15 v0.6.1 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2024/01/07 v0.6.2 Execute Python code on the fly]
 
 \RequirePackage{expl3}
 \ExplSyntaxOn
-\sys_if_engine_luatex:TF{}{
+\sys_if_engine_luatex:F{
     \PackageError{PyLuaTeX}{LuaTeX~is~required}{}
 }
-\sys_if_shell_unrestricted:TF{}{
-    \PackageError{PyLuaTeX}{Shell~escape~required~(add~-shell-escape~option)}{}
+\sys_if_shell_unrestricted:F{
+    \PackageError{PyLuaTeX}{Shell~escape~is~required~(add~--shell-escape~option)}{}
 }
 \ExplSyntaxOff
 
@@ -31,40 +31,32 @@
 \DeclareStringOption[veryveryend]{shutdown}
 \ProcessKeyvalOptions*
 
-\directlua{pyluatex.ignore_errors = \ifpyluatex at ignoreerrors true\else false\fi}
-\directlua{pyluatex.verbose = \ifpyluatex at verbose true\else false\fi}
-\directlua{pyluatex.start(
-    [==[\pyluatex at executable]==],
-    \ifpyluatex at localimports true\else false\fi
-)}
+\newcommand*{\pyluatex at boolopt}[1]{\csname ifpyluatex@#1\endcsname true\else false\fi}
 
+\directlua{pyluatex.ignore_errors = \pyluatex at boolopt{ignoreerrors}}
+\directlua{pyluatex.verbose = \pyluatex at boolopt{verbose}}
+\directlua{pyluatex.start([==[\pyluatex at executable]==], \pyluatex at boolopt{localimports})}
+
 \ExplSyntaxOn
-\cs_generate_variant:Nn \tl_if_eq:nnTF { V }
-\tl_if_eq:VnTF{\pyluatex at shutdown}{veryveryend}{
-    \RequirePackage{atveryend}
-    \AtVeryVeryEnd{\directlua{pyluatex.shutdown()}}
-}{
-    \tl_if_eq:VnTF{\pyluatex at shutdown}{veryenddocument}{
-        \RequirePackage{atveryend}
-        \AtVeryEndDocument{\directlua{pyluatex.shutdown()}}
-    }{
-        \tl_if_eq:VnTF{\pyluatex at shutdown}{off}{}{
-            \PackageError{PyLuaTeX}{
-                Invalid~value~for~package~option~"shutdown":~\pyluatex at shutdown
-            }{}
-        }
-    }
-}
+\str_case_e:nnF{\pyluatex at shutdown}{
+    {veryveryend}{
+        \AddToHook{enddocument/end}{\directlua{pyluatex.shutdown()}}
+    }{veryenddocument}{
+        \AddToHook{enddocument/afteraux}{\directlua{pyluatex.shutdown()}}
+    }{off}{}
+}{\PackageError{PyLuaTeX}{Invalid~value~for~package~option~"shutdown":~\pyluatex at shutdown}{}}
 \ExplSyntaxOff
 
 \newcommand*{\PyLTVerbatimEnv}{\directlua{pyluatex.set_parent_env([==[\@currenvir]==])}}
 
-\newenvironment{python}{\directlua{pyluatex.record_env("python", false)}}
-{\directlua{pyluatex.print_env()}}
+\newenvironment{python}{\directlua{pyluatex.record_env("python")}}
+{\directlua{pyluatex.execute_env(true, false)}}
 
-\newenvironment{pythonq}{\directlua{pyluatex.record_env("pythonq", false)}}{}
+\newenvironment{pythonq}{\directlua{pyluatex.record_env("pythonq")}}
+{\directlua{pyluatex.execute_env(false, false)}}
 
-\newenvironment{pythonrepl}{\directlua{pyluatex.record_env("pythonrepl", true)}}{}
+\newenvironment{pythonrepl}{\directlua{pyluatex.record_env("pythonrepl")}}
+{\directlua{pyluatex.execute_env(false, true)}}
 
 \newcommand*{\pyluatex at inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3, false, true)}}
 



More information about the tex-live-commits mailing list.