43.22 Converting Text Files to PostScriptPrinting used to be easy; when all we had were daisy wheel printers and line printers, you could send virtually any text file to a printer without modification. That's no longer possible; fancy "printer languages" like PostScript force you to do a fair amount of processing to get a simple text into some form that the printer can understand. As always, there are several ways to solve this problem. The first is gross and disgusting, but quite effective. Assume that you have a working version of troff with the -ms macros. Here's the script:
# the name of the script that runs troff for you roff=lw # choose your favorite macro package macros=-ms sed -e ' 1i\ .DS .in 0\ .ft CW\ .ps 10\ .vs 12 s/\\/\\e/g s/^/\\\&/ $a\ .DE ' | $roff $macros How does it work? It just "wraps" your text with a troff incantation that prints the text in a fixed-width font, with no "justification" or "fill." It relies on the ms macro package to handle margins, new lines, page numbers, and so on. The sed script also massages your file so that it will print anything that troff finds confusing - in particular, backslashes and lines beginning with periods or single quotation marks. In fact, it can even print a troff macro package; if memory serves me, that's why I originally wrote it. I like this because it works as well as any other solution I've seen, and better than most; it's extremely simple; and, because it uses UNIX tools to do the work they were designed to do, it's a good demonstration of the UNIX philosophy. It's even elegant in its own bizarre way. And, if you know a little bit (not much) about troff , you can customize it for your own situation. However, there are other solutions. Perhaps the best is to use the enscript program, which is part of Adobe's transcript package. That's proprietary software, so we can't include it with this book. But at least we can point you in the right direction.
There are a zillion options, but the most important are:
- |
|