Search code examples
scalalatexsbtmathmlscaladoc

Is there a way to include math formulae in Scaladoc?


I would like to enter math formulae in Scaladoc documentation of mathematical Scala code. In Java, I found a library called LatexTaglet that can do exactly this for Javadoc, by writing formulae in Latex: http://latextaglet.sourceforge.net/

And it seems to integrate well with Maven (reporting/plugins section of a POM). Is there an equivalent library for Scaladoc? If not, how could I integrate this library with SBT?

I also considered using MathML (http://www.w3.org/Math/), but looks too verbose. Is there an editor you would recommend? Does MathML integrate well with Scaladoc?

Thank you for your help!


Solution

  • The short answer is: no. LaTeXTaglet is made possible by the JavaDoc Taglet API. There is no equivalent in Scaladoc, therefore no clean solution.

    However, I can think of a hack that might be easy enough to do:

    There's a library called MathJax, which looks for LaTeX-style math formulae in an HTML page and dynamically renders it in place. I've used it before, it's pretty nice; all you have to do is include the script. So you could do two things:

    1. Edit and rebuild the Scaladoc source to include MathJax, or...
    2. Write a little post-processor crawl all of Scaladoc's HTML output after it runs, and inject MathJax into each file.

    That way, you could just write LaTeX formulae directly in your Scala comments and they should be rendered in the browser. Of course if you wanted a non-hacky solution, I'd suggest you create a taglet-like API for Scaladoc ;)