In Plotly, using HTML, why do some Greek letters work with decimal but not with entity name?

Viewed 539

In my Plotly figure title I need to use Greek letters and for some letters I can use the entity name directly as: μ and it renders the correct Greek letter mu. However when I do the same for omega or psi with ω or ψ then I just get the word written in Latin characters with the '&' and ';' but not the corresponding Greek one. Here is an image of the result:

enter image description here

However, using the decimal codes work as intended: layout = go.Layout(title='ω #968;')

enter image description here

1 Answers

I think it has something to do with javascript backend, and in particular entityToUnicode in svg_text_utils.js.

So I think $mu; is the only greek letter that will work (because it's specifically being handled by entityToUnicode along with a hand full of other characters).

From svg_text_utils.js:

/*
 * N.B. HTML entities are listed without the leading '&' and trailing ';'
 * https://www.freeformatter.com/html-entities.html
 *
 * FWIW if we wanted to support the full set, it has 2261 entries:
 * https://www.w3.org/TR/html5/entities.json
 * though I notice that some of these are duplicates and/or are missing ";"
 * eg: "&", "&amp", "&", and "&AMP" all map to "&"
 * We no longer need to include numeric entities here, these are now handled
 * by String.fromCodePoint/fromCharCode
 *
 * Anyway the only ones that are really important to allow are the HTML special
 * chars <, >, and &, because these ones can trigger special processing if not
 * replaced by the corresponding entity.
 */
var entityToUnicode = {
    mu: 'μ',
    amp: '&',
    lt: '<',
    gt: '>',
    nbsp: ' ',
    times: '×',
    plusmn: '±',
    deg: '°'
};
Related