TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like a way to convert a document from HTML to LaTeX on a Windows platform. What is my best option?

share|improve this question
Is the document really, truly written in HTML as its original format, or was it generated from some other way? – Loop Space Sep 14 '10 at 19:35
I'm actually looking for ways to display books from Project Gutenberg, gutenberg.org/ebooks/5230 I was inspired by this effort: pmonta.com/etext/index.html – Henry B. Sep 15 '10 at 2:35
If you're mainly looking for higher quality typography than usually offered by html or epub, I'd recommend using Prince XML, which will give you kerning and ligatures and hyphenation (using TeX's algorithm). See princexml.com ; for converting ePub to PDF using Prince, see mobileread.com/forums/showthread.php?t=89689 – frabjous Sep 15 '10 at 2:55
I approve of the rationale! That sounds like a very good use of such a converter. – Loop Space Sep 15 '10 at 9:31
up vote 38 down vote accepted

What your best option would be depends on a lot on what your needs are. Are you only trying to import the structure, or exact look, or what? How important is it that the resulting document really be done properly?

Anyway, here are a number of things to try.

AbiWord: an open source word processor that can import HTML or similar formats and export LaTeX. (Be sure to install the extra export plugins when installing; the default install doesn't include a LaTeX export, but it can easily be chosen.)

Writer2LaTeX: An openoffice plugin for exporting to LaTeX; Open office supports HTML import of course (Though W2L can handle .odt to .tex even without Open Office installed; but then converting .html to .odt might be trickier.)

rtf2latex2e: as its name implies, converts RTF to LaTeX; so you'd need some way to convert HTML to RTF (though that's relatively easy, can be done with most any word processor).

pandoc: Haskell program for converting between various mark-up languages, including HTML and LaTeX

html2latex: Perl script for such conversions (I've never tried it but plan on doing so soon)

htmltolatex Java program along similar lines (Again, I haven't tried it.)

Even with all those options, however, personally, if it was something I truly cared about doing right, simply transferring over the plain text and redoing everything manually would still be my solution of choice. The above are just quick fixes for a document of relatively little importance, or when having it in LaTeX in addition to HTML is just a matter of convenience.

share|improve this answer
some way to convert HTML to RTF (though that's relatively easy, can be done with most any word processor) - Your choice of converter here will affect the quality of output you get from the RTF to Latex converter. – Charles Stewart Sep 15 '10 at 9:03

If the document is XHTML (rather than HTML), then it can be processed directly in ConTeXt. See http://dl.contextgarden.net/myway/tas/xhtml.pdf for a tutorial and http://dl.contextgarden.net/myway/tas/ for the sample files.

share|improve this answer
tidy will convert HTML to XHTML. – Charles Stewart Sep 15 '10 at 9:06
An advantage of Context over Latex as a target format is that Context allows (encourages, even) much more of a CSS/HTML-like separation of style from content. – Charles Stewart Sep 15 '10 at 9:07

This is why Project Gutenberg should've used sensible markup from the beginning. Fortunately, things are getting marked up now, so one can use:

to convert to Text Encoding Initiative (TEI) and then use Dima's answer at: How can I efficiently convert TEI documents into LaTeX?

share|improve this answer

The following sed script is meant to convert HTML to (La)TeX (source):

# Too bad there's no way to make sed ignore case!
/<[Xx][Mm][Pp]>/,/<.[Xx][Mm][Pp]>/b lit
/<.[Xx][Mm][Pp]>/b lit
/<[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/,/<.[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/b lit
/<.[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/b lit
/<[Pp][Rr][Ee]>/,/<.[Pp][Rr][Ee]>/b pre
/<.[Pp][Rr][Ee]>/b pre
# Stuff to ignore
# character set translations for LaTex special chars
s?\\?\\backslash ?g
# Paragraph borders
s?<[Pp]>?\\par ?g
# Headings
# UL is itemize
s?<[Ll][Ii]>?\\item ?g
# DL is description
# closing delimiter for DT is first < or end of line which ever comes first NO
# Other common SGML markup.  this is ad-hoc
# Italics
s?<it>\([^<]*\)</it>?{\\it \1 }?g
# Get rid of Anchors
# This is a subroutine in sed, in case you are not a sed guru
: lit

There is also HTML to TeX, written in C, that produces LaTeX output.

share|improve this answer
You can have BSD or GNU sed ignore case, using the i modifer – hd1 Apr 28 at 5:09

For a page from a typical website, the best way is probably to simply:

  1. Paste the text from the page into a blank LaTeX document
  2. Properly escape (or make verbatim) any text with special characters in it
  3. Fill in the rest of the markup

(Of course, if you actually have a well-structured page, which e.g. uses H1 for the document title and properly nests H2- and H3-headed sections, it might be worth trying a converter program. You'll still need to add markup for the things that HTML does not provide markup for, of course.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.