TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


\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.

share|improve this question
up vote 2 down vote accepted

It seems unlikely that there is any TeX distribution anywhere that behaves differently because even though Knuth writes somewhere that this bit of code is system dependent, what you describe above is the 'sane' thing to do, far better than alternative, system-dependent options.

That does not necessarily mean that what this procedure produces is a valid file name according to the operating system, but that is a different question, I think.

share|improve this answer
Since you're probably more aware of these things than many TeX.sx users, I'll accept that answer, but it would be great if you have any references, or pointers to how I could test that (I only have access to TeXLive). – Bruno Le Floch Aug 9 '11 at 6:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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