[Tex/LaTex] Use compile LaTeX to HTML with subfiles

htmllatex2htmlpandocsubfiles

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?

EDIT:

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

\documentclass[/path/to/files]{subfiles}
\begin{document}
Some words
\end{document}

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?

Best Answer

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

\def\:tempa#1{%
  \ifcsname subfiles@end\endcsname
  \else
    \subfiles@saveEndTo\subfiles@end
  \fi
  \let\choose:begin\@secondoftwo
  \expandafter\def\csname end \endcsname##1{%
    \romannumeral
    \subfiles@StrIfEqTF{##1}{document}{%
      \z@
      \subfiles@restoreEndFrom\subfiles@end
      #1%
    }{%
      \expandafter\expandafter\expandafter\z@\subfiles@end{##1}%
    }%
  }%
}

\HLet\subfiles@renewEndDocument\:tempa
\Hinput{subfiles}
\endinput

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

Simple example.

Main file sample.tex:

\documentclass{article}

\usepackage{subfiles}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
\title{Subfile example}
\maketitle
\tableofcontents
\subfile{subfile1.tex}
\end{document}

Included file subfile1.tex:

\documentclass[sample.tex]{subfiles}
\begin{document}
\section{Hello world}
Some words

Příliš žluťoučký kůň
\end{document}

You can compile the document using command

make4ht -u sample.tex

And this is the result:

enter image description here

Related Question