[tex4ht] [bug #310] Need automated way to prevent duplicate files when using -d option
Michal Hoftich
michal.h21 at gmail.com
Wed Jun 8 14:20:18 CEST 2016
Follow-up Comment #1, bug #310 (project tex4ht):
You can use the following script in your build file:
-------
kpse.set_program_name "luatex"
local lg_file = arg[1]
-- list of removed extensions
local patterns = arg[2] or "html,css"
if not lg_file then
print "No input file"
os.exit()
end
lg_file = lg_file:gsub("tex$","lg")
if not lg_file:match "lg$" then
lg_file = lg_file ..".lg"
end
local removed_extensions = {}
for ext in patterns:gmatch("([^,]+)") do
removed_extensions[ext] = true
end
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
local current_dir = lfs.currentdir()
local remove = function(filename)
local removed = current_dir .."/" .. filename
if file_exists(removed) then
print("Removing", removed)
os.remove(removed)
end
end
local files = {}
local images = {}
local file_pattern = "File: (.*)"
local image_pattern = "--- needs --- .-==> ([^%s]+) ---"
for line in io.lines(lg_file) do
local file_match = line:match(file_pattern)
local image_match = line:match(image_pattern)
files[#files + 1] = file_match
images[#images + 1] = image_match
end
for _, v in ipairs(files) do
local ext = v:match "([^%.]+)$"
if removed_extensions[ext] then
remove(v)
end
end
for _,v in ipairs(images) do
remove(v)
end
------
you can call it with command
texlua removefiles.lua texfilename "listofremovedextensions"
list of removed extensions isn't necessary, it removes html and css files by
default. and of course images generated from the DVI file.
_______________________________________________________
Reply to this item at:
<http://puszcza.gnu.org.ua/bugs/?310>
_______________________________________________
Message sent via/by Puszcza
http://puszcza.gnu.org.ua/
More information about the tex4ht
mailing list