bilby-dev / bilby

A unified framework for stochastic sampling packages and gravitational-wave inference in Python.
https://bilby-dev.github.io/bilby/
MIT License
68 stars 75 forks source link

Remove double-backslashes from latex labels passed to matplotlib. #837

Closed AlexandreGoettel closed 1 month ago

AlexandreGoettel commented 1 month ago

Addresses #836 As far as I can tell, the issue is due to a bug in bilby_pipe, but I noticed that there is already a function to remove matplotlib errors in bilby/core/result.py.

This PR simply adds a line to this function to convert "\" into "\".

Either way I think this is a good thing to have, as I can't think of a scenario where having "\" in a matplotlib latex string is a good idea.

AlexandreGoettel commented 1 month ago

Have you checked to see how this interacts with raw strings (e.g. r"$\mathcal{M}$")?

Not 100% what you mean but afaik a variable defined as a raw string just becomes a string (with different creation rules) i.e.: r"$\mathcal{M}$" == "$\\mathcal{M}$" will return True. The code above will work in both cases.

mj-will commented 1 month ago

Not 100% what you mean but afaik a variable defined as a raw string just becomes a string (with different creation rules) i.e.: r"$\mathcal{M}$" == "$\\mathcal{M}$" will return True. The code above will work in both cases.

Ah, I didn't know that, makes sense then :)