groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] string comparison


From: Werner LEMBERG
Subject: [Groff] string comparison
Date: Mon, 05 Jun 2006 18:14:49 +0200 (CEST)

Groffistas,


lurking around in troff's source code I've found a nice method to get
string comparison.  You already know that in

  .if "..."..."

the left and right part is processed in protected environments
(without creating real output), and the resulting node lists are
compared.  In particular, this expression

  .if "\f[BI]""

is evaluated as true, which is probably not expected by everyone (the
reason is that no actual output is produced).  Additionally, it is not
possible to have incomplete input.  For example, this

  .if "\["\["

yields a bunch of error messages:

  missing `]'
  invalid base glyph `"\["' in composite glyph name
  warning: can't find special character `'
  warning: missing closing delimiter

Now enters `\?'.  This is a remedy to all of the above described
problems.  Both

  .if "\?\[\?"\?\[\?"

and

  .if "\?\f[BI]\?""

work and return the expected result, since the data embedded between
the \? escapes is read in copy-in mode, without further processing.

This method can also be used to compare macros and diversions, but
this is of limited use.


    Werner




reply via email to

[Prev in Thread] Current Thread [Next in Thread]