************* BACK AND FORTH PAGING SUBROUTINE ************

PAGEFLOP

If they want to quit, do so
 If They want to quit subsession, Do SO!
  Decrement LOCAL and GLOBAL Page Counters

FORWARD

  Increment LOCAL and GLOBAL Page Counters
   *************** END PAGEFLOP *********************
  ****** CHAPTER INTERNAL SELECTOR ALGORITHM ******

SELECTOR

   Reset Local Page Counter

SELAGAIN

 CHECK IF ONLY A <CR>

WRONGSEL

YOUR SELECTION IS NOT IN THE 0 - #SELIMIT  RANGE  Please Try Again

AANVANG

Copyright CourseWare Technologies Inc., 1985-88


 Lesson - 3


 TEXT FORMATTING 
 WITH THE nroff PROGRAM 

MENU

Text Formatting|Topics to Learn|3-0|13,38
    #               Topic
   ---              -----
    1  -  Introduction to Text Formatting
    2  -  Introduction to nroff
    3  -  Basic nroff Requests
    4  -  Predefined Macros
    5  -  Defining Your Own Macros
    6  -  Invoking nroff
    7  -  Preprocessors
    8  -  Other Word Processing Tools
    9  -  Lesson Review
    0  -  Return to the Main Menu

P1

Text Formatting|Introduction to Text Formatting|3-1.1|13,54
     UNIX provides a wide variety of tools for 
text processing.


     The extent of tool utilization will depend on 
the sophistication of your equipment and the extent 
of your skills.


     Available text processing tools range in 
sophistication from those intended for dumb terminals 
and line printers, to those for smart terminals and 
fancy typesetting equipment.

P2

Text Formatting|Introduction to Text Formatting|3-1.2|8,54
     The most basic text processing tools are the 
editors:  line editors like ed or ex and screen
editors like vi or emacs.


     Advanced text processing utilities like nroff, 
troff, tbl, or eqn add many features for enhancing 
the appearance of your output.

P3

Text Formatting|Introduction to Text Formatting|3-1.3|9,58
     As you saw earlier, text formatting is the process
of manipulating text to give it a certain appearance, 
either on the screen or on paper.  


     You can do your formatting as you enter text into 
a file, or you can rely on a program to do the formatting 
for you.  If you rely on a program, you have to specify 
formatting instructions.

P4

Text Formatting|Introduction to Text Formatting|3-1.4|7,54
     You have seen how some printing programs like cat 
will print a file without doing any formatting.  Other 
programs like pr allow you to specify some formatting 
by using certain options on the command line.  Sophisticated
programs like nroff or troff can interpret any internal 
formatting instructions and perform very elaborate 
rearrangements of your text.

PR

?? next revision add an option to pr plus syntax stuff

P5

Text Formatting|Introduction to Text Formatting|3-1.5|13,61
     Remember that text formatting with UNIX is a two-step
process:

 1.  Use an editor like vi to enter both text AND formatting 
     instructions into a file.  The internal instructions tell 
     a formatting program like nroff how specific parts of the
     text are to be arranged.

 2.  Leave the editor and pass the file to a printing program.
     If you choose a printing and formatting program like
     nroff, it will search the file for formatting instructions,
     interpret them, arrange the text, and send the output 
     either to your screen, a printer, or a file.

P6

Text Formatting|Introduction to nroff|3-2.1|7,54
     A file containing your text and any embedded 
formatting instructions is called the input file.  
The rearranged text is called the output.


     You can use the nroff program whether or not
you choose to include internal formatting instructions.

P7

Text Formatting|Introduction to nroff|3-2.2|13,58
     When you use nroff on a file that does not include 
internal instructions, it will do the following formatting 
by default:

      *  fill in each line of the output to make all lines
         the same length,
      *  justify the right and left margins,
      *  hyphenate long words at the end of a line, and
      *  single space the output.


     It DOES NOT produce top or bottom margins, NOR does it 
separate text into pages.

P8

Text Formatting|Introduction to nroff|3-2.3|16,54
     When you include nroff instructions in your input file
and/or use a macro package, you can gain more control over 
your output.  By using nroff requests and macros, you can 
do things like:

     *  specify margin sizes, line length, and line spacing,
     *  choose justified or ragged margins,
     *  specify the page length,
     *  create black lines in the output,
     *  center or underline text,
     *  indent blocks of text,
     *  create specialized headers and footers,
     *  print in columns,
     *  print footnotes at the bottom of the page,
     *  create bulleted lists, and
     *  produce numbered headings.

P9

Text Formatting|Introduction to nroff|3-2.4|9,54
     There are three types of nroff instructions:

                  *  requests
                  *  predefined macros
                  *  user-defined macros


     The basic nroff instructions from which all other
instructions can be built are called requests.

P10

Text Formatting|Introduction to nroff|3-2.5|7,57
      Basic requests can be used to build other instructions.
The new command is called a macro.  Collections of macros
predefined by someone else are called macro packages.


     Any new macros that you write are referred to as
user-defined macros.

P11

Text Formatting|Basic nroff Requests|3-3.1|13,54
     All nroff instructions consist of three parts:

           *  a period (in the first column of a line)
           *  a 2-character name
           *  an optional argument


     When a period appears in the first column of a line,
it signals the beginning of an nroff instruction.  If a 
space or any other character precedes the period, nroff 
will consider the line to be text and try to format it.  
Therefore, all nroff instructions (requests and macros) 
must appear alone on a separate line in your file.

P12

Text Formatting|Basic nroff Requests|3-3.2|14,54
     The general syntax of all nroff instructions is:

  .instruction name [+ or -][#][unit of measurement]

For example, the request to indent all following text 
one additional inch is:

    .in +1i     where

     .   indicates that the line is an nroff request,
     in  is the request name,
     +   means to increment the default value,
     1   is the number to increment by, and
     i   is the unit of measurement for inches.

P13

Text Formatting|Basic nroff Requests|3-3.3|7,54
     Now we'll cover the function and syntax for several
of the basic requests.


     There are many more requests than we have time
to cover.  Please refer to your system documentation
for additional commands.

P14

Text Formatting|Basic nroff Requests|3-3.4|17,60
REQUEST:     .po [n]    (for page offset)

FUNCTION:    sets the width of the left margin to n, that is, 
              the amount of space between the left edge of the 
              screen or paper and the beginning of the text.

DEFAULT:     n = 0; no offset

EXAMPLES:
    .po 10   makes the left margin 10 characters wide
    .po +10  increases the left margin 10 characters more 
             than it was before
    .po 1i   makes the left margin 1 inch wide
    .po 1    makes the left margin 1 character wide 

Note the difference between .po 1i and .po 1--if you mean 
inches, you have to specify the unit of measurement.

P15

Text Formatting|Basic nroff Requests|3-3.5|16,54
REQUEST:   .ll [n]   (for line length)

FUNCTION:  specifies how long each line should be; 
            the remaining space forms the right margin.

DEFAULT:   n = 6.5 inches

EXAMPLES:
    .ll 55   makes each line 55 characters wide
    .ll -10  decreases the previous line length 
             by 10 characters 
    .ll 6i   makes each line 6 inches long
    .ll 6    makes each line 6 characters long 

Note the difference between .ll 6i and .ll 6--if you mean 
inches, you have to specify the unit of measurement.

P16

Text Formatting|Basic nroff Requests|3-3.6|11,60
REQUEST:  .fi    (for fill in)

FUNCTION: nroff usually ignores the placement of carriage
           returns in your input file.  Text from the input 
           file will be filled in on each line of the output
           until the right margin is reached. Extra spaces 
           will be added between words to make the lines 
           exactly the length you requested with .ll.  This
           is also known as adjusting or justifying text.

DEFAULT:   filling in lines is done by default

P17

Text Formatting|Basic nroff Requests|3-3.7|8,54
REQUEST:  .nf    (for no fill)

FUNCTION: Lines in the output will appear exactly as 
           they do in the input file.  Wherever you put 
           a carriage return in the input file, it will 
           occur in the output.

DEFAULT:  filling in lines is done by default

P18

Text Formatting|Basic nroff Requests|3-3.8|13,60
REQUEST:  .na    (for no adjusting)

REQUEST:  .ad    (for adjusted)

FUNCTION: You may want to have your text filled in, but
           you may not like a perfectly adjusted right margin.
           If you prefer a ragged right margin, where the
           text approaches the line length but each line is
           not exactly the same length (like typewriter 
           output) use the .na request.  The .ad request will
           turn adjusting back on again if was stopped.

DEFAULT:  text is adjusted by default

P19

Text Formatting|Basic nroff Requests|3-3.9|13,54
REQUEST:  .pl [n]   (for page length)

FUNCTION: establishes the length of each page of output.
           Legal paper is 14 inches long, stationary may be 
           7 inches long, labels are 2 inches long, your 
           terminal screen is 24 lines long.

DEFAULT:  n = 11 inches

EXAMPLES:
    .pl 14i   makes the page 14 inches long
    .pl -3i   makes the page length 3 inches less
              than it was before

P20

Text Formatting|Basic nroff Requests|3-3.10|13,54
REQUEST:  .ls [n]   (for line spacing)

FUNCTION: sets the vertical line spacing.  It controls
           whether your output is single, double, triple
           spaced, etc.  n must be an integer, i.e., you
           cannot set 1.5 spacing.

DEFAULT:  n = 1, single spaced output

EXAMPLES:
          .ls 2  double spaces output
          .ls 3  triple spaces output

P21

Text Formatting|Basic nroff Requests|3-3.11|13,54
REQUEST:  .sp [n]   (for insert blank spaces)

FUNCTION: inserts n blank spaces in the output
           regardless of the line spacing set with .ls.

DEFAULT:  n = 0

EXAMPLES:
    .sp 2    inserts 2 blank lines in output
    .sp 3i   inserts 3 inches of blank space in output
    .sp -1i  moves upwards 1 inch before continuing
             to print
??? create graphic illustrating ls and sp differences
L: 3au_spacing

P22

Text Formatting|Basic nroff Requests|3-3.12|8,54
REQUEST:  .br    (for break text here)

FUNCTION:  breaks a line and returns to the beginning
            of the next line before continuing to print.
            This is the way to force a carriage return in 
            the output.  No blank lines are added.

DEFAULT:   none

P23

Text Formatting|Basic nroff Requests|3-3.13|13,54
REQUEST:  .bp [n]   (for begin new page)

FUNCTION: stops printing the current page and begins at the
           top of a new page.  If you add an n, it
           will be the page number for the new page.

DEFAULT:  n = 1 more than the last page number

EXAMPLES:
    .bp 2    begins new page and sets new page number to 2
    .bp +3   begins new page and sets number to old
             number plus 3

P24

Text Formatting|Basic nroff Requests|3-3.14|13,54
REQUEST:  .ce [n]   (for center)

FUNCTION: centers the next n lines of text in the
           input file.

DEFAULT:  n = 1 

EXAMPLES:
    .ce      centers the following line of text
    .ce 50   centers next 50 lines
    .ce 0    stops centering text

P25

Text Formatting|Basic nroff Requests|3-3.15|13,54
REQUEST:  .in [n]   (for indent)

FUNCTION: starts indenting all text the amount specified 
           in the argument

DEFAULT:  n = 0 characters

EXAMPLES:
    .in 8     starts indenting 8 characters
    .in -8    indents 8 characters less than before
    .in 2i    starts indenting 2 inches
    .in +10   indents 10 characters more than the
              previous indent
    .in 0     stops indenting
??? create graphic illustrating ce and in differences
L: 3au_center

P26

Text Formatting|Predefined Macros|3-4.1|16,69
     A macro is a collection of nroff requests that has a 
name and is defined in a way that nroff can refer to.

     Sets of predefined macros are called macro packages 
or macro libraries.

     There are several macro packages that may be provided 
with a UNIX system:

 *  the mm macros (memorandum macros) written at Bell Labs and
    usually available with the Programmer's Workbench package
 *  the me macros written at UC Berkeley and available with 
    Berkeley UNIX systems
 *  the ms macros (manuscript macros) also written by Bell Labs
    and available with UNIX and many other versions of UNIX

P27

Text Formatting|Predefined Macros|3-4.2|5,54
     We'll just mention a few of the mm macros to give
you the general notion of macro usage.  There are over
90 macros in the Memorandum Macro Package.  You should 
study the documentation covering the macro packages 
that came with your system.

P28

Text Formatting|Predefined Macros|3-4.3|11,54
MACRO:  P [type]   (for Paragraph)

FUNCTION: skips a line and starts a new paragraph with 
           the style: type

DEFAULT:  type = 0, unindented paragraph
           type = 1, paragraph indented 5 spaces

EXAMPLES:
    .P     begins an unindented paragraph
    .P 1   begins a paragraph indented 5 spaces

P29

Text Formatting|Predefined Macros|3-4.4|15,64
MACRO:  H [level] ["text of heading"]

FUNCTION: prints the text of heading indented according
           to the specified level

LEVELS: 
   level 1: 1.  HEADER  (underlined, followed by 1 blank line)
   level 2: 1.1 Header   (underlined, followed by 1 blank line)
   level 3: 1.1.1 Header (underlined, no new line)
   level 4: 1.1.1.1 Header  (underlined, no new line)
                    :                :
   level 7: 1.1.1.1.1.1.1 Header  (underlined, no new line)

EXAMPLES:
    .H 1 "SECTION 1"     1. SECTION 1
    .H 4 "Case B"        2.5.3.1 Case B
??? create graphic for .P and .H
L:3au_headers

P30

Text Formatting|Predefined Macros|3-4.5|13,54
     Some macros must be used in pairs with one macro
to indicate the beginning of some special treatment
(like a footnote or a list), and another to indicate 
the end of the treatment.


     Some examples of paired macros include:

   *  FS-FE       begin and end a footnote
   *  DS-DE       begin and end a display
   *  TS-TE       begin and end a table
   *  EQ-EN       begin and end an equation
   *  BL-LI-LE    begin a bulleted list, start each 
                  item, and end the list

P31

Text Formatting|Predefined Macros|3-4.6|2,54
      Let's look at the paired macros .FS and .FE
for creating footnotes. 

P32

Text Formatting|Defining Your Own Macros|3-5.1|16,58
     When you use a series of requests or predefined
macros over and over again, you could use them to define 
your own macro.  A user-defined macro allows a group of
requests or text to be given a name and invoked by using 
that name.


     User-defined macros should be named with an uppercase
letter followed by a lowercase letter to distinguish them
from predefined macros (which usually have 2 uppercase 
letters in the name) and nroff requests (which use 2 
lowercase letters).


     Macros must be defined in your file BEFORE they are
called.

P33

Text Formatting|Defining Your Own Macros|3-5.2|16,54
     Begin your macro definition with .de (for define), 
then include any requests or existing predefined or 
user-defined macro names, one per line.  End your 
definition with  .. .  If, for example, you want 
to write a name and address macro for yourself,
it might look like the following:

    .de Me                 (begin definition, name macro)
    .sp                    (skip one line)
    .nf                    (don't fill in lines)
    Maria Sanchez
    7777 Coast Blvd.
    La Jolla, CA   92037
    .sp 2                  (skip 2 lines)
    .fi                    (start filling in lines)
    ..                     (end definition)

P34

Text Formatting|Defining Your Own Macros|3-5.3|16,54
     You can put your definition at the top of every 
file you want to use it in or you can make a separate 
file that contains all of your personal macros.  


     If you have a separate file of macros called
mymacs, you can access your definitions 3 ways:

 *  use the :r mymacs command in the editor to read 
    the definitions into your file,
 *  place the nroff request .so /usr2/sanchez/mymacs
    at the top of your text file.  This request switches
    over to the named file, reads it, then returns to 
    the next line in your file.
 *  include your mymacs file as an argument on the
    nroff command line before your text file name.
??? give examples of these three in graphic

P35

Text Formatting|Invoking nroff|3-6.1|13,54
     The syntax for the nroff command is:

nroff [-macro package] [options] filename


     With nroff command line options you can 
choose from the various macro packages:

nroff -me file   reads the me macro package 

nroff -ms file   reads the ms macro package 

nroff -mm file   reads the mm macro package 

P36

Text Formatting|Invoking nroff|3-6.2|12,54
     You can print only selected pages of your file with
the -olist option.  For example:

    -o5       prints only page 5
    -o-9      prints from the beginning through page 9
    -o3-      prints from page 3 to the end
    -o4-8     prints from page 4 through page 8
    -o5,7,14  prints pages 5, 7, and 14


     You stop the output after every page to allow you 
to print on special paper with the -s option.

P37

Text Formatting|Invoking nroff|3-6.3|7,54
     If you have your own macros package, include it
before the filename.  For example, the command:

nroff  -o-5  -mm  mymacs  report

will nroff the first 5 pages of the file report, reading
the mm macros package and the user's macro file mymacs. 

P38

Text Formatting|Preprocessors|3-7.1|13,54
     A preprocessor is a program that prepares 
data for further processing.


     A few preprocessors that come with your system
include:

 tbl  translates simple descriptions of table layouts
      into detailed formatting instructions for nroff.

neqn translates in-line or displayed mathematical 
      formulae from easy-to-type form into detailed 
      typesetting instructions for nroff

P39

Text Formatting|Preprocessors|3-7.2|13,54
     The tbl preprocessor accepts a description of a 
table and generates nroff requests to format the table.


     The table and its formatting instructions must 
be preceded by the .TS (for Table Start) macro
and ended with the .TE (for Table End) macro.


     Your file must be preprocessed with tbl and
then piped to the nroff or troff program.

tbl  file  |  nroff

P40

Text Formatting|Preprocessors|3-7.3|17,54
      tbl can format tables according to the following 
options affecting the whole table:

       allbox  -  draws a box around each item
       box     -  draws a box around the entire table
       center  -  centers the table on the page
       double  -  draws a double box around the table
       expand  -  expands the table to the full line length


      tbl can format individual lines of data according 
to the following commands:

   r  -  will right adjust any column entry
   l  -  will left adjust any column entry
   n  -  will numerically adjust any column entry, that 
         is, it will line up the decimal points

TBL

??? if you can't do eqn right, don't do it at all.
 *P41
 C: P = 41
 
 TW:Text Formatting|Preprocessors|3-8.4| 17,54
 :integral signs, summation signs, square
 :roots, as well as complicated expressions
 :may be produced.
 :
 :"eqn"  INPUT:
 :
 :
 :x sub i
 :a sub i sup 2
 :          e sup (x sup 1 2 + y sup 2)
 :a over b
 :x sup 2 over a sup 2
 :sqrt (ax sup 2 + bx + c)
 :lim from {n->inf} sum from 0 to n x sub i
 :left [x sup 2 + y sup 2 over alpha right ] -=-1
 :pile {a above b above c}
 :matric {|col {x above y} ccol {1 above 2}}
 :x dot = f(t) bar
 :y dotdot bar -=- n under
 :x vec -=- y dyad
 U:PAGEFLOP
 
 L: 3au_eqn
 *FIG5

P41

Text Formatting|Preprocessors|3-7.4| 7,54
    The syntax for using preprocessors with nroff
and troff is:

tbl file  |  nroff     OR   tbl file  |  troff

neqn file  |  nroff     OR   eqn file  |  troff

tbl  file  |  neqn  |  nroff
tbl  file  |  eqn  |  troff

P42

Text Formatting|Other Word Processing Tools|3-8.1|12,54
     There are many additional word processing tools
available that are beyond the scope of this course.
You may have access to some of them on your system.

checkmm  identifies incorrect use of mm macros

diction  identifies phrases considered to be poor
          word choices; user can create a personal
          file of problems to be looked for

   style  analyzes writing style and prints results
          of 4 standard tests of readability

P43

Text Formatting|Other Word Processing Tools|3-8.2|10,54
worduse  prints information about correct use of 
          words; may be used interactively

  double  looks for consecutive occurrences of the 
          same word

   spell  looks for spelling errors

      wc  counts the number of characters, words and 
          lines in a file