[OS X TeX] HTML to Latex

Benoit RIVET benoit.rivet at free.fr
Sat Sep 1 22:29:52 CEST 2012


Le 1 sept. 2012 à 19:56, André Bellaïche a écrit :

> Has anyone here ever tried to convert a HTML file into a LaTeX file?

You can try and use pandoc http://johnmacfarlane.net/pandoc/. To convert example.html into test.tex just invoke on the command line :

pandoc -f html -t latex -o test.tex example.html

which gives you a nice test.tex file. However, the test.tex file has no preamble, no \begin and \end{document}, and you may need to do some fine tuning to your file before compiling (e.g. : add all the packages you need…)

You can do all the editing with TexShop :

1. Close TexShop and tell TexShop to process html files by invoking on the command line :

defaults write TeXShop OtherTeXExtensions -array-add "html"

2. Make your own html2latex engine. In ~/Library/Engines, copy one the existing engines, change the name to html2latex.engine (or any fancy name you care to give), open with TexShop (or your other favorite text editor) and change the text inside to :

#!/bin/tcsh

set path= ($path /usr/texbin /usr/local/bin)
set filename = "$1"
set texname = "${filename:r}.tex"

pandoc -f html -t latex -o "$texname" "$filename"
open -a TexShop "$texname"

3. Open some html file, set the engine to html2latex, compile and work with the resulting .tex file which automagically opens in TexShop.

4. However, the result of the conversion may be complete garbage tex code when the html code is some piece of junk html code (which should be the case on any html page you can find on the web).

5. I never ever tried to convert html to tex before you asked your question… So please take into account that my experience is limited (and that I shall certainly not try to investigate further…)

Benoît RIVET


More information about the macostex-archives mailing list