1

I have been using \sfrac inside of siunitx for a long time. Since recently, it does not work and I get bunch of errors. Can you suggest me what to do?

MWE:

\documentclass{minimal}
\usepackage{tikz,xfrac}

\usepackage{siunitx}
\DeclareSIPostPower\rooted{\sfrac{1}{2}}

\begin{document}

\si[per-mode=fraction]{\W\s\rooted\per\m\squared\per\K}

\end{document}
3
  • 1
    github.com/josephwright/siunitx/issues/558 went to CTAN yesterday to allow \sfrac as the fraction function. This one is more complicated: powers really should be real numbers (as they might need to be summed, etc.).
    – Joseph Wright
    Commented Nov 19, 2021 at 13:24
  • @JosephWright This is theoretically square root of a second, so 1/2 is more appropriate than 0.5. I did not completely understand your comment. Is this going to be fixed?
    – Pygmalion
    Commented Nov 19, 2021 at 16:19
  • 1
    I meant that the timing was 'interesting'. In terms of a fix, I have been meaning to cover conversion of decimals to fractions, but not just at the moment. I'll think about the specifics of this case, and see if there is a possible way to handle it. (I note that in a superscript, \sfrac{1}{2} is very similar to 1/2.)
    – Joseph Wright
    Commented Nov 19, 2021 at 16:28

1 Answer 1

3

The issue arises due to some internal handling of \text. As a work around, you can use

\DeclareSIPostPower\rooted{\text{\sfrac{1}{2}}}

which should keep your document working.


The issue itself is complex. In v2, siunitx resets all text and math mode font settings for each number/unit. That's quite 'expensive' when most of the time only math or text is needed. So for v3 I only set the math mode font with we are in math mode. That leaves needing to handle \text nested in math mode. To cover that, I apply the siunitx font settings if \text is found in math mode. However, \sfrac internally uses \text around each box, and that causes the issue here. I have handled it for the case fraction-command = \sfrac, but it's less clear how to do that for an arbitrary \sfrac nested inside math mode.

5
  • Thanks, this works. Please, if you ever implement a solution that does not require using \text, please leave the message here or provide new answer.
    – Pygmalion
    Commented Nov 20, 2021 at 10:38
  • I have just realised that your \text mode works well in when units in fraction mode, but when units in inline mode it looks completely disorted (huge slash). Any other workarounds?
    – Pygmalion
    Commented Feb 22, 2022 at 12:21
  • @Pygmalion Please ask a linked question with an example
    – Joseph Wright
    Commented Feb 22, 2022 at 12:25
  • 1
    I just realised that this is a problem of newtx, which makes sfrac really ugly. Nothing to do with siunitx.
    – Pygmalion
    Commented Feb 22, 2022 at 15:31
  • The link to new question for reference: tex.stackexchange.com/questions/634865/ugly-sfrac-with-newtx
    – Pygmalion
    Commented Feb 22, 2022 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .