Next: , Previous: , Up: Conditionals and Loops   [Contents][Index]


5.20.1 Operators in Conditionals

In if, ie, and while requests, in addition to ordinary Expressions, there are several more operators available:

e
o

True if the current page is even or odd numbered (respectively).

n

True if the document is being processed in nroff mode (i.e., the .nroff command has been issued). See Troff and Nroff Mode.

t

True if the document is being processed in troff mode (i.e., the .troff command has been issued). See Troff and Nroff Mode.

v

Always false. This condition is for compatibility with other troff versions only (identifying a -Tversatec device).

'xxx'yyy'

True if the output produced by xxx is equal to the output produced by yyy. Other characters can be used in place of the single quotes; the same set of delimiters as for the \D escape is used (see Escapes). gtroff formats xxx and yyy in separate environments; after the comparison the resulting data is discarded.

.ie "|"\fR|\fP" \
true
.el \
false
    ⇒ true

The resulting motions, glyph sizes, and fonts have to match,22 and not the individual motion, size, and font requests. In the previous example, ‘|’ and ‘\fR|\fP’ both result in a roman ‘|’ glyph with the same point size and at the same location on the page, so the strings are equal. If ‘.ft I’ had been added before the ‘.ie’, the result would be “false” because (the first) ‘|’ produces an italic ‘|’ rather than a roman one.

To compare strings without processing, surround the data with \?.

.ie "\?|\?"\?\fR|\fP\?" \
true
.el \
false
    ⇒ false

Since data protected with \? is read in copy-in mode it is even possible to use incomplete input without causing an error.

.ds a \[
.ds b \[
.ie '\?\*a\?'\?\*b\?' \
true
.el \
false
    ⇒ true
r xxx

True if there is a number register named xxx.

d xxx

True if there is a string, macro, diversion, or request named xxx.

m xxx

True if there is a color named xxx.

c g

True if there is a glyph g available23; g is either an ASCII character or a special character (\N'xxx', \(gg or \[ggg]); the condition is also true if g has been defined by the char request.

F font

True if a font named font exists. font is handled as if it was opened with the ft request (this is, font translation and styles are applied), without actually mounting it.

This test doesn’t load the complete font but only its header to verify its validity.

S style

True if style style has been registered. Font translation is applied.

Note that these operators can’t be combined with other operators like ‘:’ or ‘&’; only a leading ‘!’ (without whitespace between the exclamation mark and the operator) can be used to negate the result.

.nr xxx 1
.ie !r xxx \
true
.el \
false
    ⇒ false

A whitespace after ‘!’ always evaluates to zero (this bizarre behaviour is due to compatibility with UNIX troff).

.nr xxx 1
.ie ! r xxx \
true
.el \
false
    ⇒ r xxx true

It is possible to omit the whitespace before the argument to the ‘r’, ‘d’, and ‘c’ operators.

See Expressions.


Next: , Previous: , Up: Conditionals and Loops   [Contents][Index]