Special Characters in Latex Labels

I’m working on an application that works with different SI units. For that application, I need to display units as bokeh labels in plots. However, I’m having issues with some of the symbols I need, and I’m not sure if the problem is in my usage of the library, or if it’s a bug with bokeh or MathJax.

In particular, I need a non-italic greek lowercase mu (μ) and a uppercase A with an overring (Å), but have been unable to get those. They are rendered almost correctly, but appear very small and on top of the other letters.

Here’s a minimal working example of everything I’ve tried so far:

from bokeh.plotting import figure, curdoc
from bokeh.models import Label

p = figure(
    width=550,
    height=250,
    x_range=(-50, 500),
    y_range=(-125, 125),
)

label = Label(
    x=0,
    y=0,
    text=(
        r"$$\upmu\mathrm{N}\mathrm{m}$$ "
        r"$$\mbox{µ}\mathrm{N}\mathrm{m}$$ "
        r"$$\text{µ}\mathrm{N}\mathrm{m}$$ "
        r"$$\mbox{µ}^\circ\mathrm{C}\Omega\mbox{Å}\%'''^\circ{\hbar}E_\mathrm{h}$$ " # These are all the special characters I need. Most of them do work like this.
    ),
)

p.add_layout(label)

curdoc().add_root(p)

Here’s a screenshot of the resulting plot:

As you can see, the problematic letters are rendered almost correctly, they’re just very small and overlap the other letters.

Does anyone know why this happens or how I might fix it?

Well the live demo on the MathJax site seems to render things properly (see below). That said, AFAIK all we do is immediately pass off LaTeX strings to MathJax to render so I am not sure how Bokeh could be causing any issue, either. It’s possible that Bokeh is using an old version of MathJax that had some bug in the past, in which case it might be as simple as updating to a newer MathJax version. But in any case it will take some investigation, so all I can suggest is to make a GitHub Issue with all these details. (Edit: and please, always include all relevant version information in any issue or help request)

OK a little more digging: Bokeh currently uses MathJax 3.2.2. Here is a pure HTML snippet that shows your content being mis-rendered, albeit in a different way, by MathJax 3.2.2.

<!DOCTYPE html>
<html>
<head>
<title>MathJax 3.2.2 Test</title>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-mml-chtml.js"></script>
</head>
<body>
$$\mbox{µ}^\circ\mathrm{C}\Omega\mbox{Å}\%'''^\circ{\hbar}E_\mathrm{h}$$
</body>
</html>

Then:

Screenshot 2025-11-24 at 14.25.57

So at a minimum it seems like it’s time to see if Bokeh can be updated to use MathJax 4.0 and hopefully that solves the issue.

1 Like

Ah sorry, I tried answering all of the questions in the “new topic” template and as that doesn’t include the version number, I forgot.

$ pip freeze
bokeh==3.8.1
contourpy==1.3.3
Jinja2==3.1.6
MarkupSafe==3.0.3
narwhals==2.12.0
numpy==2.3.5
packaging==25.0
pandas==2.3.3
pillow==12.0.0
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.3
six==1.17.0
tornado==6.5.2
tzdata==2025.2
xyzservices==2025.11.0

I tried with older versions too, and it didn’t make a difference.

I’ve created a github issue here: Some special chars in latex labels are not rendered correctly · Issue #14732 · bokeh/bokeh · GitHub

1 Like