GNU Ghostscript

Need to preview and print PostScript Files? Here's a utility that will do just that.
Ghostscript as a Document Post-Processor and Previewer

Integrating Ghostscript into your system is not that difficult. For example, if you routinely write documents in Emacs' LaTeX mode, the following bash script takes the DVI output of Emacs' tex-buffer command, converts it to PostScript, and then post-processes the output through Ghostscript. Finally, it sends the output to the print spooler. This script, gsprint (see Listing 1), can be called by Emacs' tex-print command directly. Note that the commands which call Ghostscript and then spool the output to the lpr daemon should all be typed on one line.

An even shorter version of this script, gspreview (see Listing 2), previews the document and can be called by Emacs' tex-view command under X11. Emacs provides the name of the TeX DVI file as the argument to its tex-print and tex-view commands. All you need to do is specify the names of the external commands. First, make sure that the scripts are located in a directory in the search path (I use /usr/local/bin for my shell scripts). Give them execute permission with the command:

chmod a+x gsprint gspreview

Then add the elisp code shown in Listing 3 to your .emacs file. Whenever you use the tex-print or tex-view commands (ctrl-c ctrl-p and ctrl-c ctrl-v, respectively) in TeX-mode or LaTeX-mode, these shell scripts are called and their commands executed, using the DVI output of the most recent TeX command.

The next bash script, which I named pvga (see Listing 4), uses Ghostscript to preview output on non-X VGA displays. It takes as its argument the name of the TeX DVI output file and two optional arguments: a list of pages to be output and the Y-origin offset for each page. This script can be run from the command line or used as the core routine of a more complex VGA previewer. The list of pages that you want to view, formatted according to the dvips documentation, must be specified before the Y offset.

PostScript in a (Virtual) Box

You can easily replace TeX's Computer Modern fonts with Ghostscript's scalable fonts. By default, dvips calls the MakeTeXPK program, which in turn calls MetaFont, to generate the physical Computer Modern fonts not present on the hard disk.

Printing is faster with bitmap fonts rather than scalable fonts, but scalable fonts that use Adobe's standard encodings provide the complete Adobe character set, including kerning and ligature pairs, which the Computer Modern fonts do not provide. With reasonably fast hardware, you can turn off dvips' font-generation feature and hardly notice a difference in speed. Dvips provides the -V command line switch for this purpose. The bash script vgspreview (see Listing 5) is a modification of gspreview, above. Remember to specify zero after the -V switch, which turns the font generation facility off.

Conclusion

There are many other tasks that Ghostscript can perform with ease:

  1. Create faxes.

  2. Create PDF files that can be read by Adobe's Acrobat reader.

  3. Generate a number of different graphics formats.

  4. Work with other companies' GUI displays, notably Windows and Macintosh.

Since Ghostscript interprets the PostScript language, you can program directly in PostScript, either via Ghostscript's command interpreter or with \special commands embedded in your TeX and LaTeX files. This article has only scratched the surface of the capabilities of this free program and the many ways in which Ghostscript can perform feats of industry-standard imaging right on your desktop.

Glossary

When Robert Kiesling is not involved with the complexities of PostScript and TeX, he is at work on his “real” writing. This includes several novels, as well as fiction, poetry and nonfiction, which have appeared in literary magazines and newspapers nationwide. When he is not busy with either of the above, he is occupied by maintaining the Linux FAQ, providing editorial support to small presses and answering e-mail at rkies@cpan.org.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Emacs Tex mode printing via Ghostscript shell scripts

Anonymous's picture

The section "Ghostscript as a Document Post-Processor and Previewer" of this article sounds very interesting but doesn't work. More explanation would be nice.
Alex.

Re: Emacs TeX mode printing via Ghostscript shell scripts

Anonymous's picture

Try to isolate the problem. Do the individual utilities run correctly from the shell prompt? Then, do the shell scripts run correctly from the shell? If they don't, then try to include the error messages. If they do, then try to include the debug output from the Emacs interpreter. Also include the version of each utility, so I can duplicate the errors produced by newer versions. Or, you can follow these procedures, and submit a patch.

Robert Kiesling

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix