troff quick reference, macros

defining macros

.de XX YY
begins the definition of macro XX. The definition continues until command YY; the default for YY is a single dot. Consequently, macro definitions usually look like
.de XX
...macro text...
..
The terminating command is executed during the definition of the macro, but not copied.

The text in the macro is read and copied in copy mode. To place a line with .. in a macro (e.g. because your macro defines another macro), use

\\..

removing and renaming

.rm XX

removes the definition of macro or string XX.
.rn XX YY

renames XX to YY.

macro arguments

Macro arguments are tokenized into words; words can be quoted with double quotes (") to embed white space. Within quotes, two double quotes ("") are folded into one literal double quote; consequently, """" expands to one literal ".

\$N
accesses the current macro argument N (for N in 0..9). When defining macros, you'll want to use
\\$N
two slashes - you don't want the macro argument evaluated during the definition, only when the macro is expanded.

print macros

.pm
.pm t
prints the names and sizes (in blocks of 128 bytes) of all defined macros, followed by their total size; or, in the second form, only the total.