Wiki: TeX

Your best resource for TeX is the TeXBook, particularly chapter 20 ("Definitions (also called Macros)") and Appendix D ("Dirty Tricks"). Appendix B provides a list of almost all macros defined at startup.

The reference for plain TeX at tug.org is also a good resource.

Basics

Differences from Plain TeX

The TeX language on the site is very similar to Knuth's plain TeX, with a few small modifications:

Looping over a string

The following code loops over all tokens until \relax, replacing all - tokens with (DASH)

\def\f#1{\ifx#1\relax%
    \let\n\relax%
\else%
    \let\n\f%
    \ifx#1- (DASH)%
    \else #1%
    \fi%
\fi\n}

\f 0-185186-70-\relax

Golfing

One-byte macro ending

If a macro you define takes an argument longer than one token, you might be tempted to use curly braces. However, \def can allow for a single end character, saving one byte per usage.

\def\f#1{something #1 something}
\f{123}\f{456}
% compare
\def\f#1;{something #1 something}
\f123;\f456;

\let

Commonly-used macros can be aliased with \let

Compare:

\newcount\a\newcount\b\newcount\c
% compare
\let\N\newcount\N\a\N\b\N\c