36

I am looking to convert LaTeX to HTML. A long time ago (during my thesis, in 2000!), I used Hacha and Hevea ... but obviously, they are no longer maintained, especially the Windows version. More recently Google sent me to tex4ht, but it seems that there too the project is at a standstill (the site indicates that there will soon be opportunities for image management, but that was in 2014, since then nothing more) and is poorly documented.

Hence my question: is there a recent solution for converting LaTeX to HTML compatible with Windows? The option that I need are:

  • using CSS
  • cutting the document into several file
  • allowing the use of picture for navigation (up, prev, next)
  • compatible with Windows
  • 5
    tex4ht is maintained very well with a bunch of new features every few weeks! – Keks Dose Dec 10 '18 at 11:43
  • 1
    lwarp (which I have not used) tex4ht and latexml are the three main actively maintained ones – David Carlisle Dec 10 '18 at 12:30
  • 12
    There is also Pandoc, which does not fully support all features and packages but it generally works ok, is easy to use and it is able to convert between many different formats. – Marijn Dec 10 '18 at 14:45
  • 1
    "not obsolete" today will be "obsolete" tomorrow – Mauricio Gracia Gutierrez Dec 10 '18 at 17:06
  • 1
    The HeVeA user manual at hevea.inria.fr/doc/index.html seems to be dated July 2018 so it appears to still be maintained and updated. I just found out about it when posting a totally unrelated question and HeVeA came up are a possible match of the tags. I just stated to look into it when I came across this question, so I am curious as to why you think it is no longer maintained? – Peter Grill Dec 12 '18 at 7:59
46
+500

It is true that the main page of tex4ht and documentation seems obsolete, but the project itself is alive, as can be seen from the history of commits and the mailing list. We added MathJax output support recently, for example.

It is also true that the full distribution which is on CTAN haven't been updated since the original author passed away, but the updates go directly to TeX distributions, so it is not necessary to install the distribution by hand, it would be quite complicated process. Everything you need to run updated tex4ht is included in TeX Live.

At the moment, I am working on a new documentation, which should be big improvement over the current state.

Regarding your question, all of this should be possible with tex4ht. It produces basic CSS for your document, it also enables to include custom CSS in the generated HTML. It supports cutting of the document to separate files for chapters, sections etc. It works on Windows when you use TL, but Miktex works as well.

The following file, myconfig.cfg will split an article on sections:

\Preamble{xhtml,2}
\Configure{AddCss}{test.css}
\Css{body{background-color:green;}}
\Configure{crosslinks}{}{}{\includegraphics{next.png}}{\includegraphics{prev.png}}{}{}{}{\includegraphics{up.jpg}}
\begin{document}
\EndPreamble

The split is requested using 2 option used in the \Preamble command. The \Css command can be used for simple CSS instruction, while the \Configure{AddCss} requires inclusion of an external CSS file. The \Configure{crosslinks} requires pictures for links for previous, next and top pages.

Compilation of the document can be requested using the following command:

make4ht -uc myconfig.cfg filename.tex

make4ht is a build system for tex4ht, it should be used instead of the htlatex command.

  • 1
    @ChristopheGenolini have you tried the \Configure{crosslinks} from my answer? The used pictures must be present on your system. – michal.h21 Dec 10 '18 at 17:18
  • 1
    Yes, it works. Thanks a lot. So now that it works, I will have dozens of question (like : "I want the arrow to be in order left / up / next, how can I do that?") :-) Is there an official active forum somewhere? – Christophe Genolini Dec 11 '18 at 15:47
  • 2
    @ChristopheGenolini the unofficial forum is here, just add tex4ht tag to your question. We have also mailing list. – michal.h21 Dec 11 '18 at 16:20
  • 3
    Thanks so much for all of your work! A bounty is coming your way :) I also haven't forgotten that I've promised to contribute to the documentation, it's high on my list. – cmhughes Dec 12 '18 at 12:51
  • 2
    @cmhughes thanks :) I've created a basic design for the documentation, inspired by Readthedocs theme and started collecting existing pieces of information from the old documentation, the log file created using "info" option, etc. so any contribution is welcomed! – michal.h21 Dec 12 '18 at 20:48
4

Pandoc is the new kid on the block if it comes to processing LaTeX input, and it is very actively developed with a new release every few weeks. (It can handle LaTeX output since its early days). It's available for Windows, and it is recent too...

Pandoc has multiple input formats it can process:

echo $(pandoc --list-input-formats)

    commonmark creole docbook docx epub gfm haddock html jats json latex \
    markdown markdown_github markdown_mmd markdown_phpextra markdown_strict \
    mediawiki muse native odt opml org rst t2t textile tikiwiki twiki vimwiki

Each of these inputs it can convert into the following output formats:

 echo $(pandoc --list-output-formats)

     asciidoc beamer commonmark context docbook docbook4 docbook5 docx \
     dokuwiki dzslides epub epub2 epub3 fb2 gfm haddock html html4 html5 icml \
     jats json latex man markdown markdown_github markdown_mmd \
     markdown_phpextra markdown_strict mediawiki ms muse native odt \
     opendocument opml org plain pptx revealjs rst rtf s5 slideous slidy tei \
     texinfo textile zimwiki

The detailed styling of these outputs can be manipulated in appropriate ways for almost every single format: for HTML based outputs (including EPUB or Slidy, DZSlides, Slideous, Reveal.JS and S5 slideshows) you can apply CSS, for ODT or DOCX you can use a reference.docx or reference.odt to clone the styles from, for LaTeX you can customize the document template, etc.

The way Pandoc works is very modular: It first reads each input with a specialized Reader component, converts it into its own internal format, native, and then in turn converts native to the final output using the appropriate Writer component.

The Reader component for LaTeX is Text.Pandoc.Readers.LaTeX. Now here is an extract of the changelog in its recently (Nov 2019) released v2.5 which proofs its active maintenance and development of the relevant component:

Text.Pandoc.Readers.LaTeX

Cleaned up handling of dimension arguments. Allow decimal points, preceding space.
Don’t allow arguments for verbatim, etc.
Allow space before bracketed options.
Allow optional arguments after \ in tables.
Improve parsing of \tiny, \scriptsize, etc. Parse as raw, but know that these font changing commands take no arguments.

I cannot comment on the scope of Pandocs reading support for specialized LaTeX features and environments though. That's up to you to decide and evaluate. Maybe, or even likely, tex4ht or HaVeA are still better. But I'm sure you already have a few LaTeX documents at hand which you can put to a test quickly:

pandoc          \
  --from=latex  \
  --to=html     \
  --output=my.html

Or shorter, but with a CSS of your own choice applied:

pandoc          \
  -f latex      \
  -t html       \
  --css=my.css  \
  --output=my.html

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.