neil@yc.estec.nl (Neil Dixon) (03/22/88)
Whilst formatting a document with mm macros, I wish to (temporarily) reduce the size of the page offset. Specifically, I'm trying to include a 132-column wide FORTRAN listing as an example in a document, and since this won't fit on the page size we prefer, I'm quite happy to reduce the left hand margin for this particular example. Has anyone any idea how I can do this? -- Neil Dixon <neil@yc.estec.nl> UUCP:...!mcvax!esatst!neil, BITNET: NDIXON@ESTEC Thermal Control & Life Support Division (YC) European Space Research and Technology Centre (ESTEC), Noordwijk, The Netherlands.
bd@hpsemc.HP.COM (bob desinger) (03/23/88)
Neil Dixon (neil@yc.estec.nl) writes: > Whilst formatting a document with mm macros, I wish to (temporarily) reduce > the size of the page offset. Specifically, I'm trying to include a 132-column > wide FORTRAN listing as an example in a document, and since this won't fit > on the page size we prefer, I'm quite happy to reduce the left hand margin > for this particular example. Has anyone any idea how I can do this? The left margin is settable with the .po troff request. But it sounds like what you really want to do is print 132-column text in less than 132 columns. Would it be all right to do some slight reformatting of the text? For example, if the original looks like: C C This is a very long line of text <...out to column 132> C Here's the next very long line <...out to column 132 again> C Assuming they're lines 51 through 54, would you be happy with something like (dramatically shortened for purposes of display): 51 C 52 C This is a very long line of text\ <...out to column 132> 53 C Here's the next very long line <\ ...out to column 132 again> 54 C If so, you can do this folding of long lines with the `fold' program from Kernighan and Pike's _Unix_Programming_Environment_, page 125. Their version doesn't number lines, although my version (below) does. There is also a System V `fold' program but it doesn't print line numbers or the backslash, and the continued line starts in column 1 instead of ending in the last column as in the example above. Since I run System V, I call my version `Fold' to prevent collisions with the supported program. To create a troffable version of the Fortran source file, type Fold program.f | troffify >program.f.nr and then use ".so program.f.nr" in your document to read it in. The `troffify' script converts \ into \e to make it printable under troff, and prevents troff from interpreting lines that have leading dots and apostrophes. It's also included below. One of the problems you often face when documenting source code is that the sources change up to the last minute. If you have ditroff, you can suck the source code into your file at formatting time with the .sy request (or .SY macro below). A sample usage in your file would be: .\" display the Fortran source .DS I .ft CW \" constant-width (tty) font .SY Fold program.f | troffify .ft P \" previous font .DE The .sy request runs a program, but the program's output isn't captured anywhere or sucked back into troff. I wrote the .SY macro to take care of the messy details of reading the output back into the input stream and clean up after itself. Come to think of it, you can use .SY with any macro package, not just the MM package like its enclosed file name implies. -- bd #! /bin/sh # This is a shell archive. Remove anything before this line, # then unwrap it by saving it in a file and typing "sh file". # # Wrapped by bd at hpsemc on Tue Mar 22 22:32:37 1988 # Contents: # Fold troffify SY.mm PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:$PATH; export PATH echo 'At the end, you should see the message "End of shell archive."' echo Extracting Fold cat >Fold <<'@//E*O*F Fold//' : fold long lines, ala Kernighan and Pike page 125 expand $* | # expand tabs awk ' # add line numbers and fold long lines BEGIN { N = 74 # fold at column 74 (really 79, counting line numbers) for (i = 0; i < N; i++) blanks = blanks " " # make a string of blanks } { if ((n = length($0)) <= N) printf "%3d %s\n", NR, $0 else { printf "%3d ", NR # line number for (i = 1; n > N; n -= N) { printf "%s\\\n", substr($0, i, N) i += N; } printf " %s%s\n", substr(blanks,1,N-n), substr($0,i) } }' @//E*O*F Fold// set `wc -lwc <Fold` if test $1 -ne 19 -o $2 -ne 109 -o $3 -ne 520 then echo ! Fold should have 19 lines, 109 words, and 520 characters echo ! but has $1 lines, $2 words, and $3 characters fi chmod 664 Fold echo Extracting troffify cat >troffify <<'@//E*O*F troffify//' : make troff characters visible in troff output # make backslash visible with \e # make leading dots printable by padding them with the null character # make leading apostrophes printable by padding them with the null character sed -e 's/\\/\\e/g' -e 's/^\./\\\&./' -e "s/^'/\\\\\&'/" $* @//E*O*F troffify// set `wc -lwc <troffify` if test $1 -ne 6 -o $2 -ne 46 -o $3 -ne 293 then echo ! troffify should have 6 lines, 46 words, and 293 characters echo ! but has $1 lines, $2 words, and $3 characters fi chmod 775 troffify echo Extracting SY.mm sed 's/^@//' >SY.mm <<'@//E*O*F SY.mm//' @.\" .SY == execute a command, suck its output back into the input stream @.\" Usage: @.\" .SY command-to-run @.\" .SY cmd1 | cmd2 | cmd3 @.\" .SY "cmd1 | cmd2 | cmd3" @.de SY @.if t .sy \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 >/tmp/troff\n($$ 2>&1 @.if t .so /tmp/troff\n($$ @.if t .sy rm -f /tmp/troff\n($$ 2>/dev/null @.if n tm ! Sorry, nroff can't run .SY programs; continuing.... @.if n .br @.if n >>> Output from \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 @.if n .br @.. @//E*O*F SY.mm// set `wc -lwc <SY.mm` if test $1 -ne 14 -o $2 -ne 92 -o $3 -ne 470 then echo ! SY.mm should have 14 lines, 92 words, and 470 characters echo ! but has $1 lines, $2 words, and $3 characters fi chmod 664 SY.mm echo "End of shell archive." exit 0
bd@hpsemc.HP.COM (bob desinger) (03/24/88)
Oops. The mode for `Fold' should be 775, not 664. Fix this after unpacking with: chmod +x Fold -- bd