Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Complete Idiot's Guide to Linux
(Publisher: Macmillan Computer Publishing)
Author(s): Manuel Ricart
ISBN: 078971826x
Publication Date: 12/22/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


UNIX Text Processing

To produce fancier output, such as bold text, different typefaces, and so on, you need to use one of UNIX’s formatters such as groff (GNU’s version of the traditional troff formatting program). If you look at the source of a man page, you’ll see the formatting codes that you use with groff. (To see the source, use zless on any document inside of /usr/man/man1/). Here’s an example of what you’ll see:

     .TH man 1 “September 2, 1995”
     .LO 1
     .SH NAME
     man \- format and display the on-line manual pages
     .br
     manpath \- determine user’s search path for man pages
     .SH SYNOPSIS
     man [\-acdfhkKtwW] [\-m system] [\-p string] [\-C config_file] [\-M
      path]
     [\-P pager] [\-S section_list] [section] name ...
     .SH DESCRIPTION
     .B man
     formats and displays the on-line manual pages.  This version knows
     about the
     .B MANPATH
     and
     .B (MAN)PAGER
     environment variables, so you can have
     your own set(s) of personal man pages and choose whatever program you
     like to display the formatted pages.  If
     .I section
     is specified,
     .B man
     only looks in that section of the manual.
     You may also specify the order to search the sections for entries

As you can see from this source text, groff (troff!) formatted files don’t have any blank lines. Formatting commands (macros) must begin at the left margin. The name of the macro usually begins with a dot (.) or an apostrophe (). Formatting continues until another macro overrides it.

The macros you use will depend on the type of document you are designing. The macros in the preceding listing are designed for formatting UNIX manual pages. Man, for example, defines macros such as .B for bold and .I for italics and more complex macros for defining headers, descriptions, and so on. If you have ever composed an HTML page using a text editor, formatting text from the UNIX command line is not all that different (conceptually anyway), except for the markup tags. Markup tags will change depending on the macro package you use. For example, another package called ms provides formatting for papers.

As you might have figured out, what you can do in reality depends on the macros you have. Besides the man macros mentioned earlier, other libraries such as ms, mm, and me are used to format other types of documents (see groff_ms, groff_mm, man, and me in section 7 of the UNIX manual; to get there, type man 7 keyword). The codes and how they format the document differ from package to package.

When your text is formatted in this (somewhat perverse) way, you can generate text, PostScript, HTML, output for LaserJet printers and other formats using the groff command. The resulting file is what you then send to the lpr command to print it. The lpr command takes whatever you give it and spools it to the printer. The syntax looks like this:

     nroff -Tps -macropackage filename | lpr

Substitute macropackage with the name of the macros (man for man pages, ms, me, mm, and so on) and filename with the name of your file.

As you can tell, there’s quite a bit that you need to know in order to produce a simply formatted document. UNIX text processing doesn’t end with groff. Other more sophisticated typesetting systems such as TeX and LaTeX can produce professionally formatted documents. Many printed technical publications are developed and printed using TeX and LaTeX.

So why all the complication? The intent of the UNIX command-line printing system is to produce files with any text editor that can display and print properly to a wide range of devices, including the screen. So you can generate man pages, print them on paper, generate HTML pages, and generate pdf (Adobe Acrobat) files, all from the same formatted file. If you want simply to use word processing or desktop publishing, stick to a GUI word processor such as the one included in StarOffice. It will save you time when all you need is a nice-looking document printed on paper.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.