Printing text files

by Juliet Kemp

Occasionally it is necessary to print out a text file. There are a couple of ways of making this happen in a slightly prettier fashion than simply using lp file.txt.

a2ps is one possibility - it gives you nice borders & prints by default 2 x A5 pages sideways on A4 (landscape). There are a vast array of options. However, none of them give you double-spacing, which if you're printing in order to edit, is a nuisance.

pr, on the other hand, doesn't do the pretty thing, but does do double-spacing. And you can pipe its output elsewhere.

So we get:

pr -d -t | a2ps
which will send output to your default printer. (Use the -o switch to a2ps to get a postscript file instead if you want to check layout first.) The -d switch does double-spacing, the -t switch suppresses the filename and page header, which you don't want because a2ps will provide them.

Obviously if you want real proper nice printing then I commend to you the splendid LaTeX, but if you need plain text then putting in then stripping out all that markup is a PITA.


2008-01-24 06:17:57
the -t switch suppresses the filename and page header, which you don’t want because a2ps will provide them.

Except that it doesn't because a2ps sees it as stdin.
2008-01-24 06:20:23
a2ps has an option --stdin to set the filename to print instead of stdin.
Juliet Kemp
2008-01-24 06:42:39
You are right, thanks for the correction. (I would have sworn it worked yesterday when I actually did this, but obviously I wasn't paying attention!).
2008-01-24 10:06:07
Why not use enscript? You can set the baselineskip to anything you want.
gavin hurley
2008-01-24 10:31:06
I prefer enscript. It has enough options that you can get good looking output for both prose and code. It can specify line spacing, fonts, margins and about 200 other things.

Here's my recipe for double-spaced printing of plain text:

enscript --word-wrap -f Times-Roman10 -s 16 --margins=72:72:30:30 -p foo.txt

St├ęphane Bortzmeyer
2008-01-25 00:53:29
The big problem of a2ps is its complete lack of support for Unicode...
Juliet Kemp
2008-01-25 04:23:30
See, this is the advantage of the interwebs - I had never previously encountered enscript! Thanks for the tip :-)

(Note for myself/others - it looks like the -s flag is the one to get double-spacing.)

Jerry Peek
2008-01-29 17:38:01
It's been years since I used a2ps. (BTW, that's a link to its home page). I can see from the documentation that it's grown a lot. So these notes may not be much help. But I've been printing plain text since the days when a tty was a teletype ;-)... so, just in case, here are a couple of other ideas:

  • "Hard line breaks" -- lines that end with a newline character -- can be removed or modified with a utility like fmt(1). For instance, try something like fmt -w 5000 to "wrap" broken lines into paragraphs. Or use a much shorter line width if you need to break long lines at a particular location. The GNU version has a raft of options.

  • Another way to doublespace text is with the command sed G. To triplespace, try sed 'G;G'. And so on for quarduple-spacing, etc. (That's explained in Unix Power Tools.)

Dominic Mitchell
2008-01-30 05:53:50
I agree with St├ęphane, the lack of Unicode support is a real pain. Apart from that, I love a2ps. I've just printed out 86 pages worth of diff output on 22 sheets of paper.