Siunitx – Troubleshooting \sisetup{mode = match} Error with Tabularray

siunitxtabularray

For the MWE below, \sisetup{mode = match} throws the following error only if \square or \squared is used with a unit:

Missing $ inserted.

So, why does this happen?

\documentclass{article}
\usepackage[paperheight=68mm]{geometry}
%\usepackage{unicode-math}
\usepackage{xcolor,tabularx}
\usepackage{tabularray, siunitx}

\sisetup{mode = match} % results in an error only if \square or \squared is used

\UseTblrLibrary{booktabs,siunitx}
\NewColumnType{s}[1][]{Q[l, cmd=\sisetup{#1}\unit]}

\begin{document}
    
    \begin{longtblr}[
        caption = {The Caption},
        ]{
            width = 0.7\linewidth, 
            colspec = {
                Q[1.6,l]
                Q[0.4,c]
                S[
                table-format = 4.3e-1,
                parse-numbers = true,
                table-alignment-mode = none,
                table-number-alignment = right,
                exponent-mode = input,
                exponent-product = \times,
                round-mode = none,
                round-precision = 3,
                tight-spacing = true,
                ]
                s[%
                per-mode = symbol,
                bracket-unit-denominator,
                sticky-per%
                ]
            }, % <<<<<<<<<
            rowhead = 1,
            row{even} = {gray9},
            cell{1}{3} = {c=2}{c}, % multicolumn
        }

        Parameter & Symbol & {{{Value}}} &     \\
        two       & a      & 1.6         & \m\squared \\
    \end{longtblr}
    
\end{document}

Best Answer

Updated on 2021-09-15: This bug has been fixed. You may download the latest package file from https://github.com/lvjr/tabularray/raw/main/tabularray.sty or wait for version 2021P scheduled on 2021-10-01.

enter image description here


This is a bug of tabularray package. The following is a minimal example showing this bug:

(By the way, the s column is predefined in siunitx library since version 2021M. You don't need to and are not allowed to define s column again.)

\documentclass{article}

\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\sisetup{mode = match}

\begin{tblr}{s}
  \m\squared
\end{tblr}

\end{document}

This issue is related to the current limitation of cmd option (see #57). I will update this answer after I have fixed the issue.