I know LaTeX and I've heard that LaTeX is a set of macros in TeX. But what does it exactly mean?
9 Answers
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.
-
2To 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.– SamBCommented Dec 1, 2010 at 5:23
-
4So 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? Commented Sep 27, 2015 at 17:14
-
1@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 ♦Commented Sep 27, 2015 at 17:22
-
6
-
13@smwikipedia Nothing, or at least Leslie Lamport has never formally specified. Most people assume it's 'LAmport TeX' or similar, but ...– Joseph Wright ♦Commented Oct 11, 2016 at 10:07
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.
-
9"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. Commented Aug 4, 2010 at 23:50
-
6@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") Commented Nov 9, 2012 at 11:07
-
3Good 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. Commented Apr 30, 2013 at 12:01
-
2Is 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? Commented Aug 31, 2014 at 18:09
-
2@AaronMcDaid It would be nice if this comment would point to a new question on this site. Commented Dec 19, 2015 at 14:48
(updated to better reflect the age of the LaTeX format)
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
, andLuaTeX
. 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 -- commands defined with the help of a primitive such as
\def
-- which, taken together, make the set of primitives usable for typesetting purposes by humans. For instance,Plain TeX
is a set of macros created by Don Knuth (who also created the TeX program) to typeset his books, including the TeXbook. (Aside: The TeXbook defins and uses additional macros, besides those set up in the Plain-TeX format, to handle various formatting-related tasks.)LaTeX2e
, which has been around since 1994, is probably the most commonly used format these days. (Aside: Before LaTeX2e was released in 1994, there were various numbered versions of LaTeX; the final version as numbered "2.09".)Both
Plain TeX
andLaTeX2e
can be "mated" to various engines -- specifically,pdfTeX
,XeTEX
, andLuaTeX
. The current version ofConTeXt
is a format that builds on the LuaTeX engine; it will not run under eitherpdfTeX
orXeTeX
.For the most part, the macros defined in the
Plain TeX
format are also defined in theLaTeX
andLaTeX2e
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 bothPlain TeX
andLaTeX2e
. Some newer packages, such asfontspec
, 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 hyperlink 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 input 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.
-
3Thanks 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}– MisthaCommented Jan 4, 2015 at 6:51
-
3@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.– MicoCommented Jan 4, 2015 at 7:44
-
4This answer mentions an important point: the latex2e format is not a pure superset of plain tex. When compiling latex you can not assume plain tex macros are defined. Commented Jul 21, 2016 at 16:21
-
1@Mico oh, you're right. I didn't check it because because it'd lead to a confusion — if binary the same, why to make those links in the first place, instead of calling it always by the same name. Which it did. Still, on my system
latex
is a symlink topdftex
, but runninglatex
with your latex code works, whilst runningpdftex
with your latex code causes an error.– Hi-AngelCommented Oct 10, 2017 at 20:26 -
1
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.
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.
This was originally the answer to Difference between TeX and LaTeX, so the wording may seem a bit off context to this question, but the message remains.
Surprisingly all of those are kind of true. Here's a very brief summary to try to make things clear for you:
TeX is a program, and is the underlying program in all of the TeX family. However TeX, as a program, does a great deal of different things which lead people to call it other names, but also use the name TeX to those things.
TeX, the program, is primarily a typesetting system, which means that its fundamental job is to take your text and put it into a printable document. However when TeX reads an input file to see what you wrote it uses an embedded programming language which is also referred to as “TeX”, leading to all this confusion. The TeX programming language is a Turing-complete macro1 expansion language, so all those statements you mention are true. And finally, there is the plain TeX format2, which is a file (plain.tex
) written in the TeX programming language, to make some tasks easier while you're using the TeX language to write using the TeX program.
1 A “macro”, is a command defined in the TeX language which “expands” to something else. When you do \def\say#1{Hello #1!}
you create a macro, and when you use \say{world}
to get Hello world!
TeX expands the macro \say
.
2 A “format”, in the TeX vocabulary, is a bunch of macros which are pre-loaded when the program starts to speed up the process.
So if you want to say the word “TeX” 5 times in a single sentence you can say that: when you run tex
from the command line, TeX (the program) starts with the plain TeX format loaded and then reads a TeX (the language) input file and uses the TeX typesetting system to write a printable document.
If you understood that, LaTeX is easy: it's a format, just like plain TeX. There is a file, latex.ltx
, written using the TeX language, which is preloaded when you use the latex
(or pdflatex
or xelatex
or...) executable. It's just a (very large) bunch of macros operating on top of TeX.
Finally, there were along the years additions to TeX. These additions can't be called TeX, so their creators give them a different name (pdfTeX, XeTeX, LuaTeX, etc.) and these are different TeX engines. They all have most of the same common features as TeX (the typesetting system, the programming language, etc.) but have some fundamental changes which make them a rather different program under the hood (pdfTeX produces PDF output, LuaTeX has the Lua scripting language embedded), so they are called TeX engines.
I'd add that the name actually shows the difference: LaTeX = "Layman's TeX". This also shows that it's enough to master LaTeX to get (most) things done, but TeX to be a real master. As the saying goes: there are TeXnicians and TeXperts...
EDIT: I know this answer is inaccurate (it's one of my first contributions to TeX.SX, I have learned a lot since, tanks mostly to the community behind this site). I kept it deliberately, because this is a quite widely accepted belief, among newbies especially. The comments and the downvote I received put things right, therefore I don't believe this should be edited as it was, namely to LaTeX = "Lamport's TeX" (Leslie Lamport was the initial developer of LaTeX).
I don't know where the comments are gone (I can't see them anymore), but the edit skews the original answer and cancels its message. As I said, I kept this for educational/informative reasons. We learn not only from things that are done right, but also from mistakes. If we are smart enough, from those of our peers, too.
In TeX, you learn the basic things and use that to do what you want.
In LaTeX, you look for a specific package that already does what you want and use it.
The implications are:
In TeX, you need to learn all the basic before being able to do most tasks. Thus the initial learning curve is steep.
But you also learn how to program, thus you have the power of the computer (e.g. doing repetitive task)
LaTeX has e.g.
python
package, but it only has loose integration with the TeX layer (e.g. it's not very easy to measure the width of a box, if you e.g. want to automatically determine column width).
However, once you've learnt all the basics, you can do everything1, instead of looking up a new package you define your own command to do what you want.
For a comparison, TeX is a full programming language (imagine Python), and LaTeX is like a DSL (domain-specific language) (imagine the game engines that allow you to make games without coding).
Wikipedia link for DSL. (for whatever reason, at the moment the Wikipedia page lists LaTeX as external domain-specific language, while it's obviously embedded in TeX...)
Also, in LaTeX...
if there's no existing package that does what you want, you're probably stuck.
You're stuck with package bugs. (e.g. 2).
To make the problem worse,
- it's easy to write TeX macros that only handle limited cases,
- usually TeX packages does not report errors meaningfully (sometimes they just don't write code to check, sometimes it's really impossible),
- and interpreting error messages usually requires knowledge of TeX programming.
It could be less convenient than necessary (verbose input). For example you can't use
\verb
nested inside another command, so you're forced to use the long form e.g.\textbackslash
if you don't know how to "fix the issue".
Technical details:
It's true that LaTeX is a set of macro on top of TeX; however TeX is a really flexible programming language so the syntax can be arbitrarily complex.
(it's even possible to make a "TeX format" that interprets the document as Python program to execute it...)
More practically, it's possible for LaTeX to delete existing TeX primitives/not defining the correspond for a plain TeX macro (e.g. the
\matrix
macro in plain TeX is redefined byamsmath
package for the\begin{matrix}...\end{matrix}
environment), so strictly speaking LaTeX does not need to be a superset of TeX.The (command-line) executable
latex
is just a symlink totex
, however the program looks atargv[0]
to determine what format should it run as.
(note, diagrams might be incorrect, comments are welcome. They're only for illustration purposes.)
1: Almost. See tex general - What can't TeX do? - TeX - LaTeX Stack Exchange for example.
-
(the previous answers just don't seem very clear to me when I needed it, although now that I know the answer (after roughly learning both), I can see they're all true.) Commented Mar 23, 2022 at 2:35
-
something specific you would be able to do easily if you learn TeX but might be pretty hard with LaTeX: tex.stackexchange.com/q/639307/250119 Commented Apr 2, 2022 at 1:50
-
Also (roughly speaking / according to my understanding) TeX prioritize convenience over consistency, LaTeX prioritize consistency over convenience (yet still cannot get completely consistent because it's built on TeX) Commented Apr 10, 2022 at 7:19
-
(something else, relevant comment " If you were familiar enough with TeX you could write everything yourself by hand. But it certainly isn't true that mere familiarity with LaTeX would allow you to do this") Commented Apr 12, 2022 at 16:28
-
In the TeX diagram,
\box
will not, by itself, get you a framed box. Instead, it defines a "container" into which content can be placed and saved/used. If a visible frame is wanted, you have to construct it yourself. Commented Sep 23, 2022 at 3:45
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.
-
5I 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"? Commented Jul 28, 2010 at 18:15
-
7I 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. Commented Aug 4, 2010 at 22:41
-
5And: there is no engine called latex. It is just the format. (I didn't downvote either, but the answer is misleading).– topskipCommented Aug 5, 2010 at 5:37
-
2
-
1@JoséFigueroa-O'Farrill: Yes LaTeX is a layer over TeX; however, this answer did qualify its statement with "Treating the system as a black box…". So, I agree with Dima that, say, from a user's point of view, TeX and LaTeX might as well just be treated as different systems.– RhubbarbCommented Sep 17, 2014 at 21:05
pdftex
to generate a.pdf
file directly without the intermediate.dvi
step (depending on the contents of the .tex` file of course)Hello, world! \bye
. LaTeX is a very common document markup language written in TeX. Its syntax is more verbose, like\documentclass{book} \begin{document} Hello, world! \end{document}
. Either can write DVI or PDF directly (I've almost never had to write a DVI, however).