*BSD News Article 43096


Return to BSD News archive

Xref: sserve comp.unix.bsd:16302 comp.unix.misc:16270 comp.unix.questions:61744 comp.unix.sys5.misc:708
Newsgroups: comp.unix.bsd.misc,comp.unix.bsd,comp.unix.misc,comp.unix.questions,comp.unix.sys5.misc
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msunews!uwm.edu!news.alpha.net!news.mathworks.com!panix!cmcl2!admii!smokey!lapoint
From: lapoint@admii.arl.mil (Claude Lapointe )
Subject: troff question
Message-ID: <1995Mar3.171557.7725@arl.mil>
Sender: news@arl.mil (News Administration )
Organization: U.S. Army Research Lab (ARL), APG, MD.
Date: Fri, 3 Mar 1995 17:15:57 GMT
Lines: 78


I'm assisting a user who wants to continuously underline text
in fill mode with default adjustment (left and right margins)
turned on.

I've looked in the recently posted UNIX FAQ, but found nothing
on troff, except a sentence or two stating what troff is.

Although I'm a (very?) knowledgeable user, I don't often (ever?)
do this.  My usage of line drawing in generally to create or
duplicate forms via my own macro packages (which also contain
unskilled-user-friendly macros to format the text), together
with scripts for convenient invocation.  In this sort of use,
I invoke .nf and .na before drawing the lines.  Finally, I
abhor right adjusted margins, so, whenever I have a need to
underline text, I'm in no-adjust mode, and everything works
just the way one would like it to.

There is no problem as long as only 1 word is to be underlined,
but if several words are to be underlined, the effect is as if
adjustment were the last thing done before dumping the output
line buffer, so that the length of any horizontal line is
determined before adjustment. The result when underlining is
that the underline is shorter than the text, by exactly the
amount of the adjustment within the text of interest.

For example,

   word1 word2 word3\l'|0\(ul'
   word1 word2 word3\l'-\w'word1 word2 word3'u\(ul'
   \kqword1 word2 word3\l'|\nqu\(ul'

all produce something like

    word1  word2  word3
      -----------------


I've thought about using (and done some fooling around with)
various combinations of argument passing (to be able to
manipulate the same text repeatedly) with strings, diversions,
and a diversion trap (to determine when the output is filled),
but all my approaches are at best ugly, and I don't have a
way to measure the **adjusted** length of a **portion**
of the output line (ie, word1 word2 word3).

With a lot of a priori knowledge (ie, one or more
preliminary troff runs), I could hardwire stuff that might
work, but it's horrible. It would involve knowing, on the
output line, the text appearing before words 1,2,3 (text1)
and after them (text2), and passing arguments

   1   "text1"
   2    word1
   3    word2
   4    word3
   5   "text2"


into 2 diversions, one .na and the other .ad (a \p suffixed
to this one), getting the difference in lengths of the two,
dividing that by n-1 to obtain d (where n is the number of
words on the output line), augmenting d by the width of a
single blank, and then constructing yet another (adjusted)
diversion:


       text1 word1\h'\ndu'word2\h'\ndu'word3 text2\p


Horrible.


So, my question:

   Does anybody have a better way?

Thanks.