Search code examples
javaeclipselatexjavadoc

Eclipse JavaDoc LaTeX equations


I have code where it's common to have many equations in JavaDoc comments. I'm currently using MathML to display these equations, as it's the only way I've been able to get equations that can display in Eclipse's hover tooltips.

I don't actually care about created HTML. I just need Eclipse's hover to display equations correctly.

Unfortunately, MathML is insanely verbose. One line of simple LaTeX becomes 50 lines of MathML! It's cluttering up my source and the JavaDoc comments are unreadable in the source code (you have to hover over the method to read the comment).

Does anyone know a way to use LaTeX equations in Eclipse that will show up in this hover text?

EDIT: Something like this would be preferable, but this doesn't work in Eclipse's hovers. Presumably there's no way to inject JavaScript in those.


Solution

  • Suggestion 1: Use MathJax

    I use MathJax to write LaTeX equations in JavaDoc. You may see the result here: https://javadoc.io/static/net.finmath/finmath-lib/6.0.12/net.finmath.lib/net/finmath/montecarlo/interestrate/models/LIBORMarketModelFromCovarianceModel.html

    However, MathJax relies on JavaScript and the Eclipse Hover does not support JavaScript. But then I must say that the MathJax LaTeX can be read even without renderer, so for me it is OK to have LaTeX code in the hover text. You will see it if you enable JavaScript in the hover text - but that is a different question.

    To enable MathJax you just need to include a header in your docket config like

                    <header>
                        <![CDATA[
                        <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
                        </script>
                        ]]>
                    </header>
    

    Suggestion 2: Use CLSI on your local machine

    If you need this only for yourself you could run a CLSI (common-latex-service-interface). Then, maybe it is possible to just have an image tag with the latex code in its URL which returns an image). I have not elaborated on this... (personally I would prefer option 1, because it will also generate the LaTeX in the JavaDoc.