2

My general goal is to have a table with all S columns. While debugging, I came to these minimal examples which now almost seem too simple.

Working as expected:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\begin{tabular}{Sc}
1&2\\
\end{tabular}
\end{document}

This fails with a quite obscure error message:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\begin{tabular}{Sc}
\input{\jobname-example_content.tex}
\end{tabular}
\end{document}

Error message:

! Extra }, or forgotten $.
<recently read> }

l.11 \end
         {tabular}
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
<argument> ...{\scan_stop: \c_math_toggle_token }}

l.11 \end
         {tabular}
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Missing $ inserted.
<inserted text> 
                $
l.11 \end
         {tabular}
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.11 \end
         {tabular}
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.11 \end
         {tabular}
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing control sequence inserted.
<inserted text> 
                \inaccessible 
l.11 \end
         {tabular}
Please don't say `\def cs{...}', say `\def\cs{...}'.
I've inserted an inaccessible control sequence so that your
definition will be completed without mixing me up too badly.
You can recover graciously from this error, if you're
careful; see exercise 27.2 in The TeXbook.

! I can't find file `{test2-example_content.tex}'.
<to be read again> 
                   \color_group_end: 
l.11 \end
         {tabular}
(Press Enter to retry, or Control-D to exit)
Please type another input file name
! Emergency stop.

However, these examples all work well:

\documentclass{article}
\usepackage{siunitx}

\begin{filecontents*}{\jobname-example_content.tex}
1&2\\
\end{filecontents*}

\begin{document}
\begin{tabular}{cS}
\input{\jobname-example_content.tex}
\end{tabular}
\end{document}
\documentclass{article}
\usepackage{siunitx}

\begin{filecontents*}{\jobname-example_content.tex}
1&2\\
\end{filecontents*}

\makeatletter
\newcommand{\expinput}[1]{\@@input #1}
\makeatother

\begin{document}
\begin{tabular}{Sc}
\expinput{\jobname-example_content.tex}
\end{tabular}
\end{document}

In summary, the problem only occurs if I input values from file and the first column is an S column.

This is my version information:

$ pdflatex -version
pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019)

Related questions:

  • The workaround with \@@input stems from an answer to one of my previous questions.
  • A similar question was raised here. However, many different aspects were intertwined there and the only answer contains a version which does not use \input.
2
  • Are you sure that the issue you're encountering is limited to cases where the first column has type S? FWIW, I can replicate the issue you encounter for both \begin{tabular}{Sc} and \begin{tabular}{cS}.
    – Mico
    May 3, 2020 at 11:01
  • @Mico: I just checked again: cS works whereas Sc does not.
    – Lukas
    May 3, 2020 at 11:45

1 Answer 1

2

Just change \input{\jobname-example_content.tex} to \protect\input{\jobname-example_content.tex} or, better still, \protect\input\jobname-example_content.

This is necessary because the S column type by default parses its inputs in various sophisticated ways, making its argument "fragile" (in the LaTeX-specific sense of the word). Sure enough, if you execute \sisetup{parse-numbers=false}, the \protect directive wouldn't be needed.

\documentclass{article}
\begin{filecontents*}[overwrite]{\jobname-example_content.tex}
1&2\\
\end{filecontents*}
\usepackage{siunitx}
\begin{document}

% Either one of the two following methods "works":

\begin{tabular}{Sl}
\protect\input\jobname-example_content
\end{tabular}

\sisetup{parse-numbers=false}
\begin{tabular}{Sc}
\input\jobname-example_content % observe: no \protect instruction
\end{tabular}

\end{document}
3
  • I think you answer points in the right direction. It is essentially similar to the \@@input method I have in the question. However, you answer effectively disables S column behavior in the first cell. All other cells still have S column behavior, e.g., grouping digits... Can I consider the behavior here a bug and just live with one of the workarounds?
    – Lukas
    May 3, 2020 at 11:47
  • @Lukas - I'm not sure if it's a bug or not. Maybe the author/maintainer, Joseph Wright, who is also a moderator of the TeX.SE site, will notice this posting and be able to provide a more definitive diagnosis.
    – Mico
    May 3, 2020 at 14:04
  • Good hint. Let's see if we get more insights.
    – Lukas
    May 3, 2020 at 15:25

You must log in to answer this question.

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