![]() |
|
| Daemon News Ezine | BSD News | BSD Mall | BSD Support Forum | BSD Advocacy | BSD Updates |
Trawling the Ports CollectionGreg Lehey <grog@lemis.com>Last month we looked at how the Ports Collection can give you a more comfortable environment in which to work. One of the things I mentioned there was the issue of printed documentation for the ports. As I said then,
Let's start that other time now. This month we'll look at how to print some things with the aid of the Ports Collection. Owing to the sheer number of possibilities, we won't get done this time. Document formatsThe documentation you get nowadays can come in a number of formats. In rough order of increasing desirability, you might find:
Formatting groff documents
Unlike most text formatting packages, groff is part of the base system,
since it's needed for man pages. You can format a man page for printing pretty
easily:
That will give you 5144 lines of plain text without page breaks, and even the
primitive markup that man offers will get lost. It looks a lot better if
you print in PostScript, which you can do by specifying the -t option:
What you get out of the printer depends on the printer. If it understands
PostScript, you'll get a nicely printed man page. If it doesn't, you'll get
something which starts like this:
If that's the case, we'll look at a solution in the section on Ghostscript.
If your groff source isn't a man page, you first need to know which
macros the source file wants. You should be able to tell that by the name: by
convention, the last few letters in the name of a groff source file are the name
of the macro package it expects. For example, you'd format the file
/usr/src/usr.bin/gprof/PSD.doc/abstract.me with the me macros:
Use nroff to create plain text and groff to create PostScript output. groff also has a large number of other knobs to tweak, but there's not space in this article to go into that. The good news is that the documentation for troff, which used to be subject to an AT&T license, is now free and should become available in the BSD distributions soon. GhostscriptOne of the problems with most formatting programs is that they produce output in PostScript. At the very least you want to look at them before you print them, so one way or another you're going to need ghostscript. There are a number of things that you can do with ghostscript:
Displaying PostScriptYou can use ghostscript directly to display PostScript on your screen, but it's rather a complicated tool. Two wrappers are available to make life easier: ghostview and gv. ghostview is the older of the two, and it has a relatively primitive-looking interface. gv looks more professional. It's not until you use both tools that you discover that you can do more with ghostview. Both tools work in pretty much the same way: you start them either from the command line or from a menu. The PgUp and PgDn keys move between pages. You can also enlarge sections of the image. With ghostview you just mouse click on the area you're interested in; the left button gives the least magnification, the right button the most. With gv you need to press the middle button and then drag through a menu to get the magnification you want. You can also magnify or reduce the entire document, and of course you can print individual pages. Printing with ghostscript
ghostscript has a rather annoying syntax, and in general you don't want
to run it from the command line. As a print filter, you'd put it in your
lpd configuration. For example, I have an Epson Stylus 740 colour
printer to which I want to print web pages with Netscape Communicator.
Netscape produces PostScript output. The entry in /etc/printcap looks
like this:
Most of the magic here is in the filter /usr/local/libexec/psfilter2,
which looks like this:
This tells ghostscript to use the definition file stc500ph.upp (part of the ghostscript distribution) to convert from PostScript to something the printer can understand. Converting to PDF
Although ghostscript handles mainly PostScript, it also has some
understanding of PDF, and it can convert between the two formats. The easiest
way to do this is to use the scripts ps2pdf and pdf2ps which are
supplied with ghostscript:
pdf2ps works in the same manner. Note that you can also use acroread to convert PDF into PostScript; it has this facility to enable it to print to PostScript printers.
If you're creating text for a book or some such, you may find that ps2pdf
is not specific enough for what you want to do. I use groff to format my
book, ``The Complete FreeBSD''. Here's a slightly simplified version of the
Makefile target for creating PDF versions of the chapters:
In this Makefile, CHAPTERS is a list of the source file names (as you can guess, they use the mm macros), and GS is the name of the ghostscript executable. The PostScript versions are put in the subdirectory ps, and the PDF versions are put in the subdirectory pdf. Handling PDF with Acrobat readerAdobe charges real money for their Acrobat text processing software, and if that weren't enough, it only runs on Microsoft and Mac OS X. The reader is a different matter, though: you can download a Linux version for free. If you don't like the proprietary smell of Acrobat reader, you don't have to use it: ghostview handles it as well. Where are we now?As you can see, text processing is a can of worms. I've barely scratched the surface here; we'll get back to the subject in the months to come, but for next month I plan to look at some more ``fun'' ports. I'm open to suggestions. |