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, 2017 at 7:26
  • So I'm using the actual subfiles package. Each one is its own document.
    – Canyon
    Feb 10, 2017 at 7:38

2 Answers 2


tex4ht support this. It needs a simple configuration file, subfiles.4ht to support multiple subfiles:

  \ifcsname subfiles@end\endcsname
  \expandafter\def\csname end \endcsname##1{%


It disables \end{document} in the included subfile, because it would close the document otherwise.

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

  • This works for me when I use only one subfile. I can't seem to get this to work with more than one subfile, or even anything at all after the \subfile command in sample.tex.
    – frabjous
    Mar 27, 2022 at 19:01
  • @frabjous thanks for the report, it seems so.
    – michal.h21
    Mar 27, 2022 at 19:44
  • @frabjous I've added a subfiles.4ht file, it should fix this issue.
    – michal.h21
    Mar 29, 2022 at 15:12
  • Seems to work so far. Thanks a lot!
    – frabjous
    Mar 29, 2022 at 19:19

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, 2017 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. Feb 10, 2017 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .