1

I have a problem when using the siunitx package, specifically when using the detect-all option and trying to use the \pi symbol as a number.

Minimum working example (MWE) below:

\documentclass{article}
\usepackage{XCharter}
\usepackage{siunitx}

\begin{document}

This works happily: \SI{2\pi e15}{\radian\per\second}

\sisetup{detect-all,}
But this gives an error : \SI{2\pi e15}{\radian\per\second}.

\end{document}
4
  • What does \sisetup{detect-all,} do?
    – Someone
    Commented Apr 21, 2020 at 14:16
  • \sisetup{detect-all} is an option for the siunitx package, which essentially makes all usage of numbers and units with the package "fit in" with the text around them. So while \SI{10}{m} will normally use whatever Maths font is loaded when used in the middle of a standard text section (which looks odd, in my opinion), it will instead change the font to the standard font if \sisetup{detect-all} is enabled.
    – bth-root
    Commented Apr 21, 2020 at 15:21
  • @bth-root - The explanation "it will instead change the font to the standard font" is not quite right. Rather, it's the current font -- which need not be a "standard" font -- that'll be used. What is "current" is determined at the start of the operation of the \SI macro.
    – Mico
    Commented Apr 21, 2020 at 16:06
  • 1
    @Mico - Thanks for the clarification. Mine was definitely a layperson's explanation - it's good to have the proper description down for posterity.
    – bth-root
    Commented Apr 22, 2020 at 8:53

2 Answers 2

1

If you run \sisetup{detect-all}, siunitx requires the entire \SI directive to be in math mode in order to process \pi correctly, i.e., it requires you to run

$\SI{2\pi e15}{\radian\per\second}$

On p. 5 of the package's user guide, one finds:

By default, all text is typeset in the current upright math font. This can be changed by setting the appropriate options: \sisetup{detect-all} will use the current font for typesetting.

What this means is that if detect-all is in force, siunitx does not automatically use a math font to generate the output of \SI and \si. Thus the need for the $ symbols.


enter image description here

\documentclass{article}
\usepackage{XCharter,siunitx}
\begin{document}
\SI{2\pi e15}{\radian\per\second}

\sisetup{detect-all}
$\SI{2\pi e15}{\radian\per\second}$
\end{document}
1
  • Just a follow on from this, as I wanted to avoid using a math font in the main text of my document: a once-off, slightly ugly fix was to input the "2pi" and "times" symbol separately from the rest of the SI macro, with appropriate spacing, as follows: 2\textpi\,$\times$\,\SI{e15}{\radian\per\second} (Doing so required loading the \textgreek package for the pi symbol.)
    – bth-root
    Commented Apr 22, 2020 at 12:26
1

The siunitx documentation suggests the following approach to add more valid symbols like pi in the section "Symbolic 'digits'":

\sisetup{input-digits = 0123456789\pi}

9.15 Symbolic ‘digits’

In some cases you may want to use ‘digits’ which do not fall within the usual set 0123456789. This can be done by setting the input-digits option, but bearing in 68mind that this will affect (prevent) for example rounding.

\sisetup{input-digits = 0123456789\pi}%
\num{4\pi e-7}
4π × 10−7

Each extra entry should be a single token, and should either have a definition which is safe in both math and text mode, or should only be used when the output mode is known. It may be necessary to make some tokens robust using etoolbox for this to work, for example

\robustify\dots
\sisetup{input-digits = 0123456789\dots}%
\qty{0,4066\dots}{\metre\squared}
0.406 6 ... m^2

You must log in to answer this question.

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