web2c: \input filename caveats
4.5.3 '\input' filename caveats
-------------------------------
The quoting mechanisms just described come into play _after_ TeX has
tokenized and expanded the input. So, multiple spaces and tabs will
generally be seen as a single space, active characters such as '~' are
expanded first (generally causing an error), and so on. More examples
below.
On the other hand, various C library routines and Unix itself use the
null byte (character code zero, ASCII NUL) to terminate strings. So
filenames in Web2c cannot contain nulls, even though TeX itself does not
treat NUL specially.
Finally, the present Web2c implementation does '~' and '$' expansion
on NAME, unlike Knuth's original implementation. Thus:
\input ~jsmith/$foo.bar
will dereference the environment variable or Kpathsea config file
value 'foo' and read that file, extended with '.bar', in user 'jsmith''s
home directory. You can also use braces in the variable expansion, as
in '${foo}bar', if you want to follow the variable name with a letter,
numeral, or '_'.
(So another way to get a program to read a filename containing
whitespace is to define an environment variable and dereference it.)
In all the common TeX formats (plain TeX, LaTeX, ConTeXt, AMSTeX,
...), the characters '~' and '$' have special category codes, so to
actually use these in a document you have to change their catcodes or
use '\string'.