HELP SOUGHT WITH DIVERSIONS IN TROFF/-MS

Bertrand Meyer bpm at ucsbcsl.UUCP
Tue Nov 6 08:24:12 AEST 1984


Could someone help me with the following troff (under -ms) problem,
whose solution I have been unable to find in the manuals?

I want a macro which will accumulate some text from the input,
so that I can later use this text twice,
with different attributes each time
(in particular with different fonts: once in roman, once in boldface).
I have tried a solution along the lines of the following:

.de aS	\"macro to start accumulating
.di xX	\"start diversion
..

.de aE	\"macro to end accumulating
.di	\"end diversion
..

The idea is to use the macro in the following way:

.aS      \"start accumulating
Here comes the text
.aE      \"end accumulating


Then when I need the accumulated text for the first time, say in roman
and centered, I would write:

.R
.ce 100
.xX
.ce 0

The second time around, I want it, say, in boldface, indented:

.B
.in +5n
.xX
.in -5n
.R


However, this does not work; there is no way I can get different attributes
each time. I have tried different tricks (using environments, etc.), but to
no avail.

Let me mention why I tried this: I wanted a macro which would combine the
effects of .NH and .XS-.XE by collecting the title automatically for the
table of contents. I have a temporary solution (it uses a macro instead of
a diversion, where one of the macro arguments is the section title to be
collected). This works more or less but:
	- it restricts titles to be at most one line long (is there any way
	  to have longer macro arguments?)
	- I still have a problem in that .ce will center the macro argument
	  differently from anything else, which is rather ugly for a
	  chapter heading where the the chapter title is not well centered
	  below the word "CHAPTER" ! (I am writing books and want to submit
	  camera-ready manuscripts)
	- It is intellectually irritating not to be able to use diversions
	  properly.

Thus I would greatly appreciate it if some troff wizard could help me.
Please send me mail. Unless the solution is trivial and I have overlooked
some elementary feature of troff, I will make it public as well as any
useful macro I devise.
Please no flame, I am still a fairly novice user of troff
(although I feel I am becoming an expert rapidly, which seems to be the
only way one can use this system at all). 

-- 
-----------------------------------------------------------------------------
Bertrand Meyer			UUCP: ...!ucbvax!ucsbcsl!bpm
Visiting Professor		CSNET: bpm at ucsb.CSnet-relay
Department of Computer Science	ARPANET:ucsbcsl!bpm at BERKELEY or
University of California		bpm%ucsb at csnet-relay (usually slower)
Santa Barbara, Ca. 93106
Telephone (805) 961-4385 or 961-4321
-----------------------------------------------------------------------------



More information about the Comp.unix.wizards mailing list