bugtex4ht - Bugs: bug #310, Need automated way to prevent...

Show feedback again

You are not allowed to post comments on this tracker with your current authentification level.

bug #310: Need automated way to prevent duplicate files when using -d option

Submitted by:  Nasser M. Abbasi <nma123>
Submitted on:  Sun Jun 5 04:06:10 2016  
Category: NonePriority: 5 - Normal
Severity: 3 - MinorStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Closed

Fri Jul 17 15:57:59 2020, comment #2:

It doesn't seem like a good idea to delete any generated files automatically, so the post-processing script from my previous message is probably still the best solution.

Michal Hoftich <michal_h21>
Project Member
Wed Jun 8 12:20:18 2016, comment #1:

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"

lg_file = lg_file:gsub("tex$","lg")
if not lg_file:match "lg$" then
lg_file = lg_file ..".lg"

local removed_extensions = {}
for ext in patterns:gmatch("([^,]+)") do
removed_extensions[ext] = true

function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end

local current_dir = lfs.currentdir()
local remove = function(filename)
local removed = current_dir .."/" .. filename
if file_exists(removed) then
print("Removing", removed)

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

for _, v in ipairs(files) do
local ext = v:match "([^%.]+)$"
if removed_extensions[ext] then
for _,v in ipairs(images) do


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.

Michal Hoftich <michal_h21>
Project Member
Sun Jun 5 04:06:10 2016, original submission:

I've posted this before about this issue here http://tug.org/pipermail/tex4ht/2016q2/001474.html and thought will be good idea to enter it as bug so to remember it and record it.

When building with -d <folder_name>, as in

make4ht foo.tex -d some_folder


(or using htlatex), what happens is this: all the files generated during the build, the html files and the small image files (one for each math expression) are first generated in the current folder (where the latex file is), then at the end they are copied to the destination folder.

So one ends up with 1000's of duplicate small files (.htm and many .png or .svg, which are used for the math) in two places.

Here is MWE, say one is in /home/A/ folder:


compile with

make4ht foo.tex -d foo

Now there will copy of foo0x.png and foo.htm and foo.css in both A/* (where the latex file was) and also in A/foo/*

It will be nice to have the build or some automated command to safely remove the duplicated files that are generated during the build only from the current folder when using -d option.

TL 2015

Nasser M. Abbasi <nma123>


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by michal_h21 (Posted a comment)
  • -unavailable- added by nma123 (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    1 latest change follows.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri Jul 17 15:57:59 2020michal_h21Open/ClosedOpen=>Closed
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup+gray