Previous Next Contents

3. Miscellaneous Items

This section discusses some of the miscellaneous things that you may want to know about printing under Linux.

3.1 Formatting

Since most ASCII files are not formatted for printing, it is useful to format them in some way before they are actually printed. This may include putting a title and page number on each page, setting the margins, double spacing, indenting, or printing a file in multiple columns. A common way to do this is to use a print preprocessor such as pr.

$ pr +4 -d -h"Ph.D. Thesis, 2nd Draft" -l60 thesis.txt | lpr

In the above example, pr would take the file thesis.txt and skip the first three pages (+4), set the page length to sixty lines (-l60), double space the output (-d), and add the phrase "Ph.D. Thesis, 2nd Draft" to the top of each page (-h). Lpr would then print pr's output. See its on-line manual page for more information on using pr.

3.2 The PRINTER Environment Variables

All of the commands in the Linux printing system accept the -P option. This option allows the user to specify which printer to use for output. If a user doesn't specify which printer to use, then the default printer will be assumed as the output device.

Instead of having to specify a printer to use every time that you print, you can set the PRINTER environment variable to the name of the printer that you want to use. This is accomplished in different ways for each shell. For bash you can do this with

$ PRINTER="printer_name"; export PRINTER

in csh, you can do it with

% setenv PRINTER "printer_name"

These commands can be placed in your login scripts (.profile or .cshrc), or issued on the command-line. (See bash(1) and csh(1) for more information on environment variables.)

3.3 Printing PostScript files

Printing PostScript files on a printer that has a PostScript interpreter is simple; just use lpr, and the printer will take care of all of the details for you. For those of us that don't have printers with PostScript capabilities, we have to resort to other means. Luckily, there are programs available that can make sense of PostScript, and translate it into a language that most printers will understand. Probably the most well known of these programs is Ghostscript.

Ghostscript's responsibility is to convert all of the descriptions in a PostScript file to commands that the printer will understand. To print a PostScript file using Ghostscript, you might do something like

$ gs -dNOPAUSE -sDEVICE=deskjet -sOutputFile=|lpr thesis.ps

Notice in the above example that we are actually piping the output of Ghostscript to the lpr command by using the -sOutputFile option.

Ghostview is an interface to Ghostscript for the X Window System. It allows you to preview a PostScript file before you print it. Ghostview and Ghostscript can both be downloaded from ftp://prep.ai.mit.edu/pub/gnu/.

3.4 Printing TeX files

One of the easiest ways to print TeX files is to convert them to PostScript and then print them using Ghostscript. To do this, you first need to convert them from TeX to a format known as DVI (which stands for device-independent). You can do this with the tex(1) command. Then you need to convert the DVI file to a PostScript file using dvips. All of this would look like the following when typed in.

$ tex thesis.tex
$ dvips thesis.dvi

Now you are ready to print the resulting PostScript file as described above.

3.5 Printing troff formatted files

$ groff -Tascii thesis.tr | lpr

or, if you prefer,

$ groff thesis.tr > thesis.ps

and then print the PostScript file as described above.


Previous Next Contents