[comp.text] troff .DC macro for drop caps, version 2.0

bobm@agsm.unsw.oz (Robert Marks) (02/21/88)

Below is a shar file containing version 2.0 of the .DC drop cap troff macro
which now automatically works with .ls 2 double spacing, and takes an
argument specifying the size (in lines spanned) of the drop cap (default=2).
Because of the 99-point limitation of \s(NN, the macro abandons drop caps
greater than 99 points in size.  Thanks to Dean Okamura for suggesting the
use of \& and that the size of the drop cap should be a function of the
ambient point size, .s.  The bug pointed out by several people has been
fixed by explicit examination of drop cap size >< 36 points.
	I haven't been able to see how to separate a string into the first
character and the rest using troff functions -- although john@basser.oz.au
suggested a way of capturing the first character (unless a slosh, \) -- so
one still has to put up with incomplete words (eg. ut) from spell.
	Comments and suggestions welcome,  Bob

Robert MARKS, Australian Graduate School of Management, University of
              New South Wales, PO Box 1, Kensington, NSW 2033, Australia.

PHONE:  +61 2 662-0271				Fax: +61 2 662-2451
ARPA:   bobm%agsm.unsw.oz@uunet.uu.net		ACSnet: bobm@agsm.unsw.oz
CSNET:  bobm%agsm.unsw.oz.au			JANET: agsm.unsw.oz!bobm@ukc
UUCP:   {uunet,hplabs,ukc,mcvax,ubc-vision,nttlab}!munnari!agsm.unsw.oz!bobm

#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rw-r-----   1 bobm     bobm        4281 Feb 21 17:37 dropinmm
#
echo 'x - dropinmm'
if test -f dropinmm; then echo 'shar: not overwriting dropinmm'; else
sed 's/^X//' << '________This_Is_The_END________' > dropinmm
X.\"
X.\" The following is a (revised) short troff macro for creating drop caps
X.\" at the beginning of lines or paragraphs or sections.
X.\" Its first argument is the string to be dropped,
X.\" and its second (optional) argument is the number of lines to be
X.\" spanned (2, 3, 4, or 5; default=2).
X.\" The revised version will work with double-spacing (.ls 2)
X.\"
X.\" Written by Robert Marks, bobm@agsm.unsw.oz.au  -- Version 2.0, Feb 19, 1988
X.\"	with suggestions by  dean@jpl-devvax.jpl.nasa.gov (Dean Okamura)
X.\"
X.\"		DC sub-macro -- indent revert, trap turned off
X.de In
X'in
X.wh \\n(v2u
X..
X.\"		.DC  Drop Capital letter to the next line
X.de DC
X.br
X.nr nL 2
X.	if "\\$2"3" .nr nL 3
X.	if "\\$2"4" .nr nL 4
X.	if "\\$2"5" .nr nL 5
X.nr fS \\n(.s
X.nr pS (\\n(nL*\\n(.L*\\n(.v/10)+(35*\\n(fS*(3*\\n(nL-4)/200)
X.ie \\n(pS>99 \{\
X.	tm   The drop cap on line \\n(c. of file \\n(.F is too large --
X.	tm   (\\n(pS > 99), ... so this drop cap has been abandoned.
X\\$1\c\}
X.el \{\
X.	ne \\n(nL
X\&
X.	mk hH
X.	nr v2 (\\n(nL*\\n(.L*\\n(.v)+\\n(hH
X.	nr vV \\n(.L*(\\n(nL-2)
X.	sp \\n(vV
X.	ie \\n(pS>36 \{\s(\\n(pS\\$1\s\\n(fS
X.		nr hS \w'\s(\\n(pS\\$1\s\\n(fS\\^'\}
X.	el \{\s\\n(pS\\$1\s\\n(fS
X.		nr hS \w'\s\\n(pS\\$1\s\\n(fS\\^'\}
X.	in +\\n(hSu
X.	sp |\\n(hHu
X.	wh \\n(v2u In\}
X..
X.\" Description of the number registers used:
X.\"	nL is the size (in lines) of the drop cap
X.\"	fS is the existing font size (in points)
X.\"	pS is the drop cap size (in points)
X.\"	hH is the position of the top line (in u)
X.\"	v2 is the position of the In trap to turn off the indent of +hSu
X.\" The following text illustrates the drop cap macro in action:
X.\"
X.DC P
Xut this macro at the top of this file and ditroff it to your
Xfavourite output laser printer to see what it does.
XRemember that two-line drop caps look best with at least two and preferably
Xthree lines of text around them, so that the large letter
X(point size = \n(pS in this paragraph) stands out.
XIt uses \e& to print nothing on the top line.
XFor larger -- three-, four-, or five-line -- drop caps, invoke .DC with
Xa second argument of 3, 4, or 5, respectively.
XNote that .DC works with .ls 2 double-spacing as well.
X.br
X.DC P 3
Xut this macro at the top of this file and ditroff it to your
Xfavourite output laser printer to see what it does.
XRemember that two-line drop caps look best with at least two and preferably
Xthree lines of text around them, so that the large letter
X(point size = \n(pS in this paragraph) stands out.
XIt uses \e& to print nothing on the top line.
XFor larger -- three-, four-, or five-line -- drop caps, invoke .DC with
Xa second argument of 3, 4, or 5, respectively.
XNote that .DC works with .ls 2 double-spacing as well.
X.br
X.DC P 4
Xut this macro at the top of this file and ditroff it to your
Xfavourite output laser printer to see what it does.
XRemember that two-line drop caps look best with at least two and preferably
Xthree lines of text around them, so that the large letter
X(point size = \n(pS in this paragraph) stands out.
XIt uses \e& to print nothing on the top line.
XFor larger -- three-, four-, or five-line -- drop caps, invoke .DC with
Xa second argument of 3, 4, or 5, respectively.
XNote that .DC works with .ls 2 double-spacing as well.
X.br
X.DC P 5
Xut this macro at the top of this file and ditroff it to your
Xfavourite output laser printer to see what it does.
XRemember that two-line drop caps look best with at least two and preferably
Xthree lines of text around them, so that the large letter
X(point size = \n(pS in this paragraph) stands out.
XIt uses \e& to print nothing on the top line.
XFor larger -- three-, four-, or five-line -- drop caps, invoke .DC with
Xa second argument of 3, 4, or 5, respectively.
XNote that .DC works with .ls 2 double-spacing as well.
X.br
X.ps 16
X.vs 18
X.DC P 5
Xut this macro at the top of this file and ditroff it to your
Xfavourite output laser printer to see what it does.
XRemember that two-line drop caps look best with at least two and preferably
Xthree lines of text around them, so that the large letter
X(point size = \n(pS in this paragraph) stands out.
XIt uses \e& to print nothing on the top line.
XFor larger -- three-, four-, or five-line -- drop caps, invoke .DC with
Xa second argument of 3, 4, or 5, respectively.
XNote that .DC works with .ls 2 double-spacing as well.
________This_Is_The_END________
if test `wc -l < dropinmm` -ne 108; then
	echo 'shar: dropinmm was damaged during transit (should have been 108 bytes)'
fi
fi		; : end of overwriting check
exit 0

daw@houxs.UUCP (David Wolverton) (02/23/88)

I tried the drop-cap macro (version 2.0) that was just posted.
It puts the cap so that the base of the cap is aligned with the
last "indented" line of text, rather than the drop-cap design
I was expecting (top of cap aligned with top of first line of text).
Can someone figure out how to modify the macro to do this?  I am
not enough of a troff guru to do it myself.

Example:

    n this paragraph,
III the drop-cap is not
 I  aligned with the top
 I  line, but rather with
III the bottom line.   Is
there a way to fix this

 SSSS o that the top of the
S     drop-cap is aligned
 SSS  with the FIRST line
    S of the paragraph body?
SSSS  I think this makes a
      much better-looking
drop-cap design.


Dave Wolverton
AT&T
ihnp4!houxs!daw

barnett@vdsvax.steinmetz.ge.com (Bruce G. Barnett) (03/08/88)

In article <688@houxs.UUCP> daw@houxs.UUCP (David Wolverton) writes:
|Can someone figure out how to modify the macro to do this? 

fiddle with the line that says:
.nr pS (\\n(nL*\\n(.L*\\n(.v/10)+(35*\\n(fS*(3*\\n(nL-4)/200)

change the value to 35 to something larger.

-- 
	Bruce G. Barnett 	<barnett@ge-crd.ARPA> <barnett@steinmetz.UUCP>
				uunet!steinmetz!barnett

bobm@agsm.unsw.oz (Robert Marks) (03/09/88)

In article <4021@vdsvax.steinmetz.ge.com> barnett@steinmetz.ge.com
(Bruce G. Barnett) writes:

>In article <688@houxs.UUCP> daw@houxs.UUCP (David Wolverton) writes:
>|Can someone figure out how to modify the macro to do this? 
>
>fiddle with the line that says:
>.nr pS (\\n(nL*\\n(.L*\\n(.v/10)+(35*\\n(fS*(3*\\n(nL-4)/200)
>
>change the value to 35 to something larger.
>	Bruce G. Barnett 	<barnett@ge-crd.ARPA> <barnett@steinmetz.UUCP>
>				uunet!steinmetz!barnett

Yes.  The macro .DC embodies the assumption that with the vertical spacing
set to N points (.vs N), the read-only register .v = 10*N units.
But this is machine-dependent and may vary.  After corresponding with David
Wolverton, I believe that on his machine .v = 3*N, so Bruce Barnett is right:
David should be OK with an amended line:
 .nr pS (\\n(nL*\\n(.L*\\n(.v/3)+(35*\\n(fS*(3*\\n(nL-4)/200)
                              ^instead
Bob Marks

daw@houxs.UUCP (David Wolverton) (03/09/88)

In article <4021@vdsvax.steinmetz.ge.com>, barnett@vdsvax.steinmetz.ge.com (Bruce G. Barnett) writes:
> In article <688@houxs.UUCP> daw@houxs.UUCP (David Wolverton) writes:
> |Can someone figure out how to modify the macro to do this? 
> 
> fiddle with the line that says:
> .nr pS (\\n(nL*\\n(.L*\\n(.v/10)+(35*\\n(fS*(3*\\n(nL-4)/200)
> 
> change the value to 35 to something larger.

This equation for computing pS assumes that the value in number register .v is
10 times the current vertical separation set by .vs (default 12pts.).  It turned
out that in my case (DWB 2.0 printing to Imagen 8/300), the relationship
between .v and .vs was different.  The equation .vs = (.v - 2)/4 gives me
approximately the right results for typical font sizes (e.g. 10 - 18 pts.).
(Thanks to Bob Marks for help with figuring this out.)

Since I'm not concerned with double-spaced text, I use the equation
	.nr pS (\\n(nL*(\\n(.v-2)/4)
which seems to work for me.

Does anyone know of a way to find the value of the vertical separation set by .vs
without using .v, or the right equation to adjust the value in .v to get this
information independent of the destination?

Dave Wolverton
ihnp4!houxs!daw