Julia and Latex

Consider the problem of putting symbols for the electron, muon and tau fields in some Julia code. Or, even trickier, doing this for the anti-neutrinos. In native Julia there is a lot of escaping of e.g. backslashes to do. There is a package which helps called LaTeXStrings.

The Julia code below shows how this package might be used to create valid latex to be used in whatever other strings exist in the code. Note that it is not necessary to put the dollar signs in the strings, the package does this for us.


                using LaTeXStrings
                L"\bar{\nu}_e"
                L"\bar{\nu}_{\mu}"
                L"\bar{\nu}_{\tau}"
            

This being the case, MathJax can then correctly render the Latex.

For example, suppose we wanted to create a drawing labelled with the three types of anti-neutrino. We can put the Latex expressions directly into the html page and they are correctly rendered: $\bar{\nu}_e$ or $\bar{\nu}_{\mu}$ or $\bar{\nu}_{\tau}$. To do the same thing inside Julia code We might try something like this:


                using Luxor, LaTeXStrings

                Drawing(400, 400, "../images/LuxorAndLatex.svg")
                origin()
                
                # Text
                sethue("black")
                fontsize(14)
                text( L"\bar{\nu}_e", Point(-200, 50))
                text( L"\bar{\nu}_{\mu}", Point(-200, 0))
                text( L"\bar{\nu}_{\tau}", Point(-200, -50))

                finish()
            

Unfortunately we discover that, while the LaTexStrings package has correctly put the dollar signs around the latex expressions, mathjax doesn't work in this situation.

Looking into the svg produced from compiling the Julia code it isn't clear whether there is any actual recognisable text in it at all! Not surprising that MathJax doesn't work. It is not clear how to put the required text into a drawing using Luxor. The two alternatives seem to be:

  1. Use html tables with latex content in the cells
  2. Use Latex tables, if they can be rendered by MathJax
It seems that the first alternative is simple and the second alternative is complicated. HTML tables win!

HTML Tables

The following shows the three 'electron' types and the anti particles of the three neutrino types. I probably wouldn't need to show this particular combination of particles but the example just shows how this content could be input into the html page.

e $\mu$ $\tau$
$\bar{\nu}_e$ $\bar{\nu}_{\mu}$ $\bar{\nu}_{\tau}$

It is possible that some Julia code could generate a table that was hard to create by hand. The ouput of the code would then have to be physically pasted into the html page. This would include latex expressions generated by the LaTeXStrings code and, because they are physically part of the html page, they would be correctly rendered by MathJax.

In passing, this page includes some configuration for MathJax that I have not had to use before. It is not clear if it is optional but works when it is present!