[Tex/LaTex] How to use siunitx with non numerical values

formattingsiunitx

I understand that something like \SI{5}{\meter\per\second} defines a certain space between the number (5) and units (m/s). What should I use if instead of a numerical quantity I want a variable: R m/s? \SI{R}{\meter\per\second} fails because it expect a number in first parameter, and R \si{\meter\per\second} or $R$ \si{\meter\per\second} show different space.

Which is the correct use?

\documentclass{standalone}
\usepackage{siunitx}
\sisetup{per-mode=symbol}
\begin{document}
\begin{tabular}{r}
\SI{5}{\meter\per\second}\\
$R$ \si{\meter\per\second}\\
R \si{\meter\per\second}\\
\end{tabular}
\end{document}

enter image description here

Best Answer

As others have commented, this is partly a style question. In terms of non-numerical input, you've got a couple of choices. You could add R as a 'symbol' to those that siunitx knows, but that will not always print in math mode. So I'd prefer the approach of turning off the number parser:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI[parse-numbers = false]{R}{\metre\per\second}
\end{document}

As egreg points out, to get italic output you'll need to set the math-rm option

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\SI[number-math-rm = \mathnormal, parse-numbers = false]{R}{\metre\per\second}
\end{document}

Turning off the parser forces math mode, but retains font control and also consistent spacing (so if you alter the setting for number-unit-separator it will be updated).

Related Question