compose string from \newcommand macros

I create a new macro

``````\newcommand\var{test}
``````

I would like to use the macro to compose a string, e.g. as in

``````\input{the\varfile.txt}
``````

It now looks as if we have a new macro `\varfile`. How to separate the title of the macro from ordinary text? Is inserting a space the recommended solution as in:

``````\input{the\var file.txt}
``````

I suppose nothing would be necessary if the variable name was followed by a symbol that cannot make part of a macro name e.g. a dot `.`.

• The short answer is: yes. TeX ignores any space after a control sequence name, so `the\var file.txt` produces `thetestfile.txt`. – Phelype Oleinik Jun 12 '18 at 13:54
• it's almost the only solution, other ways to terminate a macro when typesttng eg `\var{}file` would not work here (they would put `{}` into the file name) – David Carlisle Jun 12 '18 at 14:06