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

Formatting Exponents on Magnitudes #491

Closed
jdriordan opened this issue Mar 22, 2017 · 4 comments
Closed

Formatting Exponents on Magnitudes #491

jdriordan opened this issue Mar 22, 2017 · 4 comments

Comments

@jdriordan
Copy link

jdriordan commented Mar 22, 2017

units = pint.UnitRegistry()

s  = units.second
m  = units.metre

x = 1.23e100 * s**2 / m**0.5

print('Latex:   {x:~L}, \nUnicode: {x:~P}'.format(x=x))

gives

Latex:   1.23e+100 \frac{s^{2}}{m^{0.5}}, 
Unicode: 1.23e+100 s²/m⁰.⁵

where I would like/expect

Latex:   1.23 \times 10^{100}\ \mathrm{s}^{2}\mathrm{m}^{-0.5}, 
Unicode: 1.23×10¹⁰⁰ s²/m⁰⋅⁵

The changes are primarily in using explicit scientific notation as opposed to 'e' and also;

Latex:

  • no \frac for units
  • upright font for units

Unicode:

I know that some of the LaTeX issues are remedied by using the siunitx pacakge, but at least for my use case (jupyter), that's not an option as far as I'm aware.

Also, this problem is (somewhat) remedied by using uncertainties:
G=((6.674080000000001 ± 0.000000000000021)×10⁻¹¹) m³/kg/s²
but it would be nice if the mean and uncertainty should had separate exponents.

((6.674080000000001 ± 0.000000000000021)×10⁻¹¹) m³/kg/s²

I don't think anyone re-parses LaTeX or pretty unicode and so it shouldn't be an issue to change the output to make it more presentable. If this is agreeable as-is I'm happy to make a pull request.

@hgrecco
Copy link
Owner

hgrecco commented Apr 1, 2017

Thanks for your suggestion. The idea looks good to me. Submit a PR!

@JayPalm
Copy link

JayPalm commented Jul 9, 2019

I'd like to further suggest that {\times} is used instead of \times so that there is no space between the coefficient and the base.
Using the example above:

Latex:   1.23 {\times} 10^{100}\ \mathrm{s}^{2}\mathrm{m}^{-0.5}
 
Unicode: 1.23×10¹⁰⁰ s²/m⁰⋅⁵

vs

Latex:   1.23 \times 10^{100}\ \mathrm{s}^{2}\mathrm{m}^{-0.5}

Unicode: 1.23 × 10¹⁰⁰ s²/m⁰⋅⁵

@hgrecco
Copy link
Owner

hgrecco commented Jul 9, 2019

Agreed. Submit a PR

@hgrecco
Copy link
Owner

hgrecco commented Dec 3, 2019

Closing. Feel free to reopen.

@hgrecco hgrecco closed this as completed Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants