# What is the difference between TeX and LaTeX?

I know LaTeX and I've heard that LaTeX is a set of macros in TeX. But what does it exactly mean?

-
You should really read tug.org/levels.html – Martin Schröder Jan 10 '12 at 18:36
tex.stackexchange.com/questions/79609/…. Are these the examples of programs using TeX library? – Mistha Jan 3 '15 at 15:12
You can use pdftex to generate a .pdf file directly without the intermediate .dvi step (depending on the contents of the .tex file of course) – Christian Hupfer Jan 3 '15 at 15:18
@percusse. Thanks you made it much clearer. – Mistha Jan 3 '15 at 15:20
@ChristianHupfer Ok: 0 – Mistha Jan 3 '15 at 15:20

TeX is both a program (which does the typesetting, ) and format (a set of macros that the engine uses, ). 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.

-
To clarify, the set of macros is called "plain TeX" or "plain", and it's a bit of a misnomer, since one would expect that to refer to nothing but the primitives. – SamB Dec 1 '10 at 5:23
So LaTeX is like a standard library for TeX? Is it quite simple and modular then? Maybe I can even read it and learn about good practice for writing TeX macros? – Thomas Ahle Sep 27 '15 at 17:14
@ThomasAhle LaTeX is a set of macros: saying it's standard is a bit tricky as plain users don't use LaTeX macros! – Joseph Wright Sep 27 '15 at 17:22

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.

-
"LaTeX is all about content" is correct, but that's only with LaTeX2e, because in LaTeX 2.09 the distinction between formatting and content was not clear cut. In fact, it was only when LaTeX2e was introduced that I stopped using TeX in favour of LaTeX. – José Figueroa-O'Farrill Aug 4 '10 at 23:50
@JoséFigueroa-O'Farrill surely latex 2.09 (declared obsolete in 1994) can be regarded as no longer germane to current discussions? (note, the faq, first published in 1995, iirc, still sometimes talks as if latex 2e is a shiny new object ... something more to remember when proof reading (a task like the old "painting the forth bridge") – wasteofspace Nov 9 '12 at 11:07
Good answer, but there is a bit of ambiguity in the nomenclature. The TeX term for "a set of macros built on top of TeX" is format. Plain TeX is a format, LaTeX is a format, ConTeXt is a format. So maybe it would be better to say TeX is all about formatting. – Matthew Leingang Apr 30 '13 at 12:01
Is every TeX document a valid LaTeX document? Can we say that LaTeX is just the sample as TeX but with a lot of extra macros predefined? – Aaron McDaid Aug 31 '14 at 18:09
@AaronMcDaid It would be nice if this comment would point to a new question on this site. – Maarten Bodewes Dec 19 '15 at 14:48

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.

-
Thanks for the wonderfull explanation. I just have one question. You gave example for Hello World in both TeX and LaTeX, My question is how will we make TeX realize that it is a book, a article as LaTeX defines using \documentclass{book} – Mistha Jan 4 '15 at 6:51
@Mistha - The following is clearly just "informed" speculation. (I've only been using TeX and LaTeX for 23 years...) The advisability of creating hierarchies of TeX macros to ease the task of generating various types of document must surely have been a main reason for the initial popularity of LaTeX (since the mid-1980s) and the subsequent broad success of LaTeX2e (since 1994). Separating matters of overall layout and structure of a document from matters related to content is certainly fully possible with TeX. However, doing so is much more straightforward with LaTeX2e. – Mico Jan 4 '15 at 7:44

Don Knuth provide both the TeX typesetting program and the plain TeX macros (the file plain.tex).

TeX the program does the typesetting. The preloaded macros (and the input documents, of course) control what is typeset.

Typically, the macros and input document place items on a horizontal list and then, when the \par command (for example, a blank line) is issued TeX the program breaks the paragraphs into lines.

If you run TeX with \tracingall you can see what are macros and what are TeX commands. I suggest you try this with

 \$ tex '\relax \tracingall \input story \end'


rather than a LaTeX document. LaTeX does a lot of macro processing, particularly for font selection.

-

TeX is a typesetting engine which has a macro language available. This macro language is very different from other, more typical, languages. The TeX engine reads text, font metrics and does the typesetting. This means that it decides where the characters from the loaded font will be on the page.

There are several extensions over classical TeX: pdfTeX, XeTeX, LuaTeX. They are able to produce PDF output. The classical TeX is able to produce only DVI output, which is mostly not used today.

TeX (and its extensions) have (for example) the \def command which is the core of macro programming. A macro programmer can declare new control sequences used by the author in the document. A set of such declared control sequences is a macro package. LaTeX is a macro package. For example it provides the control sequence \documentclass, because that was declared by \def\documentclass....

When you process your document, then you run TeX (or one of its extensions) with a macro package preprocessed into binary form, which is called a "format" in TeX terminology. For example, LaTeX is preprocessed from the latex.ltx text file into the latex.fmt binary file (roughly speaking). This is done by the command tex -ini or something similar when a TeX distribution is installed. This is done automatically because there are many complicated historical aspects of this iniTeX processing and there is good reason to hide this from the common user.

When the user runs latex document, then (in reality) the tex -fmt latex.fmt document (or something similar) is processed. It means that TeX is run and it first reads the preprocessed macro package latex.fmt and after that it reads the document prepared by the user.

If vanilla TeX is run (without a preprocessed macro package) then only about 300 primitive commands are available (extensions of TeX provide additional commands). But if TeX with preprocessed latex.fmt is run then about 2000 new control sequences are available. Additional macro packages can be loaded at the beginning of the document and this increases the number of available control sequences.

The common macro packages (LaTeX, ConTeXt) are based on the first macro package (format) created by Knuth, plain.tex. This enlarges vanilla TeX by about 900 control sequences (most of them are mathematical characters aka \alpha, \sum, etc.). The plain TeX is preprocessed into the binary format file tex.fmt (or similar depending on the extension) and it is read by the TeX program automatically if no another format file is specified. This means that tex document runs TeX plus tex.fmt plus document, or pdftex document runs pdfTeX plus pdftex.fmt (which is the result of preprocessing a somewhat extended plain.tex`) plus document.

My text above only simplifies the reality, sorry. The reality is much more varied due to historical reasons.

-

TeX, LaTeX, ConTeXT - different languages / syntax for typesetting.

For each of these there are many engines available that can process the above syntax and generate dvi, ps, pdf, html, svg.... and what not.

To confuse even more there are engines called tex and latex, which can be used to process tex and latex syntaxes respectivly to produce dvi outputs.

@José Figueroa-O'Farrill:

Treating the system as blackbox: ConTeXt, LaTeX and TeX have significantly different syntax and different compilers hence they are different. And most users do not need to know that one is using the other behind the scene, that's an implementation detail. The beginner user needs to know that (a) they are different (b) they all produce awesome quality documents (c) each package has its own "native" way to do stuff (d) you can seek for all of them here.

-
I don't understand the downvotes. This is somewhat terse, but there's nothing particularly wrong with this. What happened to "please consider adding a comment if you think this post can be improved"? – ShreevatsaR Jul 28 '10 at 18:15
I'm voting this up. It's a fine answer. – Chris Phan Aug 4 '10 at 21:55
I didn't vote this down, but I don't agree that TeX and LaTeX are different languages. LaTeX (as of today) is still a set of TeX macros. – José Figueroa-O'Farrill Aug 4 '10 at 22:41
And: there is no engine called latex. It is just the format. (I didn't downvote either, but the answer is misleading). – topskip Aug 5 '10 at 5:37