TeX and LaTeX. Still the best software available to translate structured markup to a pdf.
The downside is it's not super HTML-friendly (there are converters, but you can't display equations easily in HTML) so converting to Mobi, ePub, etc. is not straightforward.