TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to understand low-level stuff like \if better. I'm not looking for some random examples off Google showing me some statements but a specification of some sort - something mean and unforgiving. But it's hard searching for the phrase "if" because it doesn't match what I'm looking for.

Note: I am not talking about \ifthen.

share|improve this question
Have a look into Knuths TeXbook or Eijkhouts “TeX by Topic“. Both awesome books about how things work “under the hood”. – Marco Mar 1 '12 at 14:53
up vote 21 down vote accepted

You should probably have a look at Chapter 20 of the TeXBook and at Chapter 13 of Eijkhout's book TeX by Topic. (The latter book is probably also included in your TeX distribution -- try typing "texdoc texbytopic".)

share|improve this answer

Since you ask "where can I find ...", I believe that posting a link is a valid answer. I really like this page that explains all TeX primitives, with comments and examples:


share|improve this answer

As another quick reference I have used Tralics extensively. Although some of the commands do not appear in TeX it is of great help. Mainly due to its many low-level examples.

There are many examples. For instance for the \edef command:


You can say \edef\foo{bar}. The syntax is the same as \def, but the token list in the body is fully expanded (tokens that come from \the are not expanded).

You can put the prefix \global before \edef, note that \xdef is the same as \global\edef. In the example that follows, the \ifx is true.

{\catcode`\A=12 \catcode`\B=12\catcode`\R=12\gdef\fooval{ABAR}}
{\escapechar=`\A \edef\foo{\string\BAR}\ifx\foo\fooval\else \uerror\fi}

Another example is the following. The \meaning command returns a token list, of the form macro:#1#2->OK OK, and \strip@prefix removes everything before the > sign. What we put in \Bar is a list of five tokens, a space, and four letters of catcode 12.

\def\foo#1#2{OK OK}

For a non-trivial example, see \aftergroup.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.