Printing man Pages

Printing man Pages

Unix man pages are plain-text files written using a special formatting syntax (see man mdoc for a tutorial). The raw files are not suitable for printing because they contain text that the man command uses to produce boldface, underlining, and other text formatting, but in many cases you can translate the man page into HTML or PostScript.

Note that the printing techniques described here work for many, but not all, man pages, simply because some converters may not be able to handle certain formatting commands (the man pages may have been written at different times). However, you'll always be able to see the text on the screenon the printed page you may get truncated text or missing paragraph breaks.

See Chapter 6, "Editing and Printing Files," for more on printing from the command line.

To print a man page to a PostScript printer:

  • man -t command lp

    For example, if you want a printed man page for the date command:

    man -t date lp

    You are using the -t option of the man command to produce PostScript output and piping that into the lp command. If you're not using a PostScript printer, you will probably get a nicely formatted result because Mac OS X includes open -source Unix software that helps non-PostScript printers print PostScript. (If you are curious , see the Gimp-Print Web site, http://gimp-print. sourceforge .net, for more about this software.)

Tip

  • If you wanted to save the PostScript version of a man page, perhaps for use in some future project, then you would simply redirect the output of the man command to a file:

    man -t date > date.ps


Besides converting man pages to PostScript, you can also convert many of them to PDF or HTML (or TIFF, or JPEG, or many other formats). This will allow you to view pages in the Preview application or a Web browser and print them to any printer.

To convert a man page to PDF:

1.
man -t command > command .ps

This creates a PostScript file from the man page. It is important that you include the .ps at the end of the output filename.

2.
open command.ps

This opens the PostScript file. By default, the file opens in the Preview application, which automagically converts it to PDF for display.

3.
Choose File > Save in the Preview application.

You get the standard Mac save-file dialog, where you choose the name and location for saving the file.

4.
Choose PDF from the Format menu in the dialog.

Notice that you have the choice of several formats.

5.
Click Save.

You're done.

To convert a man page to HTML:

1.
Find the raw man page.

Use the -w option to the man commandfor example:

man -w bash

bash is just the name of the command for which we want the man page. Even though bash is your shell, it is still just another command.

 groff -man -Thtml  /usr/share/man/man1/bash.1 >  bash.html 

(You might see some debugging output on your screen from the groff command, but you can ignore it. The new file, bash.html, will not contain the debugging text. The groff command is the GNU version of the roff ( runoff ) typesetting system and provides a variety of formatting features.

2.
You can now try viewing the HTML page with your default browser, even from the command line:

open bash.html

Tip

  • Some man pages convert better than others. If you know HTML, you may be able to edit poorly formatted HTML versions to fix conversion problems.




Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net