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

{:L~} can generate \mathrm{μ} which becomes blank when latex compiled #1962

Open
doronbehar opened this issue Apr 7, 2024 · 0 comments
Open

Comments

@doronbehar
Copy link

Here's a test case:

import pint
ureg = pint.UnitRegistry()

x = (1e-6 * ureg.meter).to_compact()
latex = "${:L~}$\n".format(x)
print("trying to compile latex code {}".format(latex))
with open("x.tex", "w") as xf:
    xf.write("\\documentclass{minimal}\n")
    xf.write("\\begin{document}\n")
    xf.write(latex)
    xf.write("\\end{document}\n")

import os
os.popen("pdflatex x.tex")

Note the unicode µ in what it prints when you run it, and how it compiles:

image

Whereas if I simply add a .replace("µ", "\\mu ") I get:

image

Which is better of course, but I guess not ideal, because the font is italic. I wonder if we should simply apply the above .replace here:

diff --git i/pint/delegates/formatter/latex.py w/pint/delegates/formatter/latex.py
index 476997b..84f05ac 100644
--- i/pint/delegates/formatter/latex.py
+++ w/pint/delegates/formatter/latex.py
@@ -198,8 +198,8 @@ class LatexFormatter(BaseFormatter):
             registry=self._registry,
         )
 
-        numerator = ((rf"\mathrm{{{latex_escape(u)}}}", p) for u, p in numerator)
-        denominator = ((rf"\mathrm{{{latex_escape(u)}}}", p) for u, p in denominator)
+        numerator = ((rf"\mathrm{{{latex_escape(u)}}}".replace("µ", "\\mu "), p) for u, p in numerator)
+        denominator = ((rf"\mathrm{{{latex_escape(u)}}}".replace("µ", "\\mu "), p) for u, p in denominator)
 
         # Localized latex
         # if babel_kwds.get("locale", None):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant