It's being suggested make4ht can replace the functionalities provided by htlatex (i.e. question) to generate HTML from LATEX documents. I'm interested on it.

Particularly, I would like to put in place an ideal directory structure in order to facilitate generation of both PDF and HTML. Until now I have something like:

├── html
├── pdf
│   ├── main.aux
│   ├── main.bcf
│   ├── main.log
│   ├── main.out
│   ├── main.pdf
│   ├── main.run.xml
│   └── main.toc
└── tex
    ├── main.sty
    ├── main.tex
    ├── pdflatex.sh
    └── sub.tex

It kind of solve my needs for the PDF case. I already added an html folder there, where I'm planning to work with the make4ht.

Question: How should I proceed in order to generate the .html file in the html folder using make4ht? Should I use a build file (how it would look like)?

Following are the contents of my project files:

To trigger the PDF generation I call pdflatex.sh (from inside tex folder):


cd ..
mkdir -p pdf
pdflatex -shell-escape -output-directory=pdf tex/main.tex





% \thispagestyle{empty}
% \clearpage


% \Blindtext
% \Blindtext[4][3]
% \blinddocument
% \Blinddocument
% \blindtext[5]
% \blindlist{itemize}[5]
% \blindenumerate[10]
% \blindmathpaper





% \usepackage[outputdir=build]{minted}
% \usepackage{minted}
\usepackage[brazil]{babel} % para relatórios em português
\usepackage[utf8]{inputenc} % para acentuação direta
\usepackage{amsmath}  % improve math presentation
\usepackage{tabularx} % extra features for tabular environment
\usepackage{graphicx} % takes care of graphic including machinery
\usepackage[margin=0.8in,letterpaper]{geometry} % decreases margins
\usepackage[final]{hyperref} % adds hyper links inside the generated pdf file
% \usepackage{ulem} % do no use, linebreaks on references stop working
% \usepackage[toc,page]{appendix}

% \usepackage[strings]{underscore}

    colorlinks=true,       % false: boxed links; true: colored links
    linkcolor=blue,        % color of internal links
    citecolor=blue,        % color of links to bibliography
    filecolor=magenta,     % color of file links



% \Blindtext
% \Blindtext[4][3]
% \blinddocument
% \Blinddocument
% \blindtext[5]
% \blindlist{itemize}[5]
% \blindenumerate[10]
% \blindmathpaper


You can copy the generated files to different directory using make4ht with --output-dir (or -d) option, so you can try that:

make4ht -d html tex/main.tex      

It will left your temporary files in the current dir however. You can remove them using a build file:

local function move_file(filename, args)
  local outdir = args.outdir 
  -- copy files only when --output-directory option has been used
  if outdir ~= "" then 
    local newfile = table.concat({outdir, filename}, "/")   
    print("moving the file: ".. filename .. " to directory: " .. outdir)
    os.execute("mv ".. filename .. " " .. newfile)
  return false

Make:match("html$", function(filename, args)
  return move_file(filename, args)

Make:match("css$", function(filename, args)
  return move_file(filename, args)

Make:match("tmp$", function(filename, args)
  for _,ext in ipairs {"aux", "xref", "tmp", "4tc", "4ct", "idv", "lg","dvi", "log"} do
    local newfile = filename:gsub("tmp$", ext)
    print("Removing: ", newfile)
    -- you can  move the aux files to the outdir using
    move_file(newfile, args)
    -- or, alternatively, just delete it
    -- os.remove(newfile)
  return false

This will match the .tmp file, take it's name as the basename and move all files with extensions listed in the argument of ipairs function to the output directory. Alternatively, you can also delete them instead if you uncomment the os.remove line.

We also match html and css files. By default, they are copied to the output directory, this version will move them here instead.

One final remark: you use some macros in your \title command. I guess that you don't use this particular command in your real document, because it causes a compilation error.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.