6

What I’m trying to do is to input Unicode characters directly inside siunitx commands, like \SIrange{≳9}{≈40}{\kilogram}. But it does not work and I get errors like ! Package siunitx Error: Invalid token '≳' in numerical input..

Looking further, inputing the standard command for these symbols does not work for all of them either: \SIrange{\gtrsim9}{\approx40}{\kilogram}; \gtrsim breaks but \approx is accepted.

Some MNWE:

\documentclass{standalone}

\usepackage{siunitx}
\usepackage{unicode-math}

\begin{document}
    \SIrange{≳9}{≈40}{\kilogram}\\
    \SIrange{\gtrsim9}{\approx40}{\kilogram}
\end{document}

Does what I’m trying to do makes any sense? Is there a way to do that?

1
  • 1
    I think the parser needs to know those in advance to support them. It does not handle all symbols by default only common ones. The ones you present here are not really common
    – daleif
    Mar 17, 2019 at 18:11

2 Answers 2

7

You can add other comparators to the default list:

\documentclass{article}

\usepackage{siunitx}
\usepackage{unicode-math}

\sisetup{
  input-comparators = {
    < = > \approx \ge \geq \gg \le \leq \ll \sim % default
    \gtrsim ≳ ≈
  },
}

\begin{document}

\SIrange{≳9}{≈40}{\kilogram}

\SIrange{\gtrsim9}{\approx40}{\kilogram}

\end{document}

enter image description here

2
  • Awesome, thanks. I guess there are reasons for the initial list being limited to those symbols? Like symbols origins (TeX/LaTeX/amssymb…) for the others or something in that vein?
    – Archange
    Mar 18, 2019 at 15:11
  • @ArchangeThe author added the most common comparators, I guess.
    – egreg
    Mar 18, 2019 at 15:32
5

You could set parse-numbers to false to allow arbitrary code in the number fields:

\documentclass{standalone}

\usepackage{siunitx}
\usepackage{unicode-math}

\begin{document}
  \SIrange[parse-numbers = false]{≳9}{≈40}{\kilogram}\\
  \SIrange[parse-numbers = false]{\gtrsim9}{\approx40}{\kilogram}
\end{document}

Or, you could declare the symbols explicitly in \sisetup:

\documentclass{standalone}

\usepackage{siunitx}
\sisetup{
  input-symbols=≈≳\gtrsim\approx
}
\usepackage{unicode-math}

\begin{document}
  \SIrange{≳9}{≈40}{\kilogram}\\
  \SIrange{\gtrsim9}{\approx40}{\kilogram}
\end{document}
1
  • 1
    parse-numbers=false has side effects I would prefer to avoid. input-symbols is good, but input-comparators from @egreg has even better semantical value. ;)
    – Archange
    Mar 18, 2019 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.