summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/pyluatex/pyluatex.sty
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/latex/pyluatex/pyluatex.sty')
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.sty28
1 files changed, 24 insertions, 4 deletions
diff --git a/macros/luatex/latex/pyluatex/pyluatex.sty b/macros/luatex/latex/pyluatex/pyluatex.sty
index ab015d9638..cf67916d19 100644
--- a/macros/luatex/latex/pyluatex/pyluatex.sty
+++ b/macros/luatex/latex/pyluatex/pyluatex.sty
@@ -1,4 +1,4 @@
-%% Copyright 2021 Tobias Enderle
+%% Copyright 2021-2022 Tobias Enderle
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
@@ -9,15 +9,15 @@
%% version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2021/11/05 v0.4.0 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2022/02/04 v0.4.1 Execute Python code on the fly]
\RequirePackage{expl3}
\ExplSyntaxOn
\sys_if_engine_luatex:TF{}{%
-\PackageError{PyLuaTeX}{LuaTeX~is~required}{}%
+ \PackageError{PyLuaTeX}{LuaTeX~is~required}{}%
}
\sys_if_shell_unrestricted:TF{}{%
-\PackageError{PyLuaTeX}{Shell~escape~required~(add~-shell-escape~option)}{}%
+ \PackageError{PyLuaTeX}{Shell~escape~required~(add~-shell-escape~option)}{}%
}
\ExplSyntaxOff
@@ -27,6 +27,7 @@
\DeclareStringOption[python3]{executable}
\DeclareBoolOption{ignoreerrors}
\DeclareBoolOption{verbose}
+\DeclareStringOption[veryveryend]{shutdown}
\ProcessKeyvalOptions*
\ifpyluatex@ignoreerrors
@@ -41,6 +42,25 @@
\fi
\directlua{pyluatex.start([==[\pyluatex@executable]==])}
+\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
+ }{}%
+ }
+ }
+}
+\ExplSyntaxOff
+
\newcommand*{\PyLTVerbatimEnv}{\directlua{pyluatex.set_parent_env([==[\@currenvir]==])}}
\newenvironment{python}{\directlua{pyluatex.record_env("python", false)}}%