43

I've been working on a project and compiled it using pdfLaTeX, then tried to compile using pdftex and got a whole lot of errors. I'd like to know why that would happen since it's a very plain file and I did not put a pdflatex option in documentclass or anything like that, and what's the real difference between them.

2 Answers2

44

If a .tex file starts with \documentclass -- or, possibly, the now-obsolete \documentstyle command -- it's a file that needs to be compiled by a TeX engine that loads the LaTeX format file rather than the Plain TeX format file. Format files (or, shorter, "formats") are, loosely speaking, large collections of macros. There are many TeX formats; nowadays, the best known formats -- other than the original PlainTeX format -- are LaTeX (LaTeX2e, to be a bit more precise) and ConTeXt.

The LaTeX(2e) format is, to a first approximation, a large superset of the Plain-TeX format. It's not a strict superset, though, because there are some "Plain TeX" macros that aren't implemented in LaTeX. Hence, .tex files that contain LaTeX commands cannot be compiled if the PlainTeX format is loaded instead of the LaTeX format.

Note that the \documentclass instruction is itself a "LaTeX"-specific macro, i.e., it is not recognized by "Plain TeX". Therefore, pdftex (which loads the "plain TeX" format) cannot proceed properly once it encounters the \documentclass instruction on line 1 of the input file.

Addendum: For more information on TeX formats see, for instance, the webpage TeX formats and engines as well as the TeX.SE page List of TeX formats.

Mico
  • 506,678
  • 1
    Are {pdf,lua,xe}latex really formats? I thought LaTeX and ConTeXt were the only widely used formats nowadays, while XeTeX et. al. are different compilers. – You Jan 14 '12 at 00:36
  • 1
    @You: I thought ConTeXt was an editor. And I believe what Mico means by format is language or dialect (in the computer languages sense). – Ben Voigt Jan 14 '12 at 00:39
  • @You: see the addendum to my answer for more information on TeX formats. – Mico Jan 14 '12 at 01:00
29

pdftex expects the file to be plain TeX. pdflatex expects it to be LaTeX. These are two different dialects of TeX. You do not expect a C compiler to work with Java, do you?

Note that in practice pdftex and pdflatex are often the same command, which analyzes how it was called to switch to the proper input language. On some systems gcc behaves in the same way, compiling C if it is called as gcc or Fortran if it is called as gfortran.

Boris
  • 38,129
  • 5
    The latter part is the reason why I asked this question. It seemed like the two engines were used/mentioned everywhere interchangeably as if they were the exact same. – Ayman Elmasry Jan 13 '12 at 21:12
  • 2
    Well, many plain TeX commands are available in LaTeX, and some packages (pstricks, pgf/tikz, babel and many others) are written to work in plain, LaTeX and even in ConTeXt. So these dialects are close - but not identical. – Boris Jan 13 '12 at 21:19
  • 3
    @AymanElmasry: pdflatex is not an engine. See this link for more information. – Martin Schröder Jan 13 '12 at 22:40
  • 1
    @MartinSchröder: Your link: "Engines: TeX, pdfTeX, XeTeX, LuaTeX, … These are the actual executable binaries which implement the different TeX dialects. The LaTeX format is implemented with both the pdfTeX (pdflatex) and XeTeX (xelatex) engines, for example. When someone says “TeX can't find my fonts”, they usually mean an engine." – Ayman Elmasry Jan 14 '12 at 05:26
  • 1
    @MartinSchröder: "pdflatex is not an engine". What is it then? – Tim Jul 20 '12 at 14:15
  • 1
    @Tim: See http://tex.stackexchange.com/q/63994/5763 – Martin Schröder Jul 20 '12 at 14:28
  • Perhaps a better analogue would be C and C++. You can compile most C programs with a C++ compiler, but not the other way around. – Alexia Luna Oct 08 '14 at 13:04
  • So, is it the case that XeTeX and LuaTeX expect plain TeX scripting to process, while XeLaTeX and LuaLaTeX expect LaTeX scripting to process? And, when I frequently read about folks using LuaTeX and XeTeX (and PdfTeX) they are, more accurately, using Xe, Lua of PdfLaTeX? – user12711 Jan 09 '16 at 21:18
  • 1
    Absolutely right. – Boris Jan 11 '16 at 18:55