Passing commands thru multi-level troff diversions

lwall at sdcrdcf.UUCP lwall at sdcrdcf.UUCP
Tue May 1 01:56:00 AEST 1984


Certain nroff/troff commands must apply either at every diversion level
or at the outermost level (e.g. commands marked P in the nroff document).
\! works okay when you know how deep you are in diversions, but when writing
macros (such as index and TOC generation) you don't always have that
information.  Additionally, when deep inside diversions (such as inside a
tbl text block inside a floating display), it gets wearisome to type
.cs R 25
\!.cs R 25
\!\!.cs R 25
Constant spaced text.
.cs R
\!.cs R
\!\!.cs R

So, for whatever it's worth, here's something I whipped up a while back:

'''
'''     Do a command OUtside of diversions, or for EVery diversion level.
'''     (Use OU and EV for macro calls, Ou and Ev for bare nroff commands.)
'''
'''	Uparrow is used instead of backslash for the escape character
'''	so that you needn't count backslashes.  Just use one uparrow where
'''	you would want a backslash in the final command.
'''
'''     Examples:
'''
'''	".Ev .cs R 25" can be used in a display to set constant spacing
'''     mode such that it will again be in effect whenever the display
'''     is pulled back in from the diversion.
'''
'''	If number register P contains the current page number,
'''	.Ou .tm Current page number is ^nP
'''	will dump the correct page number to fd 2 regardless of how many
'''	levels deep in diversion you are, and how many pages your floating
'''	display floated across.
'''
.de Ou
.ie '\\n(.z'' \\{\\
.di ??
\!\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.di
.ec ^
.??
.ec
.rm ??
'br\\}
.el \\{\\
\!.ie '\\\\n(.z'' \\\\{\\\\
\!.ec ^
\!\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
\!.ec
\!'br\\\\}
\!.el \\\\{\\\\
\!.Ou "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\!'br\\\\}
'br\\}
..
.de Ev
.di ??
\!\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.di
.ec ^
.??
.ec
.rm ??
.if !'\\n(.z'' \\{\\
\!.ie '\\\\n(.z'' \\\\{\\\\
\!.ec ^
\!\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
\!.ec
\!'br\\\\}
\!.el \\\\{\\\\
\!.Ev "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\!'br\\\\}
'br\\}
..
'''
'''	Same as above, but quoting is different
'''
.de OU
.ie '\\n(.z'' \\{\\
.di ??
\!\\$1 "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
.di
.ec ^
.??
.ec
.rm ??
'br\\}
.el \\{\\
\!.ie '\\\\n(.z'' \\\\{\\\\
\!.ec ^
\!\\$1 "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\!.ec
\!'br\\\\}
\!.el \\\\{\\\\
\!.OU "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\!'br\\\\}
'br\\}
..
.de EV
.di ??
\!\\$1 "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
.di
.ec ^
.??
.ec
.rm ??
.if !'\\n(.z'' \\{\\
\!.ie '\\\\n(.z'' \\\\{\\\\
\!.ec ^
\!\\$1 "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\!.ec
\!'br\\\\}
\!.el \\\\{\\\\
\!.EV "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\!'br\\\\}
'br\\}
..
'''	Larry Wall
'''	{allegra,burdvax,cbosgd,hplabs,ihnp4,sdcsvax}!sdcrdcf!lwall



More information about the Comp.unix mailing list