How to use LaTeX for variables names for PyMC model_to_graphviz?

I have a PyMC model and I really like the pm.model_to_graphviz(model=model) functionality. I would like to include that graphviz in a paper that I’m writing. However, that graphviz plots the raw variable names defined within the model (things like ‘mu_X’ and ‘sigma_X’) – is there a way to provide pm.model_to_graphviz with a dict mapping from raw variable name to LaTeX-formatted strings like r’\mu_{\rm X}’ and r’\sigma_{\rm X} ?

I tried creating a similar pymc model with LaTeX variable names for graphviz purposes but it doesn’t work:

with pm.Model() as model:
    
    mu_X = pm.Uniform(r'$\mu_{\rm X}$', lower=0,upper=1) 
    sigma_X = pm.Uniform(r'$\sigma_{\rm X}$', lower=0,upper=1)     

pm.model_to_graphviz(model=model)

The resulting model graphviz doesn’t translate the LaTeX – is there an easy way to make this work? (again I don’t need the latex variables for my actual model that runs for the fitting – just for a separate pymc model construction like above for graphviz purposes only)

image

See for instance graphs - Use Graphviz within *TeX - TeX - LaTeX Stack Exchange

In your Python code you can just “render” the dot file, and then you do anything you want with it, such as copy-pasting it into a tex file using the graphviz package, or converting it into the good old TikZ.

You could also get some elementary LaTeX-like formulae directly in your Python notebook, using the tab shortcut. But last time I tried that I got some headache with the unicode fonts