Article View: net.text
Article #866indexing for nroff/troff plus shape macros
From: E. Sarmas
Date: Mon, 19 May 1986 20:01
Date: Mon, 19 May 1986 20:01
183 lines
4492 bytes
4492 bytes
Here is my version of getting an index for nroff/troff with ms.
Put in the nroff/troff source the line
.IX stuff to be indexed
example
.IX Artificial Intelligence
Up to 4 names are kept by ms. If you donot use ms, the macro IX is very easy
to write. It uses .tm to output to stderr 4 of the parameters then a
repeating string of periods and then the current page number.
Change your makefile or shell script to include this (only sh)
# unlike what manual says all redirections should appear before the command
# for redirecting stderr do
#
# >file.stderr 2>&1 >file.stdout command
#
# assign file.stderr to stdout
# make stderr to be the same as stdout => file.stderr
# assign file.stdout to stdout; does not affect stderr
>indx 2>&1 >text nroff -ms text.rof
cat indx | awk -f itx.awk | sort -f > index.rof
nroff -ms itx_top.rof index.rof > index
where text.rof is your source with .IX commands included. What the above
does is to direct stderr to indx, then pass it through an awk routine that
collects names that appear in many places together. Finally the awk output
is formatted using commands from itx_top.rof which you may alter for your
taste.
Here follows itx.awk
# ms outputs up to four names per index entry
# we use the arrays name[], pages[]
BEGIN { line_length = 74; }
{ page = $NF;
fields = NF - 2;
# trick, merge all fields into one string
pattern = $1;
for (i = 2; i <= fields; i++)
pattern = pattern " " $i;
if (!name[pattern]) {
name[pattern] = 1;
pages[pattern] = page;
}
else
pages[pattern] = pages[pattern] ", " page;
}
END { for (pattern in name) {
left = length(pattern);
right = length(pages[pattern]);
middle = line_length - left - right - 4;
middle_str = "";
for (i = 1; i <= middle; i++)
middle_str = middle_str".";
printf "%s %s %s\n", pattern, middle_str, pages[pattern];
}
}
And here is itx_top.rof
.nr LL 74n
.ls 3
.OF 'Page %'\*(DY''
.EF 'Page %'\*(DY''
.OH '''Index'
.EH '''Index'
.sp 1
.tl ''Index''
.sp 2
.nf
.na
By the way I include here the shape routines that appeared in a 1985 issue
of Software Practice and Experience. The calls are
SX X1 A2 A1 A0 X2 B2 B1 B0
this shapes the text following so that the two side margins have the shape
described by the equations
2
Y = A2 * X + A1 * X + A0 starting with X1
2
Y = B2 * X + B1 * X + B0 starting with X2
All values should be in inches. The default values are
0 0 0.75 3 0 0 0.75 5
which produce
a text
shaped like
this.
US stops shaping
SX and US should appear in pairs.
.\"
.\" SX,US - Shape, Unshape macros from Software Practice and Experience.
.\"
.\" Modified by E.SARMAS
.\"
.\" to work fine and safely inside diversions.
.\"
.de SX
.nr SS 1
.nr IN \\n(.i
.nr L0 \\n(.l
.ie \\.$>0 \{\
.nr X1 0+\\$1i
.nr A2 0+\\$2i
.nr A1 0+\\$3i
.nr A0 0+\\$4i
.nr X2 0+\\$5i
.nr D2 0+\\$6i
.nr D1 0+\\$7i
.nr D0 0+\\$8i
.\\}
.el \{\
.nr X1 0i
.nr A2 0i
.nr A1 -0.75i
.nr A0 3i
.nr X2 0i
.nr D2 0i
.nr D1 0.75i
.nr D0 5i
.GO
.ie '\\n(.z'' \{\
.wh (\\n(nl+\\n(.v)/1v TR
.\\}
.el \{\
.dt (\\n(.d+\\n(.v)/1v TR
.\\}
..
.de US
.nr SS 0
.in \\n(INu
.ll \\n(L0u
..
.de GO
.nr fx (\\n(A2*\\n(X1*\\n(X1/1i/1i)+(\\n(A1*\\n(X1/1i)+\\n(A0
.nr gx (\\n(D2*\\n(X2*\\n(X2/1i/1i)+(\\n(D1*\\n(X2/1i)+\\n(D0
.if \\n(fx>\\n(L0u .nr fx \\n(L0u
.if \\n(fx<0 .nr fx 0
.if \\n(gx>\\n(L0u .nr gx \\n(L0u
.if \\n(gx<0 .nr gx 0
.ie \\n(fx<\\n(gx \{\
'in \\n(fxu
.ll \\n(gxu
.\\}
.el \{\
'in \\n(gxu
.ll \\n(fxu
.\\}
.nr X1 \\n(X1+\\n(.v
.nr X2 \\n(X2+\\n(.v
..
.de TR
.GO
.ie '\\n(.z'' \{\
.ch TR (\\n(nl+\\n(.v)/1v
.\\}
.el \{\
.dt (\\n(.d+\\n(.v)/1v TR
.\\}
..
Technical Details
Message-ID:
<4986@topaz.RUTGERS.EDU>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!husc6!harvard!topaz!sarmasShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!husc6!harvard!topaz!sarmas From: sarmas@topaz.RUTGERS.EDU (E. Sarmas) Newsgroups: net.text Subject: indexing for nroff/troff plus shape macros Message-ID: <4986@topaz.RUTGERS.EDU> Date: Mon, 19-May-86 16:01:37 EDT Article-I.D.: topaz.4986 Posted: Mon May 19 16:01:37 1986 Date-Received: Wed, 21-May-86 01:30:25 EDT Organization: Rutgers Univ., New Brunswick, N.J. Lines: 183 Keywords: indexing, shaping