[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Groff] fetching a register's numeric value
From: |
Dave Kemper |
Subject: |
[Groff] fetching a register's numeric value |
Date: |
Fri, 31 Aug 2012 01:25:26 -0500 |
Hi,
Is there a way to fetch the numeric value of a register regardless of
what output format is currently associated with the register?
The only method I've been able to figure out is:
.ds reigning_format \g%
.af % 0
.nr page_number \n[%]
.af % \*[reigning_format]
to save the format, switch it to numeric, fetch the value, and then switch
the format back to its saved status. Then I can use \n[page_number]
when I need the numeric version of the page number (in calculations,
for instance). This works, but is not very elegant.
The existence of a better mechanism is implied by the .af documentation:
"Changing the output format of a read-only register causes an error.
It is necessary to first copy the register's value to a writeable
register, then apply the `af' request to this other register."
Unfortunately, no hint is provided on how one might copy the register's
value in a case where the register's output format cannot be changed.
The intuitive solution -- using .nr -- fails when the output format is
"i", generating the message:
warning: numeric expression expected (got `i')
(or "got `v'" or "got `x'", depending on the register's current value)
- [Groff] fetching a register's numeric value,
Dave Kemper <=