22

I'm a programmer, I would like to take a look at a more technical and specific definition of what is referred to as LaTeX or TeX.

My interest in on syntax, semantics, and the grammar of this language in general, I also would like a word about the packages which I assume are part of some kind of plugin-like extensible-system and I would also like to know how this interaction is defined.

Thanks.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
user2485710
  • 767
  • 5
  • 9

1 Answers1

26

The grammar of each TeX command is more or less completely given in The TeXBook. Note, however, that unlike most programming languages the lexical analysis and tokenisation of the input cannot be separated from execution as the catcode table which controls tokenisation is dynamically changeable. Thus parsing TeX tends to defeat most parser generation tools.

LaTeX is a set of macros written in TeX so is defined by its implementation, although there is fairly extensive documentation in The LaTeX Companion, the LaTeX book (LaTeX: A Document Preparation System), and elsewhere.

Packages are not really plugin-like which usually implies some sort of binary API. They are (mostly) source level inclusion of macro definitions so more like #include (if you know the C pre-processor macro system) than anything else.

David Carlisle
  • 757,742
  • thanks, could you link to some actual doc ? what is this catcode code table ? – user2485710 Dec 23 '13 at 01:02
  • 1
    @user2485710 You can find out more about catcodes in ch.7 of the TeXbook. – jub0bs Dec 23 '13 at 01:06
  • The texbook is a book (its source code is available but should not be processed, you should be able to get it from any bookstore or library) (catcode, search this site for thousands of examples:) – David Carlisle Dec 23 '13 at 01:07
  • @Jubobs yes, but you are referring to the book published in the 1984 ? It's that "TeXbook" ? – user2485710 Dec 23 '13 at 01:07
  • @DavidCarlisle there is a book published in the 1984 and another one in the 1986, which one are you considering ? http://www.amazon.com/TeXbook-Donald-E-Knuth/dp/0201134489 or http://www.amazon.com/dp/0201134470/ – user2485710 Dec 23 '13 at 01:13
  • @user2485710 Yes. If you're interested in buying a copy, I recommend getting the latest edition here. Another good reference (which is available online) is TeX by Topic, by Victor Eijkhout. Chapter 2 deals with catcodes. – jub0bs Dec 23 '13 at 01:14
  • @Jubobs I'm confused now, the book that you linked is the one from the 1986 ... – user2485710 Dec 23 '13 at 01:23
  • 1
    @user2485710 See http://tex.stackexchange.com/questions/100060/the-texbook-spiral-or-hard-cover-binding/104130#104130 for more details on the different editions of the TeXbook. – jub0bs Dec 23 '13 at 01:25
  • 9
    @user2485710 The TeXBook has gone through several reprints fixing errata but is essentially unchanged since TeX3 came out in 1986 or so, it is very rare that anyone has to refer to a specific printing of the book, the errors tend to be very esoteric and the changes very minor. If you are buying it just buy whatever the publisher says is the latest reprint. If you are borrowing it, don't worry about it, chances are it doesn't matter which version you have. – David Carlisle Dec 23 '13 at 01:43
  • @user2485710 the question is slightly embarrassing, since tex is (in essence) a somewhat arcane macro processor with a typesetting engine attached. writing grammars of macro processors isn't ordinarily a useful thing to do, and in tex's case it becomes worse since you can write macros to provide an entirely different grammar. for example, see the basix package – wasteofspace Dec 23 '13 at 11:08
  • @wasteofspace strangely enough, I feel like in Tex the semantics takes over the syntax ... – user2485710 Dec 23 '13 at 12:01
  • 2
    @user2485710: This might be a good reference for you: http://tex.stackexchange.com/a/4205/3094 Beware, hic sunt leones. :) – Paulo Cereda Dec 23 '13 at 13:58
  • @DavidCarlisle: TeX3 is from 1990, not 1986 (that would be LaTeX). :-) – Martin Schröder Dec 24 '13 at 21:02