diff options
Diffstat (limited to 'macros/luatex/latex/pyluatex/pyluatex.sty')
-rw-r--r-- | macros/luatex/latex/pyluatex/pyluatex.sty | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/macros/luatex/latex/pyluatex/pyluatex.sty b/macros/luatex/latex/pyluatex/pyluatex.sty index 11b9261709..2b0575a830 100644 --- a/macros/luatex/latex/pyluatex/pyluatex.sty +++ b/macros/luatex/latex/pyluatex/pyluatex.sty @@ -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@ignoreerrors true\else false\fi} -\directlua{pyluatex.verbose = \ifpyluatex@verbose true\else false\fi} -\directlua{pyluatex.start( - [==[\pyluatex@executable]==], - \ifpyluatex@localimports true\else false\fi -)} +\newcommand*{\pyluatex@boolopt}[1]{\csname ifpyluatex@#1\endcsname true\else false\fi} + +\directlua{pyluatex.ignore_errors = \pyluatex@boolopt{ignoreerrors}} +\directlua{pyluatex.verbose = \pyluatex@boolopt{verbose}} +\directlua{pyluatex.start([==[\pyluatex@executable]==], \pyluatex@boolopt{localimports})} \ExplSyntaxOn -\cs_generate_variant:Nn \tl_if_eq:nnTF { V } -\tl_if_eq:VnTF{\pyluatex@shutdown}{veryveryend}{ - \RequirePackage{atveryend} - \AtVeryVeryEnd{\directlua{pyluatex.shutdown()}} -}{ - \tl_if_eq:VnTF{\pyluatex@shutdown}{veryenddocument}{ - \RequirePackage{atveryend} - \AtVeryEndDocument{\directlua{pyluatex.shutdown()}} - }{ - \tl_if_eq:VnTF{\pyluatex@shutdown}{off}{}{ - \PackageError{PyLuaTeX}{ - Invalid~value~for~package~option~"shutdown":~\pyluatex@shutdown - }{} - } - } -} +\str_case_e:nnF{\pyluatex@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@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@inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3, false, true)}} |