summaryrefslogtreecommitdiff
path: root/support/make4ht/extensions/make4ht-ext-preprocess_input.lua
diff options
context:
space:
mode:
Diffstat (limited to 'support/make4ht/extensions/make4ht-ext-preprocess_input.lua')
-rw-r--r--support/make4ht/extensions/make4ht-ext-preprocess_input.lua21
1 files changed, 18 insertions, 3 deletions
diff --git a/support/make4ht/extensions/make4ht-ext-preprocess_input.lua b/support/make4ht/extensions/make4ht-ext-preprocess_input.lua
index 306c7bf772..763c25ea7e 100644
--- a/support/make4ht/extensions/make4ht-ext-preprocess_input.lua
+++ b/support/make4ht/extensions/make4ht-ext-preprocess_input.lua
@@ -6,7 +6,7 @@ local mkutils = require "mkutils"
local commands = {
knitr = { command = 'Rscript -e "library(knitr); knit(\'${tex_file}\', output=\'${tmp_file}\')"'},
pandoc = { command = 'pandoc -f ${input_format} -s -o \'${tmp_file}\' -t latex \'${tex_file}\''},
- render = { command = 'Rscript -e "library(rmarkdown); render(\'${tex_file}\', output_file=\'${tmp_file}\')"'}
+ render = { command = 'Rscript -e "library(rmarkdown); render(\'${tex_file}\', output_file=\'${tmp_file}\',output_format = \'latex_document\')"'}
}
local filetypes = {
rnw = {sequence = {"knitr"} },
@@ -17,6 +17,21 @@ local filetypes = {
rst = {sequence = {"pandoc"}, options = {input_format = "rst"}},
}
+local function get_temp_name(arg,curr, length)
+ -- we don't want to use the temp dir, because graphics would be then generated outside of
+ -- the directory of the source document. so we will make
+ local tmp_name = os.tmpname()
+ if pos == sequence then
+ -- base tmp_name on the input name in the last step of sequence
+ -- so the generated images won't have random names
+ tmp_name = arg.input .. "-preprocess_input"
+ else
+ tmp_name = tmp_name:match("([^/\\]+)$")
+ end
+ return tmp_name
+end
+
+
local function execute_sequence(sequence, arg, make)
-- keep track of all generated tmp files
@@ -25,8 +40,8 @@ local function execute_sequence(sequence, arg, make)
-- should become the tex_file for the next one. It doesn't
-- matter that it isn't TeX file in some cases
local previous_temp
- for _, cmd_name in ipairs(sequence) do
- local tmp_name = os.tmpname()
+ for pos, cmd_name in ipairs(sequence) do
+ local tmp_name = get_temp_name(arg,pos, #sequence)
temp_files[#temp_files+1] = tmp_name
-- make the temp file name accessible to the executed commands
arg.tmp_file = tmp_name