# Parsing a file name

What is the precise syntax for file names in various common distributions?

This is relevant for three primitives:

• \input<filename> (renamed \@@input in LaTeX)
• \openin<4-bit number><equals><filename>
• \openout<4-bit number><equals><filename>

where <4-bit number> is an integer between 0 and 15, and is any number of spaces, followed by an optional explicit catcode-other = token.

Testing with TeX Live 2011, I find the following: tokens are fully expanded one by one (just as everywhere else in TeX, with the get_x_token procedure). If the token found is an explicit or implicit character token, then the catcode is ignored, and the character is appended to the filename being built. A space with any catcode ends the filename and is gobbled. Any non-expandable non-character token ends the filename and remains.

Examples:

\makeatletter
\def\test{test}
\tracingall        % To see when spaces occur.
\openin4=\test     % Opens "test.tex"
\openin4=\bgroup \test \space \space % Opens "{test.tex", one space left.
\openin4=test\@sptoken \space        % Opens "test.tex", one space left.
\openin4="test \space test"          % Opens "test test.tex" in some distributions.


A remaining subtlety is that since \input is expandable and \openin and \openout are not, they behave slightly differently when appearing as the first token of a tabular cell. But that's another story.

-