4

I know that plain TeX is the low-level typographical language that describes nearly every aspect of presentation, taking care of things like paragraph breaks, new pages, and the like.

I know (well, I've inferred) that LaTeX is in fact written in TeX, partly to demonstrate its power and partly for sheer convenience; LaTeX allows the author to construct documents logically rather than 'typographically' as using plain TeX, no-frills, would have you do.

What I don't know is how LaTeX really does it. Does LaTeX compile the document into a PDF, or does it compile the document into plain TeX for tex to actually process? What features does LaTeX actually add on to plain TeX?

David Carlisle
  • 757,742
Sean Allred
  • 27,421
  • 1
    see http://tex.stackexchange.com/questions/49/what-is-the-difference-between-tex-and-latex – Fredrik Pihl Apr 30 '13 at 11:14
  • @FredrikPihl Thanks for the link; I do know the conceptual differences as well as they can be known, but what I'm asking for is something slightly more tangible. (Although I will add that I don't feel the linked question was answered, IMHO.) While the linked asks 'what separates them,' I ask 'what joins them.' – Sean Allred Apr 30 '13 at 11:20
  • It's hard to know what to add that isn't said in the linked question. LaTeX doesn't add to plain. LaTeX and plain tex are each formats written in tex running on a tex engine (tex or pdftex or xetex or luatex or whatever). The source of latex is conceptually just a load of tex definitions no different than the \def or \newcommand that you may put in your document. – David Carlisle Apr 30 '13 at 11:24
  • @DavidCarlisle Do you think it'd be better if I edited to ask what LaTeX compiles to? Because an answer to that would likely imply answers to the larger question. (And I would have thought LaTeX would be a bit more complicated, eh?) Would I be better off pulling from the SVN repository and taking a look into the beast itself? – Sean Allred Apr 30 '13 at 11:27
  • well the answer would be that it doesn't compile. TeX is mostly a macro expansion system, and LaTeX is mostly macros. No LaTeX is not more complicated. The source is latex.ltx file which is simply a TeX file consisting of tex macros. – David Carlisle Apr 30 '13 at 11:33
  • @DavidCarlisle so the pipeline would really be something like "\input{latex} <<content>> \bye" | tex? – Sean Allred Apr 30 '13 at 11:36
  • @SeanAllred you ask what joins then but latex is written in TeX. So it's like asking what joins a python script to the python executable. Or or a perl script to perl or a bash script to bash... or tex or... – David Carlisle Apr 30 '13 at 11:36
  • http://tex.stackexchange.com/questions/108733/how-to-convert-plain-tex-to-latex#answer-108737 – David Carlisle Apr 30 '13 at 11:38
  • @DavidCarlisle I want to believe, but TeX doesn't have \begin{document} (even though I'm pretty sure this is just defined as \document and \enddocument respectively). I get the point, I get the point. – Sean Allred Apr 30 '13 at 11:45
  • LaTeX was not written in TeX to demonstrate the power of TeX, nor was it merely convenient to do so. LaTeX was written in TeX to make TeX easier to use. – Matthew Leingang Apr 30 '13 at 11:48
  • @MatthewLeingang and ease of use is convenient, but I see your point. – Sean Allred Apr 30 '13 at 11:51
  • Oh, I misread that. I thought you were saying LaTeX was written in TeX because it was more convenient to write it (LaTeX) in TeX than in (say) Pascal. So I see your point, too, at least the second one. – Matthew Leingang Apr 30 '13 at 11:58
  • 1
    @SeanAllred \begin is a macro written in TeX just like the rest of latex \def\begin#1{% @ifundefined{#1}% {\def\reserved@a{@latex@error{Environment #1 undefined}@eha}}% {\def\reserved@a{\def@currenvir{#1}% \edef@currenvline{\on@line}% \csname #1\endcsname}}% @ignorefalse \begingroup@endpefalse\reserved@a} – David Carlisle Apr 30 '13 at 12:35
  • @SeanAllred I think you need to remember that 'TeX' is used to refer to 'TeX-the-program' but also 'the plain TeX format'. Both LaTeX and the plain TeX format are macro packages which use TeX-the-program via macros. However, LaTeX does not use plain TeX. – Joseph Wright Apr 30 '13 at 12:40

3 Answers3

3

LaTeX is a link to pdftex:

voss@shania:~> ls -l /usr/local/texlive/2012/bin/x86_64-linux/latex
lrwxrwxrwx 1 voss 1000 6 12. Apr 22:44 /usr/local/texlive/2012/bin/x86_64-linux/latex -> pdftex

Inside pdftex it knows that it was called as latex or pdflatex. The reason why it loads the format LaTeX, which is more or less loading under pdftex the file latex.ltx (the LaTeX kernel), which can be found with kpsewhich latex.ltx. Which program links to another one is listed at Which TeX programs produce dvi output?

2

Leslie Lamport, in his seminal work, LaTeX, A Document Preparation System, User Guide and Reference Manual, Addison-Wesley, 1985, pp.6, describe exactly how LaTeX and TeX are related:

LaTeX is your typographic designer, and TeX is its typesetter.

  • I know exactly the conceptual relationship between LaTeX and TeX; what I was looking for was a more technical explanation. It appears however that I will just have to explore the source for myself ;) – Sean Allred Apr 30 '13 at 11:41
  • 1
    I think this document may be useful: Michael Downes, TeX and LaTeX2e, available at www.ams.org/notices/200211/comm-downes.pdf –  Apr 30 '13 at 11:50
2

TeX has the option of a set of formatting macros called a format. Plain TeX is one of these formats, LaTeX is another, ConTeXt is a third. So in that sense LaTeX is just a layer of helper code over TeX, like a library in a programming language. As far as I understand it (and many here do better than I), prior to pdftex the latex executable was a version of tex pre-compiled with the LaTeX macros “baked in.” As Herbert notes, the pdftex program has many formats baked in and chooses one according the name under which it was called.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195