josephwright / siunitx

A comprehensive (SI) units package for LaTeX
LaTeX Project Public License v1.3c
356 stars 26 forks source link

Powers on units with 'tall' characters (i.e. ångström) are typeset higher than other powers #697

Closed lkkmpn closed 12 months ago

lkkmpn commented 1 year ago

When combining a unit whose symbol extends past the cap height of the font, like ångström (Å), with a power, the power is typeset relative to the top of the unit symbol, causing it to be typeset higher than powers on other units. If this is done in a longer paragraph, it causes the line where the unit is present to take up more height than other lines, leaving an undesired gap between lines.

MWE:

\documentclass{article}
\usepackage{siunitx}

\DeclareSIUnit{\angstrom}{\text{Å}}

\begin{document}
Reference output: m\textsuperscript{2}, A\textsuperscript{2}, Å\textsuperscript{2}

\textsf{siunitx} output: \unit{\metre\squared}, \unit{\ampere\squared}, \unit{\angstrom\squared}
\end{document}

(I know the ångström is deprecated in siunitx and there are probably not many other units with accents, but I feel this would still be a reasonable change to include given it is still a fairly common unit in some fields.)

daleif commented 1 year ago

You probably cannot check if a letter has an accent from a code point of view, but since Å has to be manually defined one can always do

\DeclareSIUnit{\angstrom}{\text{\smash{Å}\vphantom{A}}}
josephwright commented 1 year ago

The reference rendering here should I think be

Reference output: $\mathrm{m}^{2}$, $\mathrm{A}^{2}$, $\mathrm{\textrm{Å}}^{2}$

which shows exactly the same effect as TeX is adjusting the superscript height for the taller letter.

lkkmpn commented 1 year ago

Ah, I didn't realize that siunitx uses math mode internally for unit typesetting. Would you say the raised superscript is a desirable output, though?

@daleif Thanks for the suggestion, I didn't think of using \smash as a workaround.

josephwright commented 12 months ago

I think that as the output matches the reference, this is something that should work as-now: I'll think about whether to add a hint about adjustments for those who feel this appearance is desirable.