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.
- 259,911
- 34
- 706
- 1,036
-
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. – SamB Dec 01 '10 at 05: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? – Thomas Ahle Sep 27 '15 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 Sep 27 '15 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 Oct 11 '16 at 10:07
-
-
@SamB When you say 'the set of macros is called plain TeX', are you referring to the macros Knuth used in his book, or the set of macros that Lamport used? – Qqwy Jan 30 '21 at 14:12
-
1@Qqwy Those are Knuth's: Lamport (originally) loaded LaTeX on top of plain, but later some (but not all) of the plain macros were incorporated into
latex.ltx. – Joseph Wright Jan 30 '21 at 15:00
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.
- 62,139
- 32
- 140
- 169
-
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. – José Figueroa-O'Farrill Aug 04 '10 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") – wasteofspace Nov 09 '12 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. – Matthew Leingang Apr 30 '13 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? – Aaron McDaid Aug 31 '14 at 18:09
-
2@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
(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,\accentand\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 TeXis 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 TeXandLaTeX2ecan be "mated" to various engines -- specifically,pdfTeX,XeTEX, andLuaTeX. The current version ofConTeXtis a format that builds on the LuaTeX engine; it will not run under eitherpdfTeXorXeTeX.For the most part, the macros defined in the
Plain TeXformat are also defined in theLaTeXandLaTeX2eformats. 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\textbfand\itshapeinstead. (To be precise, the macros\bfand\itare 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
LaTeX2eformat. A few, though, work equally well with bothPlain TeXandLaTeX2e. 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.
- 506,678
-
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} – Mistha Jan 04 '15 at 06: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. – Mico Jan 04 '15 at 07: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. – jiggunjer Jul 21 '16 at 16:21
-
But if
latexandplain texare sets of macros using same primitive instructions underneath — why do they use different executables? – Hi-Angel Oct 10 '17 at 16:01 -
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
latexis a symlink topdftex, but runninglatexwith your latex code works, whilst runningpdftexwith your latex code causes an error. – Hi-Angel Oct 10 '17 at 20:26 -
@Mico thank you, I was about to say: but this returns us to my original question (except, replace "executables" with "codepaths"); but I think I get it. The reason is probably that latex doesn't require
\usepackage(design decision? mistake?) to detect its typical macros. But it still requires some code to differlatexfromtex. And the devs decided to delegate the detection to a user. – Hi-Angel Oct 11 '17 at 05:17 -
@Mico no, no, what makes you think that? After all, yesterday I upvoted your answer, it's a good one! I'm looking to try writing an import filter from latex for LibreOffice, and I'm currently evaluating the size of the effort and my resources. Having to parse only small number of trivial instructions makes things much easier. – Hi-Angel Oct 11 '17 at 09:24
-
@Mico The distinction between
formatandpackageis fuzzy when both are referred to a "collection of macros". Would it be reasonable to say thatformatis a "foundational collection of macros" upon which a "secondary, or helper collection of macros" akapackageis built? Or perhaps, more techincally, aformatvs.packageis distinquished by how the defining file is used? Where aformatwould be referenced in the command line (e.g.tex -fmt format_name.fmt) and apackagewould be included at the document level (e.g.\usepackage[T1]{fontenc}) – marc-medley Feb 14 '19 at 22:47 -
@I--marcI -- I fully agree with your conceptual distinction between "foundational" and "secondary" collections of macros. In practice, though, what exactly should be foundational and what should be secondary is often not all that obvious; some distinctions appear to be explainable more as historical accidents than the result of a careful master plan. E.g., within the pdftex/LaTeX2e space, some packages (e.g.,
inputenc,fontenc,geometry,array,babel,hyperref) tend to get loaded by virtually all serious documents. Hence, they are de facto foundational. :-) – Mico Feb 15 '19 at 05:12 -
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.
- 74,238
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.
- 1,873
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.
- 70,814
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.
- 17,424
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.
pythonpackage, 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
\verbnested inside another command, so you're forced to use the long form e.g.\textbackslashif 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
\matrixmacro in plain TeX is redefined byamsmathpackage for the\begin{matrix}...\end{matrix}environment), so strictly speaking LaTeX does not need to be a superset of TeX.The (command-line) executable
latexis 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.
- 7,143
-
(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.) – user202729 Mar 23 '22 at 02:35
-
something specific you would be able to do easily if you learn TeX but might be pretty hard with LaTeX: https://tex.stackexchange.com/q/639307/250119 – user202729 Apr 02 '22 at 01: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) – user202729 Apr 10 '22 at 07:19
-
-
In the TeX diagram,
\boxwill 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. – barbara beeton Sep 23 '22 at 03: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.
- 12,427
- 8
- 40
- 53
-
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"? – ShreevatsaR Jul 28 '10 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. – José Figueroa-O'Farrill Aug 04 '10 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). – topskip Aug 05 '10 at 05:37
-
Note that that the engines available for each format are (by and large) the same engines. (I read something that lead me to believe that ConTeXt might sometimes actually need LuaTeX, which wold make it something of an exception; also, LateX3 needs some e-TeX primitives, but those are in practically every TeX engine in use today anyway.) The use of different commands for different formats seems to be at least partly an artifact of having used the "undump" trick in the past. (And partly for convenience.) – SamB Dec 01 '10 at 05:35
-
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. – Rhubbarb Sep 17 '14 at 21:05


pdftexto generate a.pdffile directly without the intermediate.dvistep (depending on the contents of the .tex` file of course) – Jan 03 '15 at 15:18Hello, 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). – Mike Renfro Jan 03 '15 at 15:24texis a program that reads files written in the TeX language and outputs commands for printing the text. By default it is set up to load the Plain TeX format, which is a set of TeX macros allowing basic document preparation. TeX is a macro-expansion language: the inputaexpands into internal commands to put the characterafrom a certain font with certain metrics at a certain position on the page for printing; the input$\alpha$expands to commands for changing to math font, selecting the alpha symbol, and typesetting that. The interpretertexdoes this expansion at runtime. – musarithmia Jul 10 '19 at 20:37\def\strong#1{{\bf #1}(TeX) you write\newcommand{\strong}[1]{\textbf{#1}}in LaTeX language. To interpret the\newcommandmacro and all the other ones defined be LaTeX you have to run thetexprogram (=engine) with the LaTeX macros (=format) preloaded. That's what the commandlatexdoes. – musarithmia Jul 10 '19 at 20:39