Problems with \input{table.tex}\hline after 2020 fall LaTeX release
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}
Using the primitive behaviour of TeX's \input
works. This can be used in LaTeX if you omit the braces around the filename, in which case LaTeX will fallback to the primitive.
You'll lose some of the niceties of LaTeX's file handling (no hooks, no utf8 support for filenames in pdfTeX, no spaces in filenames allowed, etc.) but just to input a table body I guess this should be fine.
Since the way LaTeX needs to test for an opening brace isn't expandable, you still can't use arbitrary contents in your table. The first row can't start with something needing \noalign
(so no rules here for example) and the first cell can't start with something needing \omit
(so no \multicolumn
here for example). If that is needed, instead of using \input
you'd have to directly call the primitive, which is named \@@input
in LaTeX (you'll either need \makeatletter...\makeatother
around your table or have to call it with \csname @@input\endcsname mytable1
).
\documentclass[]{article}
\begin{filecontents}{mytable1.tex}
a & 1 & 2\\
b & 1 & 2\\
\end{filecontents}
\begin{document}
\begin{tabular}{lcc}
\hline
\input mytable1
\hline
\end{tabular}
\end{document}