summaryrefslogtreecommitdiff
path: root/support/make4ht/mkparams.lua
diff options
context:
space:
mode:
Diffstat (limited to 'support/make4ht/mkparams.lua')
-rw-r--r--support/make4ht/mkparams.lua134
1 files changed, 90 insertions, 44 deletions
diff --git a/support/make4ht/mkparams.lua b/support/make4ht/mkparams.lua
index 4db967f270..eff8c99670 100644
--- a/support/make4ht/mkparams.lua
+++ b/support/make4ht/mkparams.lua
@@ -1,6 +1,7 @@
local lapp = require "lapp-mk4"
local mkutils = require "mkutils"
local m = {} -- use ugly module system for new lua versions support
+local log = logging.new "mkparams"
-- these two variables will be used in the version number
-- progname will be set in get_args
@@ -9,25 +10,28 @@ m.progname = "make4ht"
m.version_number = "v0.1"
m.optiontext = [[
-${progname} - build system for tex4ht
+${progname} - build system for TeX4ht
Usage:
${progname} [options] filename ["tex4ht.sty op."] ["tex4ht op."] ["t4ht op"] ["latex op"]
Available options:
+ -a,--loglevel (default status) Set log level.
+ possible values: debug, info, status, warning, error, fatal
-b,--backend (default tex4ht) Backend used for xml generation.
possible values: tex4ht or lua4ht
-c,--config (default xhtml) Custom config file
-d,--output-dir (default nil) Output directory
-e,--build-file (default nil) If build file is different than `filename`.mk4
-f,--format (default html5) Output file format
- -h,-- help Display this message
+ -h,--help Display this message
+ -j,--jobname (default nil) Set the jobname
-l,--lua Use lualatex for document compilation
-m,--mode (default default) Switch which can be used in the makefile
- -n,--no-tex4ht Disable dvi file processing with tex4ht command
+ -n,--no-tex4ht Disable dvi file processing with the tex4ht command
-s,--shell-escape Enables running external programs from LaTeX
-u,--utf8 For output documents in utf8 encoding
- -x,--xetex Use xelatex for document compilation
-v,--version Display version number
+ -x,--xetex Use xelatex for document compilation
]]
-- test if the current command line argument should be passed to tex4ht, t4ht or latex
@@ -36,11 +40,12 @@ local function is_escapedargument(arg)
local ignored_options = {["-h"]=true, ["--help"]=true, ["-v"] = true, ["--version"]=true}
if ignored_options[arg] then return false end
-- in other cases, match if the argument starts with "-" character
- return arg:match("^%-")
+ return arg:match("^%-.+")
end
local function get_args(parameters, optiontext)
local parameters = parameters or {}
parameters.progname = parameters.progname or "make4ht"
+ parameters.issue_tracker = parameters.issue_tracker or "https://github.com/michal-h21/make4ht/issues"
parameters.postparams = parameters.postparams or ""
local optiontext = optiontext or m.optiontext
parameters.postfile = parameters.postfile or ""
@@ -54,7 +59,7 @@ Positional optional argumens:
Documentation: https://tug.org/applications/tex4ht/mn.html
Issue tracker for tex4ht bugs: https://puszcza.gnu.org.ua/bugs/?group=tex4ht
-Issue tracker for make4ht bugs: https://github.com/michal-h21/make4ht/issues
+Issue tracker for ${progname} bugs: ${issue_tracker}
]] .. parameters.postfile
-- we can pass arguments for tex4ht and t4ht after filename, but it will confuse lapp, thinking that these
-- options are for make4ht. this may result in execution error or wrong option parsing
@@ -88,6 +93,61 @@ local function get_format_extensions(format_string)
return format, extensions
end
+-- detect if user specified -jobname in arguments to the TeX engine
+-- or used the --jobname option for make4ht
+local function handle_jobname(input, args)
+ -- parameters to the TeX engine
+ local latex_params = {}
+ local latex_cli_params = args[4] or ""
+ -- use the jobname as input name if it is specified
+ local jobname = args.jobname ~="nil" and args.jobname or nil
+ if jobname or not latex_cli_params:match("%-jobname") then
+ -- prefer jobname over input
+ input = jobname or input
+ -- we must strip out directories from jobname when full path to document is given
+ input = input:match("([^%/^%\\]+)$")
+ -- input also cannot contain spaces, replace them with underscores
+ input = input:gsub("%s", "_")
+ table.insert(latex_params,"-jobname="..input)
+ else
+ -- when user specifies -jobname, we must change name of the input file,
+ -- in order to be able to process correct dvi file with tex4ht and t4ht
+ local newinput
+ -- first contains quotation character or first character of the name
+ local first, rest = latex_cli_params:match("%-jobname%s*=?%s*(.)(.*)")
+ if first=='"' then
+ newinput=rest:match('([^"]+)')
+ elseif first=="'" then
+ newinput=rest:match("([^']+)")
+ elseif type(first)== "string" then
+ -- if the jobname is unquoted, it cannot contain space
+ -- join the first character and rest
+ rest = first.. rest
+ newinput = rest:match("([^ ]+)")
+ end
+ if newinput then
+ input = newinput
+ end
+ end
+ --
+ table.insert(latex_params, latex_cli_params)
+ return latex_params, input
+end
+
+-- use standard input instead of file if the filename is just `-`
+-- return the filename and status if it is a tmp name
+local function handle_input_file(filename)
+ -- return the original file name if it isn't just dash
+ if filename ~= "-" then return filename, false end
+ -- generate the temporary name. the added extension is important
+ local tmp_name = os.tmpname()
+ local contents = io.read("*all")
+ local f = io.open(tmp_name, "w")
+ f:write(contents)
+ f:close()
+ return tmp_name, true
+end
+
local function process_args(args)
local function get_inserter(args,tb)
return function(key, value)
@@ -98,6 +158,14 @@ local function process_args(args)
end
end
+ -- set error log level
+ logging.set_level(args.loglevel)
+ -- the default LaTeX --interaction parameter
+ local interaction = "batchmode"
+ if args.loglevel == "debug" then
+ interaction = "errorstopmode"
+ end
+
if args.version ==true then
print(string.format("%s version %s", m.progname, m.version_number))
os.exit()
@@ -122,36 +190,12 @@ local function process_args(args)
local compiler = args.lua and "dvilualatex" or args.xetex and "xelatex --no-pdf" or "latex"
- local tex_file = args.filename
- local input = mkutils.remove_extension(args.filename)
- local latex_params = {}
+ local tex_file, is_tmp_file = handle_input_file(args.filename)
+ local input = mkutils.remove_extension(tex_file)
+ -- the output file name can be influneced using -jobname parameter passed to the TeX engine
+ local latex_params, input = handle_jobname(input, args)
local insert_latex = get_inserter(args,latex_params)
insert_latex("shell-escape","-shell-escape")
- local latex_cli_params = args[4] or ""
- if not latex_cli_params:match("%-jobname") then
- -- we must strip out directories from jobname when full path to document is given
- input = input:match("([^%/^%\\]+)$")
- -- input also cannot contain spaces, replace them with underscores
- input = input:gsub("%s", "_")
- table.insert(latex_params,"-jobname="..input)
- else
- -- when user specifies -jobname, we must change name of the input file,
- -- in order to be able to process correct dvi file with tex4ht and t4ht
- local newinput
- local first, rest = latex_cli_params:match("%-jobname=(.)(.*)")
- if first=='"' then
- newinput=rest:match('([^"]+)')
- elseif first=="'" then
- newinput=rest:match("([^']+)")
- elseif type(first)== "string" then
- rest = first.. rest
- newinput = rest:match("([^ ]+)")
- end
- if newinput then
- input = newinput
- end
- end
- table.insert(latex_params, latex_cli_params)
--table.insert(latex_params,args["shell-escape"] and "-shell-escape")
@@ -181,9 +225,9 @@ local function process_args(args)
tex4ht = args[2]
else
tex4ht = args.utf8 and " -cmozhtf -utf8" or ""
- if args.xetex then tex4ht = tex4ht .. " -.xdv" end
- -- tex4ht = tex4ht .. xdv
end
+ -- set the correct extension for tex4ht if xetex is used
+ if args.xetex then tex4ht = tex4ht .. " -.xdv" end
local t4ht = args[3] or ""
@@ -215,19 +259,21 @@ local function process_args(args)
,build_file = build_file
,output_format = outformat
,extensions = extensions
+ ,is_tmp_file = is_tmp_file
+ ,interaction = interaction
--,t4ht_dir_format=t4ht_dir_format
}
if outdir then parameters.outdir = outdir end
- print("Output dir: ",outdir)
- print("Compiler: ", compiler)
- print("Latex options: ", table.concat(latex_params," "))
- print("tex4ht.sty :",t4sty)
- print("tex4ht",tex4ht)
- print("build_file", build_file)
+ log:info("Output dir: "..outdir)
+ log:info("Compiler: "..compiler)
+ log:info("Latex options: ".. table.concat(latex_params," "))
+ log:info("tex4ht.sty: "..t4sty)
+ log:info("tex4ht: "..tex4ht)
+ log:info("build_file: ".. build_file)
if outformat~="nil" then
- print("Output format", outformat)
+ log:info("Output format: ".. outformat)
for _, ex in ipairs(extensions) do
- print("Extension", ex.type .. ex.name)
+ log:info("Extension: ".. ex.type .. ex.name)
end
end
return parameters