[Tex/LaTex] Siunitx 3 on Overleaf with TeX Live 2020

overleafsiunitx

This question is a follow-up on Siunitx V3 on Overleaf.

I am trying to use version 3 of the siunitx package on Overleaf (TeX Live 2020). After adding the siunitx.sty, as recommended in the previous question, I get compilation errors associated with commands such as

\NewDocumentCommand \DeclareBinaryPrefix { +m m m }

in siunitx. The generated PDF also displays these lines on the top of the page :
enter image description here

I created a new Overleaf project, added the siunitx.sty file, and the main.tex file is simply

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}

\begin{document}

This is a test : \qty{5}{\percent}

\end{document}

When removing the version 3 file and changing the \qty to \SI to accommodate the version 2 included in TeX Live 2020, everything runs as expected.

Best Answer

Update

The specific problem that prevented v3.0.22 from compiling nicely with the older TeX Live 2020 on Overleaf was resolved in v3.0.23 (2021-07-26) of siunitx.

The code siunitx loading xparse if it is not yet in the kernel came in a tad too late for some \NewDocumentCommands. See https://github.com/josephwright/siunitx/issues/518.

So grab version v3.0.23 or above from CTAN and you should be fine.


Old answer

There is absolutely no guarantee that this will work, but the primary issue appears to be that \NewDocumentCommand is undefined. That command was recently-ish moved from the xparse package to the LaTeX kernel. In older systems you may have to load \usepackage{xparse}.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xparse}
\usepackage{siunitx}

\begin{document}
This is a test: \qty{5}{\percent}
\end{document}

compiles for me. At least with the siunitx.sty available from .tds.zip from CTAN (http://mirrors.ctan.org/install/macros/latex/contrib/siunitx.tds.zip) (v3.0.22 from 2021-07-22).

See https://www.overleaf.com/read/mwpxvvhrjwvz.

Related Question