Skip to content

BUG: fix extraneous space in LaTeX repr for Quantity objects with superscript units - #16043

Merged
mhvk merged 2 commits into
astropy:mainfrom
neutrinoceros:units/bug/deg_to_latex
Feb 18, 2024
Merged

mhvk merged 2 commits into
astropy:mainfrom
neutrinoceros:units/bug/deg_to_latex

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

Fixes #14385
Special casing seems simple enough here. Maybe the check should be more fine tuned so that composite units that have deg as their first element also follow this special path ? I just assumed this wasn't desired.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions github-actions Bot added the units label Feb 14, 2024
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@pllim pllim added this to the v6.1.0 milestone Feb 14, 2024
@pllim pllim added the Bug label Feb 14, 2024
@neutrinoceros
neutrinoceros marked this pull request as ready for review February 14, 2024 17:46
Comment thread astropy/units/quantity.py Outdated
delimiter_left, delimiter_right = formats[format][subfmt]

return rf"{delimiter_left}{latex_value} \; {latex_unit}{delimiter_right}"
if self.unit == Unit("deg"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we probably then also should do "arcmin", "arcsec", and "hourangle"

And this is of course not the first time we are dealing with this - as you note, you don't want to do it for composite units, or if the unit is raised to some power....

How about the following hack?

# Add a space in front except for super-script units like degrees.
if not latex_unit.startswith("{}^") or unit is u.deg_C:
    latex_unit = r"\;" + latex_unit

and then remove the \; below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course ! sorry for not thinking of other angular units. I've extended the test and refactored the code based on your suggestion

@neutrinoceros
neutrinoceros force-pushed the units/bug/deg_to_latex branch 2 times, most recently from fe73492 to 3e436d2 Compare February 15, 2024 08:23
@neutrinoceros neutrinoceros changed the title BUG: fix extraneous space in LaTeX repr for Quantity expressed in degrees BUG: fix extraneous space in LaTeX repr for Quantity objects with superscript units Feb 15, 2024

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, had lost track of this one - now looks all good!

@mhvk
mhvk merged commit 9627dad into astropy:main Feb 18, 2024
@neutrinoceros
neutrinoceros deleted the units/bug/deg_to_latex branch February 18, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quantity latex representation of degrees has extraneous space

3 participants