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.

Is there a good higher-level language or tex environment that would facilate both HTML and PDF rendering? I would like to be able to write tex document and on the basis of this document create mathjax-compliant HMTL and nicely-formatted PDF. This approach would also need to handle, for example, producing multiple HTML documents but creating a single PDF that would encapsulate the same content. Is there a good way to do this?

share|improve this question
1  
Maybe Pandoc is what you're looking for. See for e.g. charlietanksley.net/philtex/primarily-pandoc –  N.N. Jul 21 '11 at 12:28

5 Answers 5

up vote 3 down vote accepted

If you are just a little familiar with python, or not scared by it, I suggest sphinx. Their website links to many examples, there are relatively many extensions available and because it is the official Python documentation system (and by consequence of many python-related projects), you have a good guarantee that it survives long.

For math, there are currently 2 systems, jsmath, latex (renders to png in HTML mode), mathjax (in depevelopment IIRC). I personally used latex due to heavy macro usage (e.g. chapter in HTML).

share|improve this answer
    
PS. syntax overview –  eudoxos Jul 21 '11 at 12:37
    
This is an interesting suggestion and I have played around a little bit with it. However, having to type :math:x if I want to enter an in-line mathematical symbol is extremely burdensome. I don't know python but maybe there's some way to get around this nastiness.. –  3Sphere Jul 22 '11 at 20:10
    
You can define hooks doing search&replace on raw text before it is processed -- that's at least how I did it (and register the hook here. The replace approach has a few gotchas, such as meesing up table alignment, but that was a minor issue for me at least. –  eudoxos Jul 24 '11 at 7:45
    
This is what the rst source with math looks like then. –  eudoxos Jul 24 '11 at 7:46

I produce multiple formats (pdf slides, pdf notes, html text) from the same source; the contents also varies depending on the format. The input has no math.

At first I tried pandoc, which is great if you have little or no structure in your text. Pandoc produces well formed HTML and well formed LaTeX/ConTeXt output. It also supports gazillion other output formats, so you get epub, docbook, etc for free. The only drawback of pandoc is that markdown is a very limited input format. Markdown tags are style tags (**...** means bold), rather than structure tags (**...** means important). But more restrictively, it provides only three types of inline tags and three or four types of block level tags. I wanted a lot more structured tag in my text.

Next I tried using ConTeXt. I can use all the structure tags that I want in my input and it is easy to generate multiple versions of the same document. ConTeXt also provides an XML/XHTML export. I used CSS to directly display the xml. Everything worked flawlessly at the TeX->PDF route, but I am not completely happy with the XHTML output. Part of the reason is that I was trying to display the output directly using CSS and, as such, was limited by what is allowed in CSS. In hind sight, I think that it would have been better to use XSLT to convert (the ConTeXt generated) XML to HTML.

I do not have much experience in using XSLT, but after playing around it with a while I think that rather than trying to convert ConTeXt generated XML to HTML, it is better to start with hand-written XML and convert it to HTML. Once I thought about it a bit, I realized that there is not much difference between tex input (at least, ConTeXt input) and XML input. In ConTeXt, all commands have a \start.. ... \stop... version, which is same as <...> ... </...> in XML. Thus,

\startsection[title={....}]
    ....
\stopsection

becomes

<section title="..."> ... </section>

and so on. The same is true for inline commands. So, next year, I am planning to start with hand-written XML input and use XSLT (or some other XML->HTML tool) to convert it to HTML and use ConTeXt to directly process it to PDF. The main advantage of this approach is that the structure of my input is almost exactly same as my tex input, and I get good PDF output with very little effort. The HTML output requires a bit of work (for me), because I am not familiar with the XML->HTML toolchain, but I am confident that there will be good tools there.

TL;DR Pandoc: Great output, limited input features. ConTeXt: Great input markup, great pdf output, you need to use XSLT to tweak XML output. XML: Flexible input markup, use ConTeXt (or LaTeX) to directly produce PDF, use XSLT (or some other tool) to generate HTML.

share|improve this answer

There is also AsciiDoc, which can be translated into many different file formats. I've never used pandoc though, so I cannot tell which one to use.

share|improve this answer
    
Thanks for the suggestion; however, at this point, I've scrapped my efforts to use a "meta language" and am writing everything in straight latex and producing PDF output; I'll eventually get around to coercing the output to HTML. –  3Sphere Nov 25 '11 at 0:54

I heartily agree with N.N.'s comment. You can write in markdown and then export to LaTeX (and then into PDF) and into HTML, DocBook, and a number of other formats using Pandoc. It's a really neat system. And for more fancy websites, there's yst, also from John MacFarlane, the author of Pandoc. It allows you to keep your data structured in YAML and then extract it into string templates which you can then turn into LaTeX/PDF/HTML/DocBook as before.

share|improve this answer
    
Oh, I don't know how pandoc plays with mathml, but for many other people who don't want that functionality specifically, this is definitely an excellent solution. –  Seamus Nov 24 '11 at 22:10
2  
Pandoc (1.9+) will convert tex math into mathml for HTML, EPUB, and DocBook output formats if you specify --mathml on the command line. –  John MacFarlane Feb 12 '12 at 21:05

tex4ht generates nice HTML with support for mathjax.

share|improve this answer

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.