<div dir="ltr"><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Well‚</p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Even in the simplest possible case, when the input file is as simple as:</p><pre style="color:rgb(0,0,0)"><code class="gmail-language-latex" lang="latex">\documentclass{article}
\begin{document}
aaa
\end{document}
</code></pre><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">“standard” make4ht makes three runs of latex on an input file on each run.</p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Adding latexmk gives <em>five</em> runs of latex during the first run of a make4ht</p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Even not introducing any changes to input (in an ideal word no run of latex is needed) we got <strong>4 (four)</strong> runs of latex. Looking into logs from latexmk in the first run (“Changed files, or newly in use[…}”) we got for the run number</p><ol style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><li>a.tex</li><li>a.aux, a.tmp</li><li>a.xref</li></ol><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">During the second run, we got</p><ol style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><li>a.tmp</li><li>a.tmp</li></ol><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">This means that after each run of latex checksum for the file a.tmp changes.</p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> Best regards </p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Wojtek</p></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">wt., 19 kwi 2022 o 11:31 Michal Hoftich <<a href="mailto:michal.h21@gmail.com">michal.h21@gmail.com</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Nasser<br>
<br>
><br>
> Thanks, but the issue is, how does one know if they<br>
> need to run it 1, 2 or 3 times? What code do I need to add<br>
> to the above to decide?<br>
> With lualatex, now this is what I do and it works (other option is to<br>
> use latexmk, but for some other reasons, I prefer to stick to makefiles<br>
> for now).<br>
><br>
<br>
One possibility is to use the latexmk_build extension, like in:<br>
<br>
make4ht -f html5+latexmk_build sample.tex<br>
<br>
Another option is to check temporary files for changes. Using some<br>
hash function. Like in this build file:<br>
<br>
--------------------<br>
local htlatex = require "make4ht-htlatex"<br>
<br>
local function get_checksum(main_file, extensions)<br>
-- make checksum for temporary files<br>
local checksum = ""<br>
local extensions = extensions or {"aux", "4tc", "xref"}<br>
for _, ext in ipairs(extensions) do<br>
local f = io.open(main_file .. "." .. ext, "r")<br>
if f then<br>
local content = f:read("*all")<br>
f:close()<br>
-- make checksum of the file and previous checksum<br>
-- this way, we will detect change in any file<br>
checksum = md5.sumhexa(checksum .. content)<br>
end<br>
end<br>
return checksum<br>
end<br>
<br>
Make:add("myhtlatex", function(par)<br>
-- get checksum of temp files before compilation<br>
local checksum = get_checksum(par.input)<br>
local status = htlatex.htlatex(par)<br>
-- stop processing on error<br>
if status ~= 0 then return status end<br>
-- get checksum after compilation<br>
local newchecksum = get_checksum(par.input)<br>
-- this is needed to prevent possible infinite loops<br>
local compilation_count = 1<br>
local max_compilations = 3 -- <- change as you want<br>
while checksum ~= newchecksum do<br>
--<br>
if compilation_count > max_compilations then return status end<br>
status = htlatex.htlatex(par)<br>
-- stop processing on error<br>
if status ~= 0 then return status end<br>
checksum = newchecksum<br>
-- get checksum after compilation<br>
newchecksum = get_checksum(par.input)<br>
end<br>
return status<br>
end)<br>
<br>
Make:myhtlatex {}<br>
-----------------------------<br>
<br>
Best regards,<br>
Michal<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">---(___C'></div>