For LaTeX, I used to rely on htlatex, latex2html, or more rarely tth. I know that we can use XML with ConTeXt, although I have no experience with this, and that Pandoc let us use Markdown syntax and provides several output formats (including ConTeXt and (X)HTML), as well as templates facilities.

However, does there exist a 'tex->html' converter for ConTeXt working out of the box, i.e. one that would accept a raw ConTeXt file (that can produce a PDF file) and transform it to HTML (single or multi-page)?

1 Answer
1

ConTeXt does not directly output XHTML, it outputs XML. However the current browsers (at least Opera, Firefox and Chromium) are able to display XML correctly. The XML can be styled using CSS.

When you want real XHTML, you have to transform the XML to XHTML using external tools. ConTeXt standalone ships with an example file: texmf-context/tex/context/base/export-example.{tex,css}. Here is a modified and shortened version of this file for demonstration.

As you can see, the style is pretty close. It can be further optimized through tweaking the CSS file. Included graphics, of course, have to be present in a format that the browser can handle.

Hyphenation is also present. ConTeXt inserts soft hyphen (0x00AD) characters where hyphenation is possible, which enables the browser to justify the paragraphs.

The resulting XML can be displayed by browsers and e-book readers. However, not all e-book reader are compatible, especially when it comes to math. Browsers also have their problems with displaying math.

(+1) Many (many) thanks for taking a look at this again. What command did you use to compile the above document, context or mtxrun? I was able to reproduce this example, and yours by replacing the \setupbackend options with export=yes,xhtml=yes (and running context on it). Anyway, that deserves a bounty!
–
chlMay 15 '12 at 21:55

Regarding math: ConTeXt generates MathML output. If you want it to work across all browsers, you can add the Mathjax js lib (which also works with MathML) in the generated XHTML file.
–
AdityaMay 15 '12 at 21:58

You can also use \setupbackend[export=example.xml,xhtml=example.xhtml,css=example.css]. I simply compiled with context example. You're welcome, I'm glad I could help.
–
MarcoMay 15 '12 at 22:01