[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Using variables from register within fractions or equations
From: |
Tadziu Hoffmann |
Subject: |
Re: [Groff] Using variables from register within fractions or equations |
Date: |
Sun, 14 Apr 2013 16:06:48 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
> When I give these tests, which often run into a number of
> pages I like to put the "page_number of total_pages".
> Something like "page 3 of 8". This at times helps me avoid
> some classroom/testing confusion. In TeX there is a package
> for this, "lastpage" if I remember correctly. How would I
> achieve this with groff?
You can specify an "end macro", which is called at the end of
processing and can do all sorts of finishing-up work, such as
writing the number of pages to an external file that can be read
again at the beginning of the job (you will need to process
the document at least two times, but you're probably running
it several times anyway while creating the document; also,
you need command-line option "-U" to enable writing to files):
.\" ------------------------------------------------------------------------
.em EM
.de EM
.open XX test-numpages
.write XX .nr %% \\n%
.close XX
..
.so test-numpages
.\" ------------------------------------------------------------------------
and then (depending on which macro package you use) set up the
page header to print something like "Page \\n% of \\n[%%]".
If you don't use a macro package, you can quickly set up the
page headers yourself:
.\" ------------------------------------------------------------------------
.wh 0 HD
.wh -2c FT
.de HD
.ev 1
.sp |1c
.tl 'English language test'2013-04-14'Page \\n% of \\n[%%]'
\v'-.8m'\D'l \\n[.l]u 0'
.sp |3c
.ev
..
.de FT
.ev 1
.bp
.ev
..
.\" ------------------------------------------------------------------------
.ps 12
.vs 14
.po 2.5c
.ll 16c
.ev 1
.ps 12
.vs 14
.ll 16c
.lt 16c
.ev
.\" ------------------------------------------------------------------------
Further tips:
With groff, instead of "--", you have to use "\[en]" to get an
en-dash. For left and right quotes use "\[lq]" and "\[rq]".