# Texlive's TeX vs Knuth's TeX

From texmf.cnf:

% But don't parse the first line if invoked as"tex", since we want that
% to remain Knuth-compatible.  The src_specials and
% file_line_error_style settings, as well as the options -enctex,
% -mltex, -8bit, etc., also affect this, but they are all off by default.
parse_first_line.tex = f
parse_first_line.initex = f


Since there are settings to make TeX compatible with Knuth's version this means that the version of tex that texlive ships is not the same as Knuth's original one.

But as far as I know TeX's license says that you must change the name if you modify the program. So why is the program that texlive ships allowed to be called TeX?

• I'm not sure I understand. The settings you showed above ensure that settings applied throughout all engines are not applied to (INI)TeX, precisely so that they remain Knuth-compatible. – Phelype Oleinik Jun 3 at 16:48
• The build setup adds extra 'stuff' to most engines - this skips some of that – Joseph Wright Jun 3 at 16:52
• @M0M0 You are not allowed to modify tex.web without changing the name, but there is a mechanism of so called change file to change the code without changing tex.web. Actually TeX can't be used without such modifications since they are needed to provide implementations of system dependent functions (e.g. opening files, showing output, reading input, ...) The result can be called TeX as long as it behaves like TeX. The setting ensures that it does. – Marcel Krüger Jun 3 at 16:57
• @MarcelKrüger And “behaving like TeX” means “passing the TRIP test”. – egreg Jun 3 at 17:09
• @egreg That and "[t]he person who wrote it must be happy with the way it works at his or her installation". – Marcel Krüger Jun 3 at 17:26

Knuth's license/restrictions/preferences for TeX make more sense if you understand the motivation for them: The spirit of the "rules" is mainly that using a program called TeX/tex (using different computers / operating systems / distributions) should produce identical typeset output for identical input documents.

After Knuth wrote TeX (initially for himself) at Stanford (SAIL) in 1977–78 and talked about it, other people were interested in using it elsewhere, and a lot of people took the SAIL code and translated it into their environment; essentially rewriting their own TeX implementations. If you look at very early issues of TUGboat, there are "Site Reports" of various places (universities etc) describing their successes and failures getting their own version of TeX running—and some of them also describe their own "extra" features like new units or additional category codes!

The risk here is that different systems could make their own tweaks to TeX along the way (changing default font or paper size, or adding new primitives/features, or changing how TeX behaves in certain corner cases), so that if someone sent over their paper.tex to another system, it could start giving different results (different line breaks and page breaks, say). To avoid such problems, Knuth rewrote TeX in 1981–82 in (WEB, built on) a subset of Pascal (then the most widely available language, though with varying quality of compilers: thus the subset), so that it would be "portable" and everyone's system could be built on the same code.

If you look at the source code of TeX, section 2, it mentions various implementations and also the restrictions on changing and renaming [emphasis added]:

A complete version of TeX was designed and coded by the author in late 1977 and early 1978; that program, like its prototype, was written in the SAIL language […] The TeX82 program, which was written by the author during the latter part of 1981 and the early part of 1982, also incorporates ideas from the 1979 implementation of TeX in MESA that was written by […]

On the other hand, the WEB description can be extended without changing the core of TeX82 itself, and the program has been designed so that such extensions are not extremely difficult to make. The banner string defined here should be changed whenever TeX undergoes any modifications, so that it will be clear which version of TeX might be the guilty party when a problem arises.

If this program is changed, the resulting system should not be called ‘TeX’; the official name ‘TeX’ by itself is reserved for software systems that are fully compatible with each other. A special test suite called the “TRIP test” is available for helping to determine whether a particular implementation deserves to be known as ‘TeX’ [cf. Stanford Computer Science report CS1027, November 1984].

The last two paragraphs above may seem contradictory (there can be "versions" of TeX with different banners, but the program must not have changed?), but they are not: The last paragraph with "fully compatible" is about the typesetting output of TeX not changing, while the paragraph before that is about having to make changes to TeX (without modifying tex.web) for customizing TeX to different operating systems.

The thing the question asks about is exactly one such new feature: with this file foo.tex:

%&latex
\documentclass{article}
\begin{document}
Hello
\end{document}


running it as pdftex foo.tex shows:

This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=latex)


so you can see it loads the latex format (instead of the pdftex format, as it would if the first line were missing). (Similarly with %&xelatex on the first line and invoking xetex.) If this feature were also to work with tex, then someone may depend on this feature, then move to another system that did not implement it, and conclude that tex is unstable. Therefore this feature is disabled for tex, and (as this feature is not user-visible) it doesn't matter that the underlying tex binary happens to contain, somewhere in its depths, never-accessed code to parse the first line for the format to be loaded. The program is "changed" but this is deemed acceptable as the changes cannot affect a user.

This is what the TRIP manual says:

I propose, in fact, that a program must meet two criteria before it can justifiably be called TeX: (1) The person who wrote it must be happy with the way it works at his or her installation; and (2) the program must produce the correct results from TRIP.TEX. […] However, I don’t want faulty imitations to masquerade as TeX processors, since users want TeX to produce identical results on different machines.

A restriction on the file tex.web also exists, but is much narrower:

Unlimited copying and redistribution of this file are permitted as long as this file is not modified. Modifications are permitted, but only if the resulting file is not named tex.web. (The WEB system provides for alterations via an auxiliary file; the master file should stay intact.)

(Incidentally, before 2021 it said something slightly different:

Copying of this file is authorized only if (1) you are D. E. Knuth, or if (2) you make absolutely no changes to your copy. (The WEB system provides for alterations via an auxiliary file; the master file should stay intact.)

—I guess it was changed to make it clearer.)

To summarize:

1. tex.web is not allowed to be modified directly, but one can either add changes via a change file (like etex.ch) or rename the file (like pdftex.web and xetex.web).

2. A program (starting with tex.web and a change file, or even an entirely independent implementation) can be called "TeX" only if it produces "the same results" as TeX (in particular as validated using the rigorous TRIP test). But note that "same" here means:

• The binary does not need to be identical (and of course cannot be, in general),

• The limits at which various resources are exceeded (memory, number of strings, etc) can be different (not sure where this is documented actually, but this is clearly the case…),

• Even the user interface is allowed to change; consider the question “Some Implementations of TeX” or the case of Doug McKenna's (private to himself) "JSBox" TeX implementation which can be said to pass the TRIP test even though its output is entirely different. See also Knuth's statement "I never have intended to control the aspects of user interaction on particular systems" from The TeX tuneup of 2008.