Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix latex rendering of variables with underscore in name #7501

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

Dekermanjian
Copy link
Contributor

@Dekermanjian Dekermanjian commented Sep 11, 2024

Description

I added a simple fix to LaTeX Repr that escapes variables that have underscores in them and I created a unit test to test the fix.

Related Issue

Checklist

  • Checked that the pre-commit linting/style checks pass
  • Included tests that prove the fix is effective or that the new feature works
  • Added necessary documentation (docstrings and/or example notebooks)
  • If you are a pro: each commit corresponds to a [relevant logical change]

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7501.org.readthedocs.build/en/7501/

@Dekermanjian
Copy link
Contributor Author

Dekermanjian commented Sep 11, 2024

Hey @ricardoV94, I added a simplistic fix to address the underscores breaking the KaTeX output in VSCode and Jupyter. I tested in VSCode and Jupyter Lab. Are there any other environments I should test it out in?

Hmm actually, it is not working now in Jupyter for me. Let me figure out what happened.

Oh never mind, I was just not selecting the proper environment. It does work in Jupyter Lab.

@Dekermanjian
Copy link
Contributor Author

Dekermanjian commented Sep 14, 2024

Hey @twiecki, I think some of the tests failed because they expect the LaTeX representation of underscores to be unescaped. Would it be okay, to modify those tests so that they expect underscores for LaTeX to be escaped?

@twiecki
Copy link
Member

twiecki commented Sep 14, 2024

Hey @twiecki, I think some of the tests failed because they expect the LaTeX representation of underscores to be unescaped. Would it be okay, to modify those tests so that they expect underscores for LaTeX to be escaped?

Yes.

… fixed testing to expect underscores in LaTeX representation to be escaped
@Dekermanjian
Copy link
Contributor Author

Hey @twiecki, I applied the underscore escaping function to also work at the distribution level within a model. So both calling objects holding distributions or calling the entire model will escape underscore variables for LaTeX representation. I also changed the expected string objects in the testing script to expect that underscores in LaTeX be escaped.

Copy link

codecov bot commented Sep 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.43%. Comparing base (d596afb) to head (4156804).
Report is 14 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7501      +/-   ##
==========================================
+ Coverage   92.16%   92.43%   +0.26%     
==========================================
  Files         103      103              
  Lines       17200    17109      -91     
==========================================
- Hits        15853    15814      -39     
+ Misses       1347     1295      -52     
Files with missing lines Coverage Δ
pymc/printing.py 87.41% <100.00%> (+0.43%) ⬆️

... and 19 files with indirect coverage changes

@twiecki twiecki merged commit af5ea5c into pymc-devs:main Sep 16, 2024
22 checks passed
Copy link

welcome bot commented Sep 16, 2024

Congratulations Banner]
Congrats on merging your first pull request! 🎉 We here at PyMC are proud of you! 💖 Thank you so much for your contribution 🎁

aphc14 pushed a commit to aphc14/pymc that referenced this pull request Sep 17, 2024
pymc-devs#7501)

* implemented fix for escaping underscores in latex repr and added a unit test

* updated unit test staticmethod to include underscore in var name

* add underscore escape fix to distribution repr as well as model repr, fixed testing to expect underscores in LaTeX representation to be escaped

* added cleaner method using re to escape underscores, added cleaner test to assert underscores are escaped
@ricardoV94 ricardoV94 changed the title implemented fix for escaping underscores in latex repr and added a un… Fix latex rendering of variables with underscore in name Oct 2, 2024
@ricardoV94 ricardoV94 added the bug label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: KaTeX parse error on Jupyter Notebook when using underscore, etc.
3 participants