2

When I create a PDF of my main.tex file, I do it like:

pdflatex -output-directory=build main.tex

This way the PDF file and all the other (suff) files generated during the process goes in the build folder.

I just learned how to create HTML from main.tex, doing:

htlatex main.tex

It generates a main.html file and a lot of other (stuff) files.

Is there an option to make it a little cleanly? Perhaps build in a dedicated folder?

  • Symbolic links are one way to do this. Make a convert directory which contains symlinks to the source files and directories you need to compile. – musarithmia Dec 29 '16 at 21:47
2

You can pass -output-directory to htlatex as well:

htlatex filename xhtml "" "" " -output-directory=build"

The problem with this approach is that tex4ht is searching for the generated dvi file in the current directory, so it fails:

Output written on build/filename.dvi (1 page, 9632 bytes).
Transcript written on build/filename.log.
----------------------------
tex4ht.c (2012-07-25-19:36 kpathsea)
tex4ht -f/filename 
  -i~/tex4ht.dir/texmf/tex4ht/ht-fonts/ 
--- warning --- Can't find/open file `filename.dvi'
--- error --- Can't find/open file `filename.dvi'

The solution is to use make4ht, which is much more powerful way to call tex4ht than htlatex.

With make4ht, you can use a build file to modify the compilation parameters and to move files to a correct destination. Save the following code as mybuild.mk4:

local outdir = "build"
local newinput = outdir .."/" ..settings.input
settings.latex_par= "-output-directory=".. outdir 
settings.input = newinput

Make:match(".css$", "mv ${filename} ".. outdir .."/${filename}")
Make:match(".tmp$", "rm ${filename}") 

The build file is Lua script, output directory name is saved in outdir variable, we then modify default settings to use the outdir, settings.latex_par contains parameters for LaTeX, settings.input is the location of the dvi file. Make:match is used to fix location of some files generated by tex4ht, which don't follow the -output-directory option. The first one moves the css file to the output dir, because it is written by tex4ht to the current dir. If you use Windows, replace mv with move. The second deletes filename.tmp file. Again, if you use Windows, replace rm with del.

You can compile the document using

make4ht -e mybuild.mk4 filename

And the output structure is following:

$ ls -R1
.:
build
filename.tex
mybuild.mk4

./build:
filename.aux
filename.css
filename.dvi
filename.html
filename.idv
filename.lg
filename.log
filename.tmp
filename.xref
filename.4ct
filename.4tc

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.