2

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

pdflatex.sh

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

main.tex

\documentclass[12pt]{article}

\usepackage{tex/main}

\begin{document}

\title{\truncate[]{15cm}{\lipsum[8]}}
\author{\truncate[]{5cm}{\lipsum[1]}}
\date{\today}
\maketitle
% \thispagestyle{empty}
\tableofcontents
% \clearpage

\subimport{tex/}{sub.tex}

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

\end{document}

main.sty

\ProvidesPackage{main}

%++++++++++++++++++++++++++++++++++++++++

\usepackage[backend=biber,style=numeric,sorting=none,sortlocale=pt-BR]{biblatex}
\addbibresource{tex/relatorio.bib}
% \usepackage[outputdir=build]{minted}
% \usepackage{minted}
\usepackage[brazil]{babel} % para relatórios em português
\usepackage[utf8]{inputenc} % para acentuação direta
\usepackage[T1]{fontenc} 
\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{url}
\usepackage{import}
\usepackage[final]{hyperref} % adds hyper links inside the generated pdf file
\usepackage{csquotes}
\usepackage{indentfirst}
\usepackage{float}
\usepackage{subfig}
% \usepackage{ulem} % do no use, linebreaks on references stop working
\usepackage{listings}
\usepackage{csquotes}
% \usepackage[toc,page]{appendix}
\usepackage{appendix}

% \usepackage[strings]{underscore}
\usepackage{adjustbox}
\usepackage{longtable}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage[breakwords]{truncate}

\hypersetup{
    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
    urlcolor=blue         
}
%++++++++++++++++++++++++++++++++++++++++
\addto\captionsbrazil{%
   \renewcommand{\appendixtocname}{Apêndice}%
   \renewcommand{\appendixpagename}{Apêndice}%
}
\newcommand{\cubesat}{\textit{cubesat}}
\newcommand{\frames}{\textit{frames}}
\newcommand{\beacon}{\textit{beacon}}

sub.tex

\begin{abstract}

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

\end{abstract}
3

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)
  end
  return false
end

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

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


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)
  end
  return false
end)

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.