A formula like a picture is often worth a thousand words. Working on software for mathematical optimization, I've been wondering how can I embed math in my API documentation generated by Javadoc. Recently I had some time to explore this problem and this post is devoted to my findings.
As Javadoc generates output in HTML format, MathML is the obvious candidate for embedded math. However, I am not paid for the number of lines of code I write, so MathML doesn't really appeal to me. For example here's a MathML snippet for \(ax^2 + bx + c\):
What really appeals to me is LaTeX especially considering that it will
allow me to copy existing formulas to and from my LaTeX documents. The above
example in LaTeX is just
ax^2 + bx + c. Besides, browser support
for MathML is patchy at best.
formulas. To link MathJax to the generated HTML pages add the
-header option providing the necessary code to the
javadoc command as follows:
$ javadoc -header \ '' ...
Or, if you are using Maven, you can pass the Javadoc parameter via
additionalparam as in the following POM extract:
Note that substantial amount of escaping is needed in this case.
Now you should be able to use LaTeX in your Javadoc:
and get nice rendering of formulas:
This class implements a very sophisticated algorithm which has something to do with polynomial \(ax^2 + bx + c\) .