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

Wojciech Myszka wojciech.myszka at gmail.com
Tue Apr 19 16:29:06 CEST 2022


Well‚

Even in the simplest possible case, when the input file is as simple as:

\documentclass{article}
\begin{document}
aaa
\end{document}

“standard” make4ht makes three runs of latex on an input file on each run.

Adding latexmk gives *five* runs of latex during the first run of a make4ht

Even not introducing any changes to input (in an ideal word no run of latex
is needed) we got *4 (four)* runs of latex. Looking into logs from latexmk
in the first run (“Changed files, or newly in use[…}”) we got for the run
number

   1. a.tex
   2. a.aux, a.tmp
   3. a.xref

During the second run, we got

   1. a.tmp
   2. a.tmp

This means that after each run of latex checksum for the file a.tmp changes.

 Best regards

Wojtek

wt., 19 kwi 2022 o 11:31 Michal Hoftich <michal.h21 at gmail.com> napisał(a):

> 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
>


-- 
---(___C'>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/tex4ht/attachments/20220419/4733925a/attachment.html>


More information about the tex4ht mailing list.