I've got a rather large tex project I'd like to turn into one or many linked html files. However neither of my go-to converters, pandoc and latex2html, seem to support recursive compilation.

Is there a compiler flag for one of them that I'm missing? If not, is there a converter that supports what I'm trying to do, or do I just have to copy and paste everything into one absurdly long document?


To be clear, I have a file main.tex with the subfiles package. I have several other files, i.tex etc, of the form:

Some words

How do I include all of them in my final document, either as content in some main.html or separate i.html files linked in to main.html, without doing the hard work by hand?

  • do you include the subfiles in the main document, or is each of them separate document with it's own preamble? – michal.h21 Feb 10 '17 at 7:26
  • So I'm using the actual subfiles package. Each one is its own document. – Canyon Feb 10 '17 at 7:38

tex4ht support this. Simple example.

Main file sample.tex:


\title{Subfile example}

Included file subfile1.tex:

\section{Hello world}
Some words

Příliš žluťoučký kůň

You can compile the document using command

make4ht -u sample.tex

And this is the result:

enter image description here


Does latexml do what you want? I'm a little unsure of your exact needs but it can take a large LaTeX file and split it up by chapter or section (etc) into multiple HTML files.

I'm no expert but the command I'm using to do this (assuming document tex/mydocument.tex and saving to an html/ directory) is:

latexml tex/mydocument.tex | latexmlpost - \
  --sourcedirectory=tex \
  --format=html5 \
  --destination=html/mydocument.html \
  --splitat=chapter \

Here the split is by chapter, and each chapter needs a \label for the split naming to work. If you remove --splitnaming=label, it will simply call each HTML file something like Ch1.html..ChN.html.

It's not included in TeX Live but I had no problem on macOS installing directly from the LaTeXML Github repository.

  • I'm trying to do the opposite of that---take several tex files and make them one html file. – Canyon Feb 10 '17 at 7:39
  • Hmm, your question didn't say that. I assumed "subfiles" was just a descriptor, not a package :) I think I would either preprocess or recreate the .tex sub-files without the \documentclass and document environment lines, and use plain old \input in a master document that can be fed into latexml (or other, if they supposed that too). It would be possible to define appropriate behaviour in latexml so this isn't necessary but I haven't figured out how to do that yet. – Will Robertson Feb 10 '17 at 9:40

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.