From 37dfda47fe844c888a24fb8cc380d34139dca9f4 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 28 Apr 2017 21:21:37 +0000 Subject: tex4ebook (28apr17) git-svn-id: svn://tug.org/texlive/trunk@44103 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/tex4ebook/exec_epub.lua | 52 +++++++++++++++------- Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua | 1 + Master/texmf-dist/scripts/tex4ebook/tex4ebook | 5 +-- 3 files changed, 40 insertions(+), 18 deletions(-) (limited to 'Master/texmf-dist/scripts/tex4ebook') diff --git a/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua b/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua index ff5784bcdb3..1311516bfb6 100755 --- a/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua +++ b/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua @@ -133,6 +133,8 @@ function make_opf() local dir_part = item:split("/") table.remove(dir_part,#dir_part) local id=table.concat(dir_part,"-")..fname.."_"..ext + -- remove invalid characters from id start + id = id:gsub("^[%.%-]*","") return "",id end local find_all_files= function(s,r) @@ -161,13 +163,22 @@ function make_opf() local opf_complete = {} table.insert(opf_complete,h_first:read("*all")) local used_html = find_all_files(opf_complete[1]) - local lg_file = ebookutils.parse_lg(outputfilename..".lg") - local used_files = lg_file["files"] + -- local lg_file = ebookutils.parse_lg(outputfilename..".lg") + -- The lg_file has been already loaded by make4ht, it doesn't make sense to load it again + -- Furthermore, it is now possible to add new files from Lua build files + local lg_file = Make.lgfile or ebookutils.parse_lg(outputfilename..".lg") + local used_files = {} + for _,filename in ipairs(lg_file["files"]) do + -- we need to test the filenames in order to prevent duplicates + -- filenames are tested without paths, so there may be issues if + -- the same filename is used in different directories. Is that a problem? + used_files[filename] = true + end --[[for f in lfs.dir("./OEBPS") do --table.insert(used_files,f) --used_files[f] = true end--]] - local all_html = find_all_files(table.concat(used_files,"\n")) + -- local all_html = find_all_files(table.concat(used_files,"\n")) local outside_spine = {} -- This was duplicated code --[[for i, ext in pairs(all_html) do @@ -180,6 +191,7 @@ function make_opf() end--]] local all_used_files = find_all_files(opf_complete[1],"([%a%d%-%_]+%.[%a%d]+)") local used_paths = {} + local used_ids = {} for _,k in ipairs(lg_file["files"]) do local ext = k:match("%.([%a%d]*)$") local parts = k:split "/" @@ -188,11 +200,11 @@ function make_opf() table.remove(parts,#parts) --table.insert(parts,1,"OEBPS") table.insert(parts,1,outputdir) - --print("SSSSS "..fn.." ext .." .. ext) + -- print("SSSSS "..fn.." ext .." .. ext) --if string.find("jpg gif png", ext) and not all_used_files[k] then local item,id = lg_item(k) if item then - local path = table.concat(parts) + local path = table.concat(parts) if not used_paths[path] then ebookutils.mkdirectories(parts) used_paths[path]=true @@ -206,20 +218,28 @@ function make_opf() print "Tidy: Cannot load tidyconf.conf" end end - ebookutils.copy(k, outputdir .. "/"..k) - if not all_used_files[fn] then - table.insert(opf_complete,item) - if allow_in_spine[ext] then - table.insert(outside_spine,id) - end + if not used_ids[id] then + ebookutils.copy(k, outputdir .. "/"..k) + if not all_used_files[fn] then + table.insert(opf_complete,item) + if allow_in_spine[ext] then + table.insert(outside_spine,id) + end + end end + used_ids[id] = true end end for _,f in ipairs(lg_file["images"]) do local f = f.output - local p = lg_item(f) - ebookutils.copy(f, outputdir .. "/"..f) - table.insert(opf_complete,p) + local p, id = lg_item(f) + -- process the images only if they weren't registered in lg_file["files"] + -- they would be processed twice otherwise + if not used_files[f] and not used_ids[id] then + ebookutils.copy(f, outputdir .. "/"..f) + table.insert(opf_complete,p) + end + used_ids[id] = true end local end_opf = h_second:read("*all") local spine_items = {} @@ -283,6 +303,8 @@ function make_opf() end print(mimetype) local zip = find_zip() + -- we need to remove the epub file if it exists already, because it may contain files which aren't used anymore + if ebookutils.file_exists(outputfile) then os.remove(outputfile) end print("Pack mimetype " .. os.execute("cd "..basedir.." && "..zip.." -q0X "..outputfile .." ".. mimetype_name)) print("Pack metadir " .. os.execute("cd "..basedir.." && "..zip.." -qXr9D " .. outputfile.." "..metadir_name)) print("Pack outputdir " .. os.execute("cd "..basedir.." && "..zip.." -qXr9D " .. outputfile.." "..outputdir_name)) @@ -309,4 +331,4 @@ end --deldir(outputdir) --deldir(metadir) --os.remove(mimetype) - end +end diff --git a/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua b/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua index e51746e7773..eb829284b59 100755 --- a/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua +++ b/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua @@ -10,6 +10,7 @@ function prepare(params) outputdir= basedir.."/"..outputdir_name input = params.input params.ext = ext + params.tex4ht_sty_par = params.tex4ht_sty_par .. ",html5" params.packages = params.packages .. string.format("\\Configure{ext}{%s}",ext) return eb.prepare(params) end diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook b/Master/texmf-dist/scripts/tex4ebook/tex4ebook index b305c806c57..5c9f65573f7 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook @@ -52,12 +52,11 @@ else end if args.version then - print "tex4ebook version 0.1d" + print "tex4ebook v0.1e" return end if args.lua then - print("Mame lua") latex_cmd="dvilualatex" end @@ -167,7 +166,7 @@ if args["build-file"] and args["build-file"] ~= "nil" then build_file = args["build-file"] end -local config_file = ebookutils.load_config(nil, build_file) +local config_file = ebookutils.load_config(params, build_file) params["config_file"] = config_file --config_file.Make:run() -- cgit v1.2.3