10

I want to have equations with units. For example, the Hooke's law in physics. There are 4 non-trivial ways as follows.

First Option

% first option
\documentclass[border=1cm,varwidth]{standalone}
\usepackage{siunitx,esvect}
\begin{document}
\SI[parse-numbers=false]{\vv F=-kx\hat{x}}{\newton}
\end{document}

enter image description here

Second Option (cannot be compiled)

% second option
\documentclass[border=1cm,varwidth]{standalone}
\usepackage{siunitx,esvect}
\begin{document}
\SI[parse-numbers=true]{$\vv F=-kx\hat{x}$}{\newton}
\end{document}

Third Option

% third option
\documentclass[border=1cm,varwidth]{standalone}
\usepackage{siunitx,esvect}
\begin{document}
$\vv F=-kx\hat{x}\,\si{\newton}$
\end{document}

enter image description here

Fourth Option

% fourth option
\documentclass[border=1cm,varwidth]{standalone}
\usepackage{siunitx,esvect}
\begin{document}
$\vv F=-kx\hat{x}$~\si{\newton}
\end{document}

enter image description here

Because the first one is not properly rendered in math font and the second one cannot be compiled, I have to choose between the last two. So which one is the recommended one?

  • According to point #12 in this page, your first solution is the correct one. – Rémi Peyre Sep 22 '18 at 11:26
  • Shouldn't that mean that #3 is the correct one? But it'd be nice to have something official explaining why. Or to figure out how to make #2 compile, so that siunitx can properly take care of the spacing, since that's one of its jobs. – Teepeemm Nov 29 '18 at 16:25
  • 4
    I would recommend not putting units with your equations, or at the very least not as is. Right now N looks like a variable or multiplicative factor, such that the units of this force would be square newtons. Consider also tex.stackexchange.com/a/166610/173134 – aoi Nov 29 '18 at 20:41
9
+500

From the documentation of siunitx (section 4.3):

Very often, numbers and units are given together. Formally, the value of a quantity is the product of the number and the unit, the space being regarded as a multiplication sign. The \SI macro combes the functionality of \num and \si, and makes this both possible and easy.

It follows that your first and second option are not supposed to give satisfactory results because the first argument of \SI is designed to take numbers but not formulas. Thus, you are right with your third and fourth option, to change to the use of \si to typeset the formula and connect it manually to the unit.

I assume you want the same space between the formula and the unit as one would get from \SI between a number and the unit. The space in \SI is given by the option number-unit-product. According to table 24 of the documentation, this option's default value is \,. Thus, the "recommended" way is your option 3:

\documentclass[border=1cm,varwidth]{standalone}
\usepackage{siunitx,esvect}
\begin{document}
$\vv F=-kx\hat{x}\,\si{\newton}$
\end{document}

One more quote from section 4.3 of the documentation:

The formatting methods will work with both math and text mode.

So it doesn't really matter whether you put \si inside or outside of math-mode, as long as you choose the appropriate space.

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.