Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
3  
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
1  
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

5 Answers 5

up vote 30 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
1  
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

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

tex4ht seems to be the best option. But, in my experience, all these latex/html converters cause troubles when applied to documents more complicated than beginner's ones.

share|improve this answer
3  
Sorry, wrong way! –  Charles Stewart Sep 14 '10 at 18:47
4  
@Sergey: This might be an opportunity for you to earn the Peer Pressure Badge ... –  doncherry Jul 26 '11 at 17:52
    
here you go (-1). You are welcome, Sergey ;) –  DaveBall aka user750378 Aug 23 '13 at 13:04

Your Answer

 
discard

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.