6

I am trying to make use of the \unit macro that is described on page 6 of the siunitx user manual and the compiler tells me that I have an undefined control sequence.

\unit{\kilo\gram\metre\per\square\second}

I have added the siunitx package to the tex file, and other macros in the package such as \num and \ang work.

Any ideas as to why I am getting this error would be greatly appreciated.

4
  • Works ok here. Are you sure you have installed the latest version and that you do not use the units package also?
    – Rmano
    Commented Jun 15, 2021 at 19:50
  • I am using overleaf, and so i would assume that everything there is up to date, I do have alot of other packages installed however, but not units. Commented Jun 15, 2021 at 19:52
  • overleaf is not up-to-date, they use texlive 2020. Commented Jun 15, 2021 at 19:53
  • 3
    Overleaf is not updated to the last --- it's frozen on TeXLive 2020 now, so they have siunitx v2. Change \unit{} to \si{}...
    – Rmano
    Commented Jun 15, 2021 at 19:53

1 Answer 1

8

It sounds like you have v2 available: I re-worked the document commands for v3. You could use the v2 command \si, or if you want your input to use the v3 interfaces, we can do a bit of work to set up \unit:

\documentclass{article}
\usepackage{siunitx}
\ifdefined\unit\else
  \ifdefined\NewCommandCopy
    \NewCommandCopy\unit\si
  \else
    \NewDocumentCommand\unit{O{}m}{\si[#1]{#2}}
  \fi
\fi
\begin{document}
\unit{\kilo\gram\metre\per\square\second}
\end{document}

(This should work with any release of siunitx since v2.0: if you only have v1, life gets more interesting! But that would mean a pre-2009 LaTeX installation.)

1
  • I couldn't figure out why the same document worked on my PC but not on my Mac - the Mac Tex Live Utility had auto updated to v2. This solution worked and made the document portable! Thanks! Commented Nov 4, 2021 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .