1

In order to input data from a file into a tabular environment, the TeX macro \@@input has to be used (see this question), since \input is non-expandable. Why is it not possible to change the catcode in a tabular contained in a beamer frame, e.g.

\documentclass{beamer}

\begin{document}
\begin{frame}
  \begin{tabular}{c}
    \makeatletter \@@input file \makeatother
  \end{tabular}
\end{frame}
\end{document}

Although this does not give any errors, it only outputs @input file.

Why do I have to use \csname @@input\endcsname file (see David Carlisle's answer to this question)?

  • 1
    Works fine for me. Show a complete example. – Ulrike Fischer Feb 16 '20 at 23:19
  • @UlrikeFischer Ok, the problem is, that it is inside a beamer frame and catcode changing is not possible. Shall I delete the question? – EuklidAlexandria Feb 16 '20 at 23:30
  • 2
    It's much better to say, in the preamble, \makeatletter\newcommand{\expandableinput}[1]{\@@input #1\relax}\makeatother and use \expandableinput{file} in the document. This will work independently of the document class. – egreg Feb 16 '20 at 23:32
  • 2
    @EuklidAlexandria Do as egreg says. Just for an explanation: beamer frames collect their contents, so it's like you used a catcode change (\makeatletter) in the argument of a command, which does not work. – Phelype Oleinik Feb 16 '20 at 23:46
  • @PhelypeOleinik Ok, thank you! But shouldn't I delete the question since the catcode change does work outside a beamer frame? – EuklidAlexandria Feb 16 '20 at 23:54
  • @EuklidAlexandria No, you should add to your question a minimal example that demonstrates your issue, so that other users who try this will see that it doesn't work with beamer (this is why people here ask for minimal examples so much). You could use: \documentclass{beamer} \begin{document} \begin{frame} \begin{tabular}{c} \makeatletter\@@input file \makeatother \end{tabular} \end{frame} \end{document}, which is enough to demonstrate the problem. – Phelype Oleinik Feb 16 '20 at 23:57
  • @PhelypeOleinik Ok, thank you. Is it ok so? But isn't it a duplicate now? – EuklidAlexandria Feb 17 '20 at 00:10
  • @EuklidAlexandria Yes, much better now, thanks! Yes, it could be a duplicate (there are hundreds of questions whose answer is "beamer grabs the frame contents: use \begin{frame}[fragile]"), but I couldn't find one that seemed an okay duplicate. If you know of one, you can mark your own question as duplicate, if you like. Otherwise, you can leave it as is, no problem in that either. – Phelype Oleinik Feb 17 '20 at 00:13
  • @PhelypeOleinik Thank you very much! Sorry for the trouble. – EuklidAlexandria Feb 17 '20 at 00:47
  • @EuklidAlexandria No problem ;-) – Phelype Oleinik Feb 17 '20 at 00:50

1 Answers1

3

I wouldn't recommend using @-commands in the document body anyway.

If you plan to use \@@input, add

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

to your document preamble and use

\tableinput{file}

in the document.

Beware that this will create spurious spaces in other contexts.

egreg
  • 1,121,712