summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/make4ht/mkparams.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-04-09 21:09:51 +0000
committerKarl Berry <karl@freefriends.org>2018-04-09 21:09:51 +0000
commit4d2d4764dde3caf40817a1ef84719e1319b10d2f (patch)
tree096967b6679e1e110b75e42e1747936323508fc4 /Master/texmf-dist/scripts/make4ht/mkparams.lua
parent1e0147a88c7bc3a3e2986968f697ef5fbcef2bcb (diff)
make4ht (9apr18)
git-svn-id: svn://tug.org/texlive/trunk@47398 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/mkparams.lua')
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/mkparams.lua55
1 files changed, 53 insertions, 2 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/mkparams.lua b/Master/texmf-dist/scripts/make4ht/mkparams.lua
index 61c522a2406..f5df4849966 100755
--- a/Master/texmf-dist/scripts/make4ht/mkparams.lua
+++ b/Master/texmf-dist/scripts/make4ht/mkparams.lua
@@ -17,6 +17,7 @@ ${progname} [options] filename ["tex4ht.sty op." "tex4ht op." "t4ht op" "latex o
-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
-l,--lua Use lualatex for document compilation
-m,--mode (default default) Switch which can be used in the makefile
@@ -26,6 +27,15 @@ ${progname} [options] filename ["tex4ht.sty op." "tex4ht op." "t4ht op" "latex o
-x,--xetex Use xelatex for document compilation
-v,--version Display version number
]]
+
+-- test if the current command line argument should be passed to tex4ht, t4ht or latex
+local function is_escapedargument(arg)
+ -- we need to ignore make4ht options which can be used without filename, ie --version and --help
+ 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("^%-")
+end
local function get_args(parameters, optiontext)
local parameters = parameters or {}
parameters.progname = parameters.progname or "make4ht"
@@ -33,10 +43,37 @@ local function get_args(parameters, optiontext)
local optiontext = optiontext or m.optiontext
parameters.postfile = parameters.postfile or ""
optiontext = optiontext .. parameters.postparams .."<filename> (string) Input file name\n" .. 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
+ -- as fix, add a space before options at the end (we need to stop to add spaces as soon as we find
+ -- nonempty string which doesn't start with - it will be filename or tex4ht.sty options
+ if #arg > 1 then -- do this only if more than one argument is used
+ for i=#arg,1,-1 do
+ local current = arg[i]
+ if is_escapedargument(arg[i]) then
+ arg[i] = " ".. arg[i]
+ -- empty parameter
+ elseif current == "" then
+ else
+ break
+ end
+ end
+ end
--print("--------------\n" .. optiontext .."--------------\n")
return lapp(optiontext % parameters)
end
+--- get outptut file format and list of extensions from --format option string
+local function get_format_extensions(format_string)
+ local format, rest = format_string:match("^([a-zA-Z0-9]+)(.*)")
+ local extensions = {}
+ -- it is possible to pass only the extensions
+ rest = rest or format_string
+ rest:gsub("([%+%-])([^%+^%-]+)",function(typ, name)
+ table.insert(extensions, {type = typ, name = name})
+ end)
+ return format, extensions
+end
local function process_args(args)
local function get_inserter(args,tb)
@@ -80,7 +117,7 @@ local function process_args(args)
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 = input:match("([^%/^%\\]+)$")
table.insert(latex_params,"-jobname="..input)
else
-- when user specifies -jobname, we must change name of the input file,
@@ -140,9 +177,14 @@ local function process_args(args)
local build_file = input.. ".mk4"
if args["build-file"] and args["build-file"] ~= "nil" then
- build_file = args["build-file"]
+ build_file = args["build-file"]
end
+ local outformat, extensions
+ if args["format"] and arg["format"] ~= "nil" then
+ outformat, extensions = get_format_extensions(args["format"])
+ end
+
local parameters = {
htlatex = compiler
,input=input
@@ -156,6 +198,8 @@ local function process_args(args)
,mode = mode
,dvi = dvi
,build_file = build_file
+ ,output_format = outformat
+ ,extensions = extensions
--,t4ht_dir_format=t4ht_dir_format
}
if outdir then parameters.outdir = outdir end
@@ -165,8 +209,15 @@ local function process_args(args)
print("tex4ht.sty :",t4sty)
print("tex4ht",tex4ht)
print("build_file", build_file)
+ if outformat~="nil" then
+ print("Output format", outformat)
+ for _, ex in ipairs(extensions) do
+ print("Extension", ex.type .. ex.name)
+ end
+ end
return parameters
end
m.get_args = get_args
+m.get_format_extensions = get_format_extensions
m.process_args = process_args
return m