scikit-hep/hist

[FEATURE] Representation in notebooks does not take into account math formulae in labels

eduardo-rodrigues opened this issue · 2 comments

Something like

h = hist.Hist.new.Reg(40, 70, 110, label=r"$l^{+} l^{-}$ invariant mass").Int64()

Displays only "invariant mass" as x-axis label. Is that on purpose or a feature? In either case, and just because math is so often used in labels, it would be useful to have such an example in the docs or some information about the feature somewhere.

I was wondering about this as well and had a brief look at this. h._repr_html_() reveals the repr used in the notebook, and the difference between the axis label (where LaTeX portions of the string are skipped) and the summary information to the right of the axis (where LaTeX works fine) is that the former is within an <svg> environment.

Here is an example of the relevant parts of the html that can be run in a notebook:

from IPython.core.display import HTML

HTML("""\
<html>
    $\ell$
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="-10 -10 100 15">>
        <text> abc $\ell$ </text>
    </svg>
</html>
""")

which renders the $\ell$ part outside the svg fine, but skips it within the svg. I suspect that might not be on purpose.

Many thanks @alexander-held! Interesting findings. Let's see what the maintainers team say ...