Scala or XML for Documents? (March 24, 2006)

I have used DocBook in the past for documents where I would like to distribute both HTML and for-print versions. It works reasonably well, but there are three major shortcomings:

  1. There are no subroutines or macros. If you do something twenty times, you have to repeat yourself.
  2. It does not look as nice as a carefully written Latex file.
  3. It does not handle math formulas, where Latex remains king.

To address these, I have now tried using Scala case classes rather than XML, and a plain old Scala method to replace the sophisticated DocBoox style sheets. I believe this experiment is neutral or positive on all three points:

  1. Scala wins: Scala has subroutines.
  2. Scala wins: The HTML version looks about the same, and the PDF version looks vastly better.
  3. Tie: math formulas are difficult either way.

Here is the old version in DocBook:

Here is the new version, written in Scala:

The two versions are about the same size as each other, so we can’t prefer one or the other over the length of code.

The quality of output is a matter of taste, but I would say that the HTML versions are about the same, and the PDF version is much better with Scala than DocBook.