# Does the concatenation of two text files, which compile under tex, always compile under tex?

In other words, does the set of all text files that compile under tex form a monoid under concatenation?

I have recently dabbled a bit in plain tex and my algebraic spider senses were immediately tingling. I thought I'd google the answer with ease, but so far I have found nothing.

First, a plain tex file ends by \bye (and a latex file ends by \end{document}), and everything after this is ignored. So your statement is trivially correct, since the second file is ignored after concatenation.

If we consider \bye to be a "metacommand", dropped in a concatenation, then your statement is incorrect.

Consider the files

\def\aa{0}
\aa
\bye


and

\def\bb{0}
\bb
\ifx\aa\bb\cc\fi
\bye


Each of them compiles, but the concatenation does not:

\def\aa{0}
\aa
\def\bb{0}
\bb
\ifx\aa\bb\cc\fi
\bye


produces

! Undefined control sequence.
l.5 \ifx\aa\bb\cc
\fi
?
! Emergency stop.


The reason is, undefined \aa is undefined in the second file, but is the same as \bb in the concatenated one.

• Only a nitpicking remark: in the second file \aa is not \relax, it's simply undefined, as far as \ifx is concerned. The test \ifx\UnDeFiNeD\relax returns false, if \UnDeFiNeD is undefined. – egreg Jul 28 '15 at 23:05
• I stand corrected. PS. It was great to see you in Darmstadt! – Boris Jul 29 '15 at 0:23

In plain TeX a properly formatted file will end in \bye to tell the compiler to stop looking for input. Therefore the concatenation will only compile the first file then the rest is ignored.. (So no.) In LaTeX, a compilable file will end in \end{document} again to tell the compiler it is done. So only the first file in the concatenation will compile and the rest is ignored. Plus the second file will have a preamble now in an location which would cast a compiling error if i was seen. (So no.)

Not discussed are additional impacts of packages, fonts, inputted file, etc.