siunitx
siunitx copied to clipboard
Use prefixes outside unit command
I recently updated my siunitx package to version 3 (currently 3.0.11) and noticed that one of my files didn't compile anymore. This was due to the fact that I was using units with prefixes in equations like $42 \kilo\meter$
instead of like $42 \unit{\kilo\meter}$
. The latter works, the former does not and when looking this up in the documentation, I found that this was indeed due to the update to v3. The documentation states 'prefixes cannot now be given without units'. At least that's how I got the idea to try encapsulating it in \unit{}
.
I was now wondering if it is possible to have the first command work again in the future. Specifically I would find it confusing if I can keep using the option free-standing-units when loading the package so I'm able to use units outside of \unit{}
, but then not being able to use prefixes with these units. Below is a minimal (non-)working example. The first line after \begin{document}
is the problem, the second line is the solution. Maybe this is just me not using the package as intended, but in my opinion if the second line works, so should the first.
The issue is not just with \kilo
, it appears with \mega
, \micro
, \milli
, etc. as well. The compilation error is 'undefined control sequence'. Another possible 'solution' is using \DeclareSIUnit{\noop}{\relax}
followed by \newcommand{\kilo}{\unit{\kilo\noop}}
for every prefix you want to use (this is probably very bad practice or something, but it saved me from typing in \unit
for every time I used it already, which was a lot).
\documentclass{article}
\usepackage[free-standing-units]{siunitx}
\begin{document}
The road is $42~\kilo\meter$ long.
The road is $42~\unit{\kilo\meter}$ long.
\end{document}
Free standing units have only ever been intended to be used as single macros, so for your situation it was always expectedy you'd have
\DeclareSIUnit{\kilometre}{\kilo\metre}
in your preamble then use \kilometre
in the document body. The reason is that there's no good way of getting the spacing right for any more complex 'free standing' case, such as \metre\per\second\squared
.
Probably I should adjust the messaging here to be clearer
Thanks for the clarification, I'll try the suggestion and see how I'll do things. Should I close this then?