summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-06-05 21:02:04 +0000
committerKarl Berry <karl@freefriends.org>2022-06-05 21:02:04 +0000
commit80aa3b5de37b11d9f895cf844adcd9bb8fc127d2 (patch)
tree1453475e0f24bea856956c6326dfba3ceb01fc3a /Master/texmf-dist/tex/lualatex
parent4d435df3faff5acb9f1c0f0b94944c4285980c9e (diff)
pyluatex (5jun22)
git-svn-id: svn://tug.org/texlive/trunk@63491 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua15
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty11
2 files changed, 18 insertions, 8 deletions
diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
index efa80c75f41..0580d25a539 100644
--- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
+++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
@@ -141,7 +141,7 @@ local function split_lines(str)
return t
end
-function pyluatex.execute(code, auto_print, write, repl_mode)
+function pyluatex.execute(code, auto_print, write, repl_mode, store)
local full_code
if auto_print then
full_code = "print(str(" .. code .. "), end='')"
@@ -159,14 +159,17 @@ function pyluatex.execute(code, auto_print, write, repl_mode)
ignore_errors = pyluatex.ignore_errors
}
)
- last_code = split_lines(code)
- last_output = split_lines(output)
+ local output_lines = split_lines(output)
+ if store then
+ last_code = split_lines(code)
+ last_output = output_lines
+ end
if success or pyluatex.ignore_errors then
if pyluatex.verbose or not success then log_output(output) end
if write then
- tex.print(last_output)
+ tex.print(output_lines)
end
else
if not pyluatex.verbose then log_input(full_code) end
@@ -195,7 +198,7 @@ local function record_line(line)
table.insert(env_lines, code_in_line)
end
local code = table.concat(env_lines, "\n")
- local success = pyluatex.execute(code, false, false, env_repl_mode)
+ local success = pyluatex.execute(code, false, false, env_repl_mode, true)
if success or pyluatex.ignore_errors then
return line:sub(s)
else
@@ -235,7 +238,7 @@ function pyluatex.run_file(path, write, repl_mode)
elseif code:sub(-1) == "\n" then
code = code:sub(0, -2)
end
- pyluatex.execute(code, false, write, repl_mode)
+ pyluatex.execute(code, false, write, repl_mode, true)
else
tex.sprint(err_cmd("File not found: " .. path))
end
diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
index 4d8325c8078..6e287e51000 100644
--- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
+++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
@@ -9,7 +9,7 @@
%% version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2022/03/16 v0.4.4 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2022/06/05 v0.5.0 Execute Python code on the fly]
\RequirePackage{expl3}
\ExplSyntaxOn
@@ -66,7 +66,7 @@
\newenvironment{pythonrepl}{\directlua{pyluatex.record_env("pythonrepl", true)}}{}
-\newcommand*{\pyluatex@inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3, false)}}
+\newcommand*{\pyluatex@inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3, false, true)}}
\newcommand*{\py}[1]{\pyluatex@inline{#1}{true}{true}}
\newcommand*{\pyq}[1]{\pyluatex@inline{#1}{true}{false}}
@@ -81,4 +81,11 @@
\newcommand*{\pyfileq}[1]{\directlua{pyluatex.run_file([==[#1]==], false, false)}}
\newcommand*{\pyfilerepl}[1]{\directlua{pyluatex.run_file([==[#1]==], false, true)}}
+\newcommand*{\pyif}[1]{%
+ \ifnum1=\directlua{pyluatex.execute([==['1' if (#1) else '0']==], true, true, false, false)}\relax
+ \expandafter\@firstoftwo
+ \else
+ \expandafter\@secondoftwo
+ \fi}
+
\endinput