groff can perform arithmetic. This is documented in the full groff manual, which is available online or in GNU Info format (use
info groff, or
pinfo groff to see the full manual)....as with many GNU programs, the man page is just a quick reference, full docs are in Info format.
gtroff has most arithmetic operators common to other languages:
- Arithmetic: ‘+’ (addition), ‘-’ (subtraction), ‘/’ (division), ‘*’
(multiplication), ‘%’ (modulo).
gtroff only provides integer
arithmetic. The internal type used for computing results is ‘int’,
which is usually a 32-bit signed integer.
Comparison: ‘<’ (less than), ‘>’ (greater than), ‘<=’ (less than or
equal), ‘>=’ (greater than or equal), ‘=’ (equal), ‘==’ (the same as
Logical: ‘&’ (logical and), ‘:’ (logical or).
Unary operators: ‘-’ (negating, i.e. changing the sign), ‘+’ (just for completeness;
does nothing in expressions), ‘!’ (logical not; this works only within
if and while requests). See below for the use of unary operators in
The logical not operator, as described above, works
only within if and while requests. Furthermore, it may appear only at
the beginning of an expression, and negates the entire expression.
Attempting to insert the ‘!’ operator within the expression results in
a ‘numeric expression expected’ warning. This maintains compatibility
with old versions of troff.
.nr X 1
.nr Y 0
.\" This does not work as expected
.if (\n[X])&(!\n[Y]) .nop X only
.\" Use this construct instead
.if (\n[X]=1)&(\n[Y]=0) .nop X only
info is the standard GNU Info document viewer. pinfo is an alternative viewer that provides a more "browser-like" UI, similar to a text web browser like
lynx. I personally can't stand
info and use
pinfo instead. It's available pre-packaged for most distros and source code is available in the pinfo link above.