Skip to content

BUG: KaTeX parse error on Jupyter Notebook when using underscore, etc. #6508

@fanurs

Description

@fanurs

Describe the issue:

I apologize if this was an intended feature implemented to reflect the demand of the PyMC community. But when I migrate my codebase from PyMC3 to PyMC5, this seems more like a bug to me; it didn't raise an error in PyMC 3.8.

Issue

When trying to display (not print) a PyMC model on Jupyter Notebook, I received a "KaTeX parse error". Apparently, this is due to the underscore character, _, in the name.

Reproduceable code example:

import pymc as pm
with pm.Model() as model:
    new_a = pm.Normal('new_a')
display(model) # on jupyter notebook

Error message:

ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 53: … \text{new_̲a} &\sim & \ope…

PyMC version information:

pip install pymc==5.0.2

Context for the issue:

Right now, I could bypass this error by adding a slash, \_, e.g. new\_a instead of new_a. But this is less desirable. For instance, I often have many variables that I would like to define. To do that, I would loop over some dictionary, and declare the variable one by one, while automatically assign them names that match the keys in the dictionary. However, with this "bug", I would either have to avoid using underscores at all or pre-process the names by replacing _ with \_.

More

Because of this parse error, I thought maybe I could write LaTeX syntax in my name field, or use raw string? But I don't think it works. Below are the things that I have tried:

  • pm.Normal(r'new_a') - I though raw string would "protect" the underscore from getting parse error, but it still raises the same error.
  • pm.Normal('\alpha') - Nope.
  • pm.Normal('\\alpha') - Nope.
  • pm.Normal('$\alpha$') - Nope.
  • pm.Normal('$\\alpha$') - Nope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions