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

Nasser M. Abbasi nma at 12000.org
Sat Apr 23 00:27:08 CEST 2022


On 4/19/2022 4:30 AM, Michal Hoftich wrote:
> 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

Hello Michal;

Just a clarification. I now trying using your build file above to optimize
the number of times tex4ht is called.

Do I need to also add

\Preamble{xhtml}
\typeout{(\jobname.4tc)}
\begin{document}
\EndPreamble

to my .cfg? or is this above for use with the other method you showed
which is using latexml?

So if I just want to use the above build file, is it enough to just
load it using -e  build_file.mk4   where build_file.mk4 is what you
show above or do I need to do something more to my .cfg?

btw, when I try the above on a simple file, it calls
tex4ht twice starting from clean folder. I assume this is normal?
i.e. from clean folder:

--------------------------
cat report.tex
\documentclass[11pt]{book}
\begin{document}

test
\end{document}
-------------------

and now

----------------------------
make4ht  --shell-escape -ulm default -a debug
      -c nma_mathjax.cfg
      --build-file $TEXMFHOME/tex/latex/tex4ht_build_files/MAIN.mk4
       report.tex
       "mathjax,htm,fn-in,1,notoc*,p-width,charset=utf-8" "-cunihtf -utf8" "" "--interaction=batchmode"
---------------

Shows it calls dvilualatex twice

[INFO]    htlatex: LaTeX call: dvilualatex --interaction=errorstopmode -jobname='report'  --interaction=batchmode -shell-escape '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\AddToHook{class/before}{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode nma_mathjax.cfg,mathjax,htm,fn-in,1,notoc*,p-width,charset=utf-8,charset=utf-8,html5.a.b.c.\input "\detokenize{report.tex}"'
This is LuaTeX, Version 1.15.0 (TeX Live 2022)
  system commands enabled.

[INFO]    htlatex: LaTeX call: dvilualatex --interaction=errorstopmode -jobname='report'

--interaction=batchmode -shell-escape '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\AddToHook{class/before}{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode nma_mathjax.cfg,mathjax,htm,fn-in,1,notoc*,p-width,charset=utf-8,charset=utf-8,html5.a.b.c.\input "\detokenize{report.tex}"'
This is LuaTeX, Version 1.15.0 (TeX Live 2022)
  system commands enabled.

.....
[STATUS]  make4ht: Conversion finished

Is the above expected? why 2 times on this simple file?

But when now I use the same command again, but do not
clear the folder and keep all intermediate files generated from earlier
command, it now calls dvilualatex one time only and not 2 times.

Just wanted to make sure this is all what is expected as I want
to use this in my main makefiles.

Thank you,

--Nasser






More information about the tex4ht mailing list.