5

With the 2020 fall update, the behaviour of \input{} changed. Before, I would have a main latex document (main.tex) and then the table contents in another file (table.tex) . Importantly, the file table.tex could be anywhere on my PC, because I could add directories that the \input command went through. So my set-up looked like this:

The main.tex document:

\documentclass[11pt, a4paper]{article}  

\makeatletter
\providecommand*{\input@path}{}
\g@addto@macro\input@path{{"C:/Users/me/inpath/"}}% \input finds files in this directory
\makeatother

\begin{document}

\begin{tabular}{lll}
\hline
\input{table.tex}
\hline
\end{tabular}

\end{document}

Then the file table.tex that would be placed in the directory "C:/Users/me/inpath/":

1 & 2 \\
3 & 4 \\

Unfortunately, this set-up no longer works. My question is: What is the best way to replicate this behaviour? For now, my solution would be to change the main.tex to:

\documentclass[11pt, a4paper]{article}      

\newcommand{\inpath}{"C:/Users/me/inpath/"}

\makeatletter\let\expandableinput\@@input\makeatother



\begin{document}

\begin{tabular}{lll}
\hline
\expandableinput{\inpath table.tex}
\hline
\end{tabular}



%%% Or alternatively
\begin{tabular}{lll}
\hline
\input \inpath table.tex
\hline
\end{tabular}

\end{document}

Is there a more elegant way to achieve this? A solution similar to how things worked before the latex fall update? In which I can tell the TeX primitive \@@input where to look for files? What I have found so far is the information here and here.

7

LaTeX's \input in tables was always tricky, because it was never expandable, then at the beginning of table cells it could not work properly sometimes, so it was never fully supported. This now breaks because the code for \input has to do some bookkeeping after the file is read (which didn't exist before), and that breaks the scanning for \noalign, then when \hline appears the \noalign appears where it's not expected to.

You can use an expandable \input using expl3's \file_full_name:n to do the lookup on \input@path, and \@@input to read the file in expandably. This is somewhat (but not entirely) equivalent to what LaTeX's \input used to do (without file hooks, of course):

\ExplSyntaxOn
\cs_new:Npn \expandableinput #1
  { \use:c { @@input } { \file_full_name:n {#1} } }
\ExplSyntaxOff

Here's the compilable example:

\begin{filecontents}{table.tex}
1 & 2 \\
3 & 4 \\
\end{filecontents}

\documentclass[11pt, a4paper]{article}

\ExplSyntaxOn % providing \expandableinput
\cs_new:Npn \expandableinput #1
  { \use:c { @@input } { \file_full_name:n {#1} } }
\ExplSyntaxOff

\makeatletter % setting your search path
\providecommand*{\input@path}{}
\g@addto@macro\input@path{{"C:/Users/me/inpath/"}}% \input finds files in this directory
\makeatother

\begin{document}

\begin{tabular}{lll}
\hline
% \input{table.tex}
\expandableinput{table.tex}
\hline
\end{tabular}

\end{document}

enter image description here

1
  • 1
    Thanks, very illuminating! – Max Feb 18 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.