[tex4ht] How to control/optimize the number of times make4ht runs dvilualatex?

Michal Hoftich michal.h21 at gmail.com
Tue Apr 19 11:30:45 CEST 2022


Hi Nasser

>
> Thanks, but the issue is, how does one know if they
> need to run it 1, 2 or 3 times? What code do I need to add
> to the above to decide?
> With lualatex, now this is what I do and it works (other option is to
> use latexmk, but for some other reasons, I prefer to stick to makefiles
> for now).
>

One possibility is to use the latexmk_build extension, like in:

      make4ht -f html5+latexmk_build sample.tex

Another option is to check temporary files for changes. Using some
hash function. Like in this build file:

--------------------
local htlatex = require "make4ht-htlatex"

local function get_checksum(main_file, extensions)
  -- make checksum for temporary files
  local checksum = ""
  local extensions = extensions or {"aux", "4tc", "xref"}
  for _, ext in ipairs(extensions) do
    local f = io.open(main_file .. "." .. ext, "r")
    if f then
      local content = f:read("*all")
      f:close()
      -- make checksum of the file and previous checksum
      -- this way, we will detect change in any file
      checksum = md5.sumhexa(checksum .. content)
    end
  end
  return checksum
end

Make:add("myhtlatex", function(par)
  -- get checksum of temp files before compilation
  local checksum = get_checksum(par.input)
  local status = htlatex.htlatex(par)
  -- stop processing on error
  if status ~= 0 then return status end
  -- get checksum after compilation
  local newchecksum = get_checksum(par.input)
  -- this is needed to prevent possible infinite loops
  local compilation_count = 1
  local max_compilations  = 3 -- <- change as you want
  while checksum ~= newchecksum do
    --
    if compilation_count > max_compilations then return status end
    status = htlatex.htlatex(par)
    -- stop processing on error
    if status ~= 0 then return status end
    checksum = newchecksum
    -- get checksum after compilation
    newchecksum = get_checksum(par.input)
  end
  return status
end)

Make:myhtlatex {}
-----------------------------

Best regards,
Michal


More information about the tex4ht mailing list.