pint icon indicating copy to clipboard operation
pint copied to clipboard

Temperature units do not properly format as string

Open wgxli opened this issue 9 years ago • 4 comments

degC, degF, and degR (along with their delta-equivalents) are not properly formatted in Unicode, HTML, or LaTeX.

wgxli avatar Jul 09 '16 23:07 wgxli

We need to address this. Thanks for reporting

hgrecco avatar Jul 20 '16 03:07 hgrecco

Possibly related? I got a

ValueError: Unknown format code g for object of type 'str'

when trying to cast a temperature to string.

Needed to change

mstr = format(obj.magnitude, mspec).replace("\n", "")

to

mstr = format(float(obj.magnitude), mspec).replace("\n", "")

in quantity.py, __format__() (ca. line 300) to make it work.

eevleevs avatar Jul 09 '20 07:07 eevleevs

I have also realized that the LaTeX conversions for some units are wrong.

Steps to reproduce:

import pint
test = pint.Unit('celsius')
print(f'{test:L}')
print(f'{test:Lx}')

Output

\mathrm{degree\_Celsius}
\si[]{\degree_Celsius}

In LaTeX this renders completely wrong. The expected output would be:

For :L

\mathrm{\degree_C} or

Or better for :Lx

\si[]{\celsius}

Thanks for looking into this!

invarianz avatar Jul 02 '25 12:07 invarianz

a PR fixing this is welcomed

andrewgsavage avatar Jul 02 '25 13:07 andrewgsavage