Skip to content

Quantity.to_string() should allow unicode format #14386

Open

Description

@mhvk

What is the problem this feature will solve?

Currently, units can be typeset in unicode, but Quantity cannot. However, Angle.to_string does support unicode.

Describe the desired outcome

That the .to_string() methods of Unit, Quantity, and all Quantity subclasses such as Angle support as much as possible the same arguments.

Additional context

See #14379

EDIT: A tricky bit is that for inline=False, i.e., when the units are typeset as a fraction, one needs to add the correct number of spaces, otherwise one still gets what used to happen with __format__ (#14398):

import astropy.units as u
q = 10*u.m/u.s
print(f"{q:unicode}")
10.0  m
 ─
 s

Also not obvious is what should happen for the case that the quantity is an array; but at least inline=True should be possible.

EDIT (2024-01-11): the :unicode formatting now typesets the unit in-line, so it is less broken, though numbers in arrays are not typeset using unicode, unlike for latex.

10.0 m s⁻¹
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions