1

I want to put units in an equation. Someone published a paper with units written that way. I need to mimic that. A simple case would be:

\begin{equation}
   a = \si{\ell}{(\cm)}
\end{equation}

or

\begin{equation}
   a = \si{\ell}{\cm}
\end{equation}

But both give Undefined control sequence. I think the problem is that I do not know how to use the package siunitx in an equation.

  • 2
    The \si command takes only one argument, which is the unit to print. If you want to print a number as well use \SI. To print non-numeric numbers (?) use \SI[parse-numbers=false]{\ell}{\cm}. What do you want the output to look like? – Phelype Oleinik Apr 17 at 20:31
  • Did you load siunitx? – Bernard Apr 17 at 20:32
  • @PhelypeOleinik Your solution worked. If you write it as an answer, I will accept it – wander95 Apr 17 at 20:36
2

The \si command takes only one argument, which is the unit to print. If you want to print a number as well use \SI{<number>}{<unit>}.

However, siunitx tries to parse the <number>, and when you give it \ell it tells you:

! Package siunitx Error: Invalid token '\ell ' in numerical input.

For immediate help type H <return>.
 ...                                              

l.5   a = \SI{\ell}{\cm}

? h

Numbers can only contain tokens defined using the 'input-...' options:
the token '\ell ' is not set up as a valid part of a number.

To have siunitx print a non-numerical input you can disable the parsing mechanism with parse-numbers=false:

\begin{equation}
  a = \SI[parse-numbers=false]{\ell}{\cm}
\end{equation}

or, if you're going to use it several times in the same equation:

\begin{equation}
  \sisetup{parse-numbers=false}
  a = \SI{\ell}{\cm}
\end{equation}
  • It turned out that a simpler solution in the equation environment is \ell \si{(\cm)} – wander95 Apr 17 at 20:45
  • @wander95 Note that the spacing is different, though. Try a = \ell\,\si{\cm}. – Phelype Oleinik Apr 17 at 20:50

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.