[Tex/LaTex] Problems with \input{table.tex}\hline after 2020 fall LaTeX release

hlineinputtables

Since updating to the 2020 Fall release (MikTeX on Windows but also tested with TeXLive), I can no longer compile files where tables are imported from an external file using \input and followed by \hline (or \bottomrule).

Things work perfectly with older releases.

Note that it works if the last \\ is outside the file to be imported, but this is not a feasible option if the tables are created automatically from other softwares.

Here is a MWE:


\begin{document}

\begin{table}
  \caption{Table in text}
  \begin{tabular}{lcc}
    a & 1 & 2\\
    b & 1 & 2\\
    \hline
  \end{tabular}
\end{table}

\begin{table}
  \caption{Table in other file 1}
  \begin{tabular}{lcc}
    \input{table1}
    \hline
  \end{tabular}
\end{table}

\begin{table}
  \caption{Table in other file 2}
  \begin{tabular}{lcc}
    \input{table2}\\
    \hline
  \end{tabular}
\end{table}

\end{document}

with external files:

table1.tex:

    a & 1 & 2\\
    b & 1 & 2\\

table2.tex:

    a & 1 & 2\\
    b & 1 & 2

Here is the log when it fails:

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.10)
entering extended mode
(MWE.tex
LaTeX2e <2020-10-01> patch level 1
L3 programming layer <2020-10-05> xparse <2020-03-03>
("C:\Program Files\MiKTeX\tex/latex/base\article.cls"
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
("C:\Program Files\MiKTeX\tex/latex/base\size10.clo"))
("C:\Program Files\MiKTeX\tex/latex/l3backend\l3backend-pdftex.def") (MWE.aux)
(table1.tex)
! Misplaced \noalign.
\hline ->\noalign 
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.18     \hline
               
! You can't use `\hrule' here except with leaders.
\hline ->\noalign {\ifnum 0=`}\fi \hrule 
                                         \@height \arrayrulewidth \futurelet...
l.18     \hline
               
! Missing number, treated as zero.
<to be read again> 
                   \futurelet 
l.18     \hline
               
! Illegal unit of measure (pt inserted).
<to be read again> 
                   \futurelet 
l.18     \hline
               
(table2.tex) [1{C:/Users/Gouel/AppData/Local/MiKTeX/pdftex/config/pdftex.map}]
(MWE.aux) )
(see the transcript file for additional information)<C:/Program Files/MiKTeX/fo
nts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on MWE.pdf (1 page, 14750 bytes).
Transcript written on MWE.log.

With an older release under Linux, it works perfectly:

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./MWE.tex
LaTeX2e <2020-02-02> patch level 2
L3 programming layer <2020-02-14>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def)
(./MWE.aux) (./table1.tex) (./table2.tex) [1{/var/lib/texmf/fonts/map/pdftex/up
dmap/pdftex.map}] (./MWE.aux) )</usr/share/texlive/texmf-dist/fonts/type1/publi
c/amsfonts/cm/cmr10.pfb>
Output written on MWE.pdf (1 page, 13788 bytes).
Transcript written on MWE.log.

Best Answer

Yes, LaTeX changed here, but it also added new environments hooks, and you could use them to change to the primitive input in all tabular, This would have the additional benefit, that it will also work, if the file starts with a \multicolumn.

(That the engine accepts a braced input is rather new too).

\documentclass{article}

\begin{filecontents}{table1.tex}
a & 1 & 2\\
 b & 1 & 2\\
\end{filecontents}    

\makeatletter
%primitive input in tabular
\AddToHook{env/tabular/begin}{\let\input\@@input}
\makeatother
\begin{document}
\begin{tabular}{lcc}
    \input{table1}
    \hline
  \end{tabular}
\end{document}
Related Question