7

I am trying to typeset this table, but I keep running into the following error:

    ! Missing $ inserted.
<inserted text> $
l.34 ...{Global data expressed in \qty{e10}{\gram}
                                                  .\\%

My minimum working example is given below:

\documentclass[a4paper]{article}
\usepackage[sfdefault]{atkinson}
\usepackage{hyperref}
\usepackage{siunitx}
\sisetup{mode=text}
\sisetup{range-phrase=--}
\sisetup{range-units=single}
\sisetup{separate-uncertainty=true}
\sisetup{detect-all}
\sisetup{inter-unit-product=\ensuremath{{\cdot}}}
\sisetup{open-bracket=\, ,
                close-bracket=\,}
\sisetup{tight-spacing=true}
\DeclareSIUnit[number-unit-product = ]\percent{\%}
\usepackage{threeparttable}
\usepackage{booktabs}
\begin{document}
\begin{table}[h!]
\begin{threeparttable}
\caption{Estimated biomass.}
\begin{tabular}{l c c }
\toprule
\textbf{Family}&\textbf{Global}&\textbf{Local}\\
\midrule
Family1&8.8&4.5\\
Family2&10.7&3.4\\
Family3&10.7&2.6\\
Family4&11.8&3.2\\
Family5&15.4&5.1\\
Family6&17.4&3.9\\
Family7&31.2&7.4\\         
\bottomrule
\end{tabular}
\footnotesize{Global data expressed in \qty{e10}{\gram}.\\%
Local data expressed in \qty{e8}{\gram}.%
}
\end{threeparttable}
\end{table}
\end{document}

When I comment out the siunitx parts of the text, things work fine. Is there a setting I am missing?

4
  • 4
    A more minimal example that still produces the error message: \documentclass{article} \usepackage{siunitx} \sisetup{mode=text, tight-spacing=true} \begin{document} Global data expressed in \qty{e10}{\gram} \end{document}.
    – leandriis
    Oct 14, 2021 at 21:23
  • 2
    Removing either mode=text or tight-spacing=true seems to solve the problem. Apparently these clash for some reason (maybe one forces text mode, whereas the other requires math mode).
    – erik
    Oct 14, 2021 at 21:28
  • 4
    Looks like a bug in v3 - I see the source, I just have to work out a good fix
    – Joseph Wright
    Oct 14, 2021 at 21:54
  • @leandriss: My bad. I wasn't thinking straight when I posted this. Thank you.
    – Miloop
    Oct 15, 2021 at 7:12

1 Answer 1

3

This was caused by an ordering bug in siunitx: exactly how one deals with tight spacing and text mode is tricky. I've logged as https://github.com/josephwright/siunitx/issues/553. A temporary fix until that reaches CTAN:

\documentclass{article}
\usepackage{siunitx}
\sisetup{mode=text, tight-spacing=true}
\ExplSyntaxOn
\makeatletter
\cs_gset_protected:Npn \__siunitx_print_text_replace:n #1
  {
    \group_begin:
      \tl_if_head_eq_meaning:nNTF {#1} \mathchoice
        { \__siunitx_print_text_replace:Nnnnn #1 }
        {
          \tl_set:Nn \l__siunitx_print_tmp_tl {#1}
          \__siunitx_print_replace_font:N \l__siunitx_print_tmp_tl
          \cs_set:Npn \mathord ##1 {##1}
          \cs_set:Npn \pm { \exp_not:N \textpm }
          \cs_set:Npn \mp { \exp_not:n { \ensuremath { \mp } } }
          \cs_set:Npn \cdot { \exp_not:N \textperiodcentered }
          \cs_set:Npn \times { \exp_not:N \texttimes }
          \protected@edef \l__siunitx_print_tmp_tl { \l__siunitx_print_tmp_tl }
          \__siunitx_print_text_replace:N \l__siunitx_print_tmp_tl
          \tl_use:N \l__siunitx_print_tmp_tl
        }
    \group_end:
  }
\cs_gset_protected:Npx \__siunitx_print_text_replace:N #1
  {
    \exp_not:N \__siunitx_print_text_replace:NNn #1
      -
        { \exp_not:N \textminus }
      \char_generate:nn { `\_ } { 8 }
        { \exp_not:N \__siunitx_print_text_sub:n }
      ^
        { \exp_not:N \__siunitx_print_text_super:n }
      \exp_not:N \q_recursion_tail
        { ? }
      \exp_not:N \q_recursion_stop
  }
\makeatother
\ExplSyntaxOff
\begin{document}
Global data expressed in $\qty{e10}{\gram}$
\end{document}
3
  • There's also an issue with some custom created units using \DeclareSIUnit. For example, \DeclareSIUnit\mps{\meter/\second} which produce the error Undefined control sequence. \unit{\mps}. I am still haven't updated to the most recent version of siunitx (15/10/2021) as it is still unavailable on CTAN. Hopefully, the update would resolve this issue as well. Thanks for every effort made in your package.
    – hesham
    Oct 20, 2021 at 19:27
  • 1
    @hesham You've got a situation where you've mixed literal and macro units in a unit macro: this was never really supported and the changes in v3 mean it doesn't work. Either use a macro-based unit (\metre\per\second) in your abbreviation or put in the literals you want (m/s).
    – Joseph Wright
    Oct 21, 2021 at 7:08
  • I thought it was possible when I came across to test an old file of mine. But well you were right and the manual is pretty clear when I checked that part (page 14) "The ⟨symbol⟩ can contain literal input, other units, multiple prefixes, powers and \per, although literal text should not be intermixed with unit macros," which was actually there even before v3.
    – hesham
    Oct 22, 2021 at 9:08

You must log in to answer this question.

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