What is the difference between TeX and LaTeX?

TeX is both a program (which does the typesetting, tex-core) and format (a set of macros that the engine uses, plain-tex). Looked at in either way, TeX gives you the basics only. If you read the source for The TeXBook, you'll see that Knuth wrote more macros to be able to typeset the book, and made a format for that.

LaTeX is a generalised set of macros to let you do many things. Most people don't want to have to program TeX, especially to set up things like sections, title pages, bibliographies and so on. LaTeX provides all of that: these are the 'macros' that it is made up of.


In short TeX is all about formatting, for document/template designers, while LaTeX is all about content, for document writers.

TeX is a typesetting system. It provides many commands which allow you to specify the format of your document with great detail (e.g. font styles, spacing, kerning, ligatures, etc.), and has specialized algorithms to compute the optimal flow of text in your document (e.g. where to cut lines, pages, etc.). TeX is all about giving you powerful algorithms and commands to specify even the tiniest detail to make your documents look pretty.

LaTeX is a set of macros built on top of TeX. The idea behind LaTeX is to shift the focus from the format to the content of your document. In LaTeX commands are all about giving a structure to the content of your document (e.g. sections, emphasis, tables, indices, etc.). In LaTeX you just say \section{...} instead of: selecting a larger font, a different font style, and inserting appropriate spaces before and after the section heading. As LaTeX is built on top of TeX you also get, of course, a beautiful document as your output; but, more importantly, your source input can also be well structured, easier to read (and write!) for humans.


It's important to distinguish between typesetting "engines", "formats", and "packages".

  • The engine is the actual program. Nowadays, the most commonly used engines that are distributed with TeXlive and MiKTeX are pdfTeX, XeTeX, and LuaTeX. The "engines" make use of a number of so-called "primitive" instructions to accomplish the job of processing user inputs. Examples of "primitive" instructions provided by the original TeX engine (and also provided by the more recent engines!) are \def, \outer, \expandafter, \noexpand, \futurelet, \relax, \catcode, \vbox, \hbox, \accent and \kern. The primitive instructions are very powerful, but many of them are so low-level that using them directly in a document would be rather tricky, to put it politely.

  • A format is a collection of macros that make the TeX primitives usable for typesetting purposes by humans. For instance, Plain TeX is a set of macros created by Don Knuth (the creator of the TeX program) to typeset his books, including the TeXbook. (Aside: The TeXbook uses additional macros, besides those set up in the Plain-TeX format, to handle various formatting-related tasks.) LaTeX2e, which has been around for more than 20 years, is probably the most commonly used format these days. Both Plain TeX and LaTeX2e can be "mated" to various engines -- specifically, pdfTeX, XeTEX, and LuaTeX. The current version of ConTeXt is a format that builds on the LuaTeX engine; it will not run under either pdfTeX or XeTeX.

    For the most part, the macros defined in the Plain TeX format are also defined in the LaTeX and LaTeX2e formats. However, quite a few Plain-TeX macros -- especially those associated with changing the appearance of fonts in a document, such as \bf, \it, and \tt -- are considered deprecated and should no longer be used in a LaTeX-based document; use LaTeX2e-based macros such as \textbf and \itshape instead. (To be precise, the macros \bf and \it are not defined in the LaTeX2e kernel, but "only" in some LaTeX2e document classes.)

  • A huge number of packages -- a few thousand, maybe even tens of thousands -- have been written over the years to either accomplish new typesetting-related tasks or to simplify other tasks. Many packages require the LaTeX2e format. A few, though, work equally well with both Plain TeX and LaTeX2e. Some newer packages, such as fontspec, run only under XeLaTeX and LuaLaTeX.

    To be sure, decisions about which typesetting tasks should be handled by engines, formats, and packages can be a bit arbitrary and are frequently history-dependent. For instance, in 1994, when LaTeX2e was first circulated broadly, the ability to hyper-link pieces of text within a document and across documents was not considered to be a core typesetting job. I'm sure that the hyperref package -- which came along only long after LaTeX2e was (essentially) frozen -- would be much more streamlined and easier to maintain had various "hooks" and important design decisions related to hyperlinking been built into the LaTeX2e format from the start.

    Another example: TeX (the engine) has powerful, and generally very successful, paragraph-building algorithms. However, it is not possible for users (or package writers) to tweak or modify these algorithms directly if they use TeX, pdfTeX, or XeTeX as the underlying engine. In contrast, with LuaTeX important components of the paragraph building algorithms have been "opened up" to programmers. As a result, we're starting to see new packages -- which obviously require the use of LuaTeX as the engine -- that provide additional typesetting capabilities that were simply infeasible so far.

  • When you execute an instruction such as

    pdflatex myfile
    

    at a command line, what's actually run is the pdfTeX program in a way that first loads the LaTeX format and then processes what's in myfile.tex to create a file called myfile.pdf.

Here are three ways to print "Hello World". The first requires (Plain) TeX, the second LaTeX2e, and the third ConTeXt.


Hello World.
\bye

\documentclass{article}
\begin{document}
Hello World.
\end{document}

\starttext
Hello World.
\stoptext

Assume the input file is named hello.tex in all three cases. To generate a pdf file, you'd compile the first file by typing pdftex hello, the second by typing pdflatex hello, and the third by typing context hello.

For more information on the subject of TeX engines and formats, I recommend Section 1 of the document A guide to LuaLaTeX by Manuel Pégourié-Gonnard. It features a handy table that categorizes the potential interactions between four engines, two formats, and two ways of creating dvi and pdf files.