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

Is there a converter that will convert LaTeX to HTML? I have tried several services but the LaTeX diagrams and some of the maths came out weird.

I actually converted the Latex to PDF without a problem. Then I used an online PDF to HTML converter to convert from PDF to HTML. The square root signs did not appear properly and some of the Cartesian coordinate plane diagrams had nothing on them except the grid.


If $x$ is non-positive then $x \leq -\sqrt{\frac{1}{2}}$     $\hspace{30 mm} $     (6)\\

(4) and (6) tell us that\\

(4)  $-1 \leq x \leq 0$  \\

(6)  If $x$ is non-positive then $x \leq -\sqrt{\frac{1}{2}}$\\

Therefore $-1 \leq x \leq -\sqrt{\frac{1}{2}}$\\

\vspace{50 mm}

\psline[linewidth=1pt](-1.8, 0)(-1.8,4)
\psline[linewidth=1pt](-1.8, 0)(-1.8,-4)


PDF output:

enter image description here

PDF->HTML output:

enter image description here

share|improve this question
It may help if you describe what techniques you have tried and include examples of what turned out weird. – N.N. Dec 25 '11 at 14:57
Perhaps one of the questions listed at tex.stackexchange.com/questions/tagged/latex2html is helpful to you? – doncherry Dec 25 '11 at 15:18
@doncherry: And if those don't, there's always the FAQ. – Martin Schröder Dec 25 '11 at 18:19
So, @XYZ: Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. – doncherry Dec 25 '11 at 19:08
See comment below answer. – XYZ Dec 26 '11 at 13:52

Using PDF as an intermediate format when converting from LaTeX to HTML is not very good idea. LaTeX and HTML are both mostly structural markup langauages, which means you use them to describe the document structure (sections, emphasize, formulas etc.), whereas PDF is mostly about representation of your document on the screen or paper. When converting LaTeX to PDF, you loose much of the structural information, and it cannot be successfully recovered by conversion from PDF to HTML.

It is much better to convert LaTeX directly to HTML. There are number of ways (WayBack Archive) how to do that, one I would recommend is by using htlatex. It is probably already part of your TeX distribution, is very powerful and flexible, and its use can be as simple as running

htlatex mydocument.tex

If you tell us more about your environment (which operating system do you use, what is your TeX distribution, your text editor/LaTeX IDE, how you generated the PDF file etc.) we may be able to give you more details on how to use htlatex.

share|improve this answer
I used MiKTeX 2.9 which I downloaded off the internet onto a computer using Windows 7. It is TeXworks and some of the options are pdfLaTeX + MakeIndex + BibTeX, LaTeXmk, pdfTeX, pdfLaTeX, pdfLaTeX + MakeInndex + BibTex, XeTeX, XeLaTeX, XeLaTeX + MakeIndex, + BibTex, ConTeXt(LuaTeX), conTeXt(pdfTeX), ConteXt(XeTeX) – XYZ Dec 27 '11 at 14:04

Is there a converter that will convert LaTeX to HTML?

Yes. There are lots. But you already knew this, as evidenced by your second "question":

I have tried several services but the LaTeX diagrams and some of the maths came out weird.

"turning out weird" could mean any number of things:

  • The document fails to compile
  • The document compiles, but is empty or corrupted
  • The document compiles and opens, but is somehow faulty.

Each of these categories breaks down further and the solution may well depend on what you used to do the conversion, so as it stands, this question is unanswerable.

For diagrams, one word of general advice I would give is that it might be best to compile the diagrams separately and include them into the html by hand with <img> tags. Diagrams are hard. The standalone package/class can help with this. See also the pgf/TikZ externalisation tag.

share|improve this answer
I actually converted the Latex to PDF without a problem. Then I used www.pdfonline.com to convert from PDF to HTML. The square root signs did not appear properly and some of the Cartesian coordinate plane diagrams had nothing on them except the grid. – XYZ Dec 26 '11 at 13:48
@XYZ add this information to your question, along with an example of a file that has this problem. – Seamus Dec 26 '11 at 17:13

You may try to use pdf2htmlEX, which is a general PDF to HTML converter. You can compile the LaTeX source to PDF, and then convert the PDF to HTML via pdf2htmlEX. A good reference of pdf2htmlEX is its wiki page. The work-flows are given in the Figure 3 of the article on TUGboat: Online publishing via pdf2htmlEX HTML / PDF.

The screenshot shows the converted HTML (Ubuntu 14.04, Google Chrome 43).

enter image description here

share|improve this answer
Wow, pdf2htmlEX looks awesome: coolwanglu.github.io/pdf2htmlEX/demo/cheat.html – asmaier Sep 20 '15 at 20:44

As previously observed using PDF format for converting from LaTeX to HTML is very bad idea. Here you will find a comprehensive list of programs that convert LaTeX to HTML (Note not all of those programs are capable of converting pure TeX.)


I am familiar with three of these programs: LaTeX2HTML, TeX4ht, and Hevea. All of them have their strengths and weaknesses and they use different approaches. TeX4ht is included in TeXLive and MiKTeX unlike other two and from the point of view of theoretical CS is a "correct" way to do conversion (not surprisingly it was written by a (now deceased) member of the CS department at Ohio State). If you have just a few pages to convert, probably the right approach for you would be to chose any of the three and then do some manual editing. Now you have to be careful. For example Hevea will try to use HTML tags for things like square root while TeX4ht will use bitmap images for any math expressions. Since pure HTML has a poor support for mathematics the first approach can quickly get into trouble but when it works the output is really beautiful.

As for diagrams and pictures, all of the above programs to my knowledge rely on ImageMagic to do image conversion. Hevea has to be run multiple times (it is actually bunch of scripts) and the proper way to use it is by writing a Makefile (Unix again). I would actually convert images and diagrams manually using GraphicMagic which is IMHO far more stable and better batch image processor than ImageMagic.

share|improve this answer
What do you mean by "theoretical CS correct" more precisely? – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Aug 15 '14 at 14:54

Three words: use LaTeX subset

LaTeX and its common output formats like PDF are super complicated. Converting all of it to HTML + CSS is close to impossible.

But if you restrict yourself only to a small subset of LaTeX features it becomes feasible.

Check out Softcover: it has a LaTeX subset which it calls Polytex that it can convert to HTML. The exact subset is not well documented, but it already handles 99.9% of what we need to make regular books as shown in their documentation https://github.com/softcover/softcover_book/tree/master/chapters : sections, lists, equations, tables, images, references. Softcover does it's magic through Tralics, which does LaTeX to XML.

As Seamus said, diagrams are hard, and it is unlikely they will be part of the implementable subset any time soon, so use images. Generate the images through a command line tool like gplot or pyplot, and then build the PDF with a Makefile that first builds the images and then the PDF.

share|improve this answer
If anyone can guess why the downvote, let me know. – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Jul 11 '15 at 14:36

I have had good mileage with and would recommend pandoc for converting LaTeX to HTML output.

Pandoc provides capability for applying CSS styling to HTML output and can take care of equation rendering with e.g. MathML and citation/bibliography styling, among many other features, and is well documented.

share|improve this answer

RtextDoc has a built in Latex to Html converter

share|improve this answer
How well does it cope with the type of documents the poster is interested in? – Andrew Swann Oct 23 '13 at 6:25

I'm currently developing a free open source tool that can convert LaTeX to a single HTML file. Its called PDBF (https://github.com/uds-datalab/PDBF) and runs on win/linux/mac.


Resulting HTML file is placed in the same folder as the source tex file with the same name as the source tex file.

Technical details: The PDBF compiler basically uses a regular tex engine to compile your pdf and then stores the pdf as base64 encoded javascript string in the HTML and then includes a slightly modified version of pdf.js (The free and open source pdf engine of firefox) into the HTML to display that pdf.

Hope you like my project. Feel free to contact me through github if you have suggestions or encounter bugs.

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.