[comp.text] Constant-width macros for MM

daw@houxs.UUCP (Dave Wolverton) (08/26/87)

This posting contains a set of ditroff macros to supplement MM to provide
the same capabilities for constant-width (i.e. "typewriter") font which 
the MM macro package provides for the Roman, italic, and bold fonts.

My initial approach was to copy the corresponding code for the existing 
comparable macros from MM, but the code was so convoluted that I could never 
have maintained it.  This is my first attempt at writing a nontrivial macro, 
so please excuse my (no doubt) amateur coding style.

The meaning is thus:
	.C	if 0 arguments, change the current font to the CW font;
		if > 0 arguments, print the arguments in alternating fonts,
		first in CW font, then in the current font, etc., up to
		6 arguments, with no intervening whitespace
	.CR	like .C but alternate between CW and R fonts; 0 args is illegal
	.CI	like .C but alternate between CW and I fonts; 0 args is illegal
	.CB	like .C but alternate between CW and B fonts; 0 args is illegal
	.RC	like .C but alternate between R and CW fonts; 0 args is illegal
	.IC	like .C but alternate between I and CW fonts; 0 args is illegal
	.BC	like .C but alternate between B and CW fonts; 0 args is illegal

I have used these for about 6 months, outputting to an Imagen 8/300.  In that 
time the only strange behavior (which I would like to know how to fix) is:

1)  There is a slight, but noticable, gap of space in front of a word set in 
    constant width type with any of .C, .CR, .CI, .CB

2)  If the left margin is indented, such as by a display, TABs on the input may 
    cause different column alignment than on a terminal.  (This may be inherent 
    in the CW font.)

Enjoy!

Dave Wolverton
AT&T
ihnp4!houxs!daw

---------------------------------------------------------------------------
\" Constant-width macros for MM by David Wolverton (ihnp4!houxs!daw).
\" Please send any useful modifications to the author.
.de C
.if \\n(.$>6 .tm Error: .C macro called w/ >6 arguments
.if \\n(.$=0 .ft CW
.if \\n(.$>0 \f(CW\\$1\fP\\$2\f(CW\\$3\fP\\$4\f(CW\\$5\fP\\$6
..
.de CR
.if (\\n(.$<1 || \\n(.$>6) .tm Error: .CR macro called w/ <1 or >6 arguments
\f(CW\\$1\fP\fR\\$2\fP\f(CW\\$3\fP\fR\\$4\fP\f(CW\\$5\fP\fR\\$6\fP
..
.de CI
.if (\\n(.$<1 || \\n(.$>6) .tm Error: .CI macro called w/ <1 or >6 arguments
\f(CW\\$1\fP\fI\\$2\fP\f(CW\\$3\fP\fI\\$4\fP\f(CW\\$5\fP\fI\\$6\fP
..
.de CB
.if (\\n(.$<1 || \\n(.$>6) .tm Error: .CB macro called w/ <1 or >6 arguments
\f(CW\\$1\fP\fB\\$2\fP\f(CW\\$3\fP\fB\\$4\fP\f(CW\\$5\fP\fB\\$6\fP
..
.de RC
.if (\\n(.$<1 || \\n(.$>6) .tm Error: .RC macro called w/ <1 or >6 arguments
\fR\\$1\fP\f(CW\\$2\fP\fR\\$3\fP\f(CW\\$4\fP\fR\\$5\fP\f(CW\\$6\fP
..
.de IC
.if (\\n(.$<1 || \\n(.$>6) .tm Error: .IC macro called w/ <1 or >6 arguments
\fI\\$1\fP\f(CW\\$2\fP\fI\\$3\fP\f(CW\\$4\fP\fI\\$5\fP\f(CW\\$6\fP
..
.de BC
.if (\\n(.$<1 || \\n(.$>6) .tm Error: .BC macro called w/ <1 or >6 arguments
\fB\\$1\fP\f(CW\\$2\fP\fB\\$3\fP\f(CW\\$4\fP\fB\\$5\fP\f(CW\\$6\fP
..

krishnan@hplabsb.UUCP (N K Krishnan) (08/27/87)

dave>  There is a slight, but noticable, gap of space in front of a word set in 
dave>   constant width type with any of .C, .CR, .CI, .CB

We noticed a similar thing here.  In a sequence of the form

	... blah \f(CWblah\fP ....

the space between the blah's is out of proportion to the spaces between
the other words on the same line.  It almost appears as if the distribution
of white space between the words in a line is biased against CW fonts.
With Bold or Italic fonts the problem does not seem to occur.

	= krishnan@hplabs.hp.com

krishnan@hplabsb.UUCP (N K Krishnan) (08/27/87)

dave>I have used these for about 6 months, outputting to an Imagen 8/300.  In that 
dave>time the only strange behavior (which I would like to know how to fix) is:
dave>1)  There is a slight, but noticable, gap of space in front of a word set in 
dave>   constant width type with any of .C, .CR, .CI, .CB

bill> The reason for the gap is that the interword gap in  troff is 1/3 "m".
bill> In other words, it depends on the general width of the font in effect.
bill> If  you have different fonts before  and after an interword gap, troff
bill> uses the "m" of the trailing font, in this case \f(CW.

This is certainly a good tip, but in the example Dave had no interword gap!
It looked something like 
	blah1\f(CWblah2\fPblah3

	=== krishnan@hplabs

wjc@ho5cad.ATT.COM (08/27/87)

Posting-Front-End: GNU Emacs 18.47.1 of Fri Jun 26 1987 on ho5cad (usg-unix-v)


In article <507@houxs.UUCP> daw@houxs.UUCP (Dave Wolverton) writes:
>>   [about some CW macros he supplies]
>>
>>   I have used these for about 6 months, outputting to an Imagen 8/300.  In that 
>>   time the only strange behavior (which I would like to know how to fix) is:
>>
>>   1)  There is a slight, but noticable, gap of space in front of a word set in 
>>	   constant width type with any of .C, .CR, .CI, .CB
>>

The reason for the gap is that the interword gap in  troff is 1/3 "m".
In other words, it depends on the general width of the font in effect.
If  you have different fonts before  and after an interword gap, troff
uses the "m" of the trailing font, in this case \f(CW.

Universal fix is to  replace all instances  of "\f(CW" with "\&\f(CW".
Now, troff sees  a zero-width space of  the same font  as the previous
word.   The font   change occurs after  the   interword gap  has  been
emitted.

BTW, this also  causes problems when  switching back and forth between
italic and other fonts (e.g., \fIS\fRl),  but with the Computer Modern
fonts used in many Imagens, its most noticable with the CW font.

	Bill Carpenter
	(AT&T gateways)!ho5cad!wjc
	HO 1L-410, (201)949-8392

PS:- I learned this tip from Narain  Gehani's "Document Formatting and
Typesetting on the UNIX System" (Silicon Press).

paul@dana.UUCP (Paul Ausick) (08/29/87)

> 
>>  There is a slight, but noticable, gap of space in front of a word set in 
>>   constant width type with any of .C, .CR, .CI, .CB
> 
> We noticed a similar thing here.

I wouldn't swear to this, but the problem probably results from a
troff requirement/bug.  Have you mounted the font CW in one of the
available font positions, with `.fp x CW'? Try that.  You could
also change the DESC file.

The reason: troff reads its input until it reaches a word that can
no longer be fit into the output line.  Then it justifies the line
and lays it on the page.  The justification is the last thing it does.
It can't compute the width of a CW character at that point unless
the font is mounted.

This may be stated imprecisely.  I'm trying to recall something I read
once about troff and can't think of right now.   

A recent book from Hayden, UN*X Text Processing, by Dale Dougherty
and Tim O'Reilly, is the best, most comprehensive thing I've seen
on n/troff.  The answer is probably rattling around somewhere among
its 650+ pages.

/Paul Ausick	...hplabs!dana!paul
-- 
/Paul Ausick
Dana Computer, Inc.
550 Del Rey Ave.		uucp: ...hplabs!dana!paul
Sunnyvale, CA 94086		408/732-0400

daw@houxs.UUCP (Dave Wolverton) (08/31/87)

In article <59900001@hplabsb.UUCP>, krishnan@hplabsb.UUCP (N K Krishnan) writes:
> In a sequence of the form
> 
> 	... blah \f(CWblah\fP ....
> 
> the space between the blah's is out of proportion to the spaces between
> the other words on the same line.

Someone (Bill Carpenter, I think) pointed out that the space is being set
in the trailing font (CW), and that a space from CW font doesn't look "right"
in normal text.  The following will force the space to be set in the first
font:
	... blah \&\f(CWblah\fP ...

Dave Wolverton
AT&T
ihnp4!houxs!daw

daw@houxs.UUCP (Dave Wolverton) (08/31/87)

In article <59900002@hplabsb.UUCP>, krishnan@hplabsb.UUCP (N K Krishnan) writes:
> bill> The reason for the gap is that the interword gap in  troff is 1/3 "m".
> bill> In other words, it depends on the general width of the font in effect.
> bill> If  you have different fonts before  and after an interword gap, troff
> bill> uses the "m" of the trailing font, in this case \f(CW.
> 
> This is certainly a good tip, but in the example Dave had no interword gap!
> It looked something like 
> 	blah1\f(CWblah2\fPblah3

The problem I reported DID occur with an interword gap, but it was not eplicit
in the macros.  Given

	This is a sentence in Roman except
	.C this
	is in CW.

this would format like so

	This is a sentence in Roman except  this is in CW.
	                                  ^^
					"Extra" space

Dave Wolverton
AT&T
ihnp4!houxs!daw