# Why is \input not expandable?

In latex.ltx I found \def\input{\@ifnextchar\bgroup\@iinput\@@input} where \@@inputis expandable. I would like to know if there is an expandable version of \input.

The problem comes from an example with my package alterqcm.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\newcommand*{\square}{\vbox{\hrule\hbox to 6pt{\vrule height 5.2pt \hfil\vrule}\hrule}}%
%  \usepackage{fourier} % \square is defined with fourier
\usepackage{alterqcm}

\begin{document}
\begin{alterqcm}
\AQmessage{Soit $h$ la fonction telle que: $h:x\longmapsto x(x-1)$.}

\AQquestion{Par cette fonction: L'image de}{
{4 est 8},
{0 est 2},
{8 est 4},
{2 est 0}
}
\end{alterqcm}
\end{document}


Now it's possible to put the question in a file named 'question_1_2.tex'

  \AQmessage{Soit $h$ la fonction telle que: $h:x\longmapsto x(x-1)$.}
\AQquestion{Par cette fonction: L'image de}{
{4 est 8},
{0 est 2},
{8 est 4},
{2 est 0}
}


Now

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\newcommand*{\square}{\vbox{\hrule\hbox to 6pt{\vrule height 5.2pt \hfil\vrule}\hrule}}%
\usepackage{alterqcm}

\begin{document}
\begin{alterqcm}
\input{question_1_2.tex}
\end{alterqcm}
\end{document}


gives an error \omit misplaced. I need to write :

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\newcommand*{\square}{\vbox{\hrule\hbox to 6pt{\vrule height 5.2pt \hfil\vrule}\hrule}}%
\usepackage{alterqcm}

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

\begin{document}
\begin{alterqcm}
\ExpandableInput{question_1_2.tex}
\end{alterqcm}
\end{document}


1) Is it possible to use another macro or version of \input?

2) Why does the error disappear if I put

 \begin{alterqcm}
...
\end{alterqcm}


inside question_1_2.tex?

The LaTeX \input command, by Lamport's choice, must support both

\input{file}


and

\input file


so it's necessary to define it in that way: a test on the following character is necessary as the primitive \input scans its argument in a very peculiar way.

If you don't want to support the original syntax inside your environment, then putting

\def\input#1{\@@input #1 }


in the environment's definition is OK (unless a very devious user writes \input file inside the file that's input), and should not give problems of "Misplaced \omit".

The problem is caused by the fact that the \input file starts with \AQmessage that I understand is doing a \multicolumn: it's too late for it with the kernel definition of \input, because \multicolumn must come first in a table cell (it's \omit, actually, which is produced as the first token by \multicolumn); but the code for doing the business of \input is already there.

Why the problem does not show when the environment is inside question_1_2.tex? Well, the alignment begins inside the file, when \input has already done its service.

• Perhaps you could add that \omit must appear as the first token in an alignment cell, after expansion. – Bruno Le Floch Feb 1 '12 at 0:52
• Also, \input using LaTeX syntax will search for a file before trying to input it, which does not happen with TeX syntax. That is again non-expandable. – Joseph Wright Feb 1 '12 at 10:54