TheoChem-VU / TCutility

Utility functions/classes for the TheoCheM programs
https://theochem-vu.github.io/TCutility/
MIT License
6 stars 0 forks source link

Issue with generating LaTeX and pyplot renderable molecular formulae #318

Closed YHordijk closed 1 month ago

YHordijk commented 1 month ago

When generating text for use with LaTeX or pyplot we run into an issue. For example:

>>> from tcutility import formula
>>> formula.molecule('NMe2*', mode='latex')
\mathrm{N}\mathrm{M}\\ma\mathrm{t}h\ma\mathrm{t}hrm{r}m{m}a\mathrm{t}\\ma\mathrm{t}h\ma\mathrm{t}hrm{r}m{m}a\mathrm{t}h\ma\mathrm{t}hrm{r}\ma\mathrm{t}h\ma\mathrm{t}hrm{r}m{m}{h}\ma\mathrm{t}hrm{r}\ma\mathrm{t}h\ma\mathrm{t}hrm{r}m{m}{e}_2^•

Which is of course nonsense. It should return instead \mathrm{N}\mathrm{M}\mathrm{e}_2^•. This then renders nicely as:

Screenshot 2024-10-08 at 10 44 32

The issue is due to the way we replace characters in the string to make them non-mathmode. This should be an easy fix luckily.