So I understand that a2ps is mostly for converting ASCII code to postscript for printing, but occasionally I like to print a .txt or .md file for school. Often, an entire sentence (or even a paragraph) will be on one line, and a2ps will break the line at whatever character it needs to in order to wrap correctly.

This often leaves either awkward half words on a line, or spaces immediately at the beginning of the line. I can't seem to find an option to prevent this hard wrapping in the middle of words (even with --pretty-print).

Is there any option to do this, or am I using the incorrect tool for the task?

  • Can you include a sample .txt file that exhibits this behavior? Just a fragment would be sufficient. – slm Sep 21 '14 at 15:22

From my past experiences with a2ps, it doesn't handle wrapping in an intelligent manner. So you have to present your text file already formatted to the proper width & wrapping, before handing it off to a2ps.

If your system has enscript installed I'd make use of that instead. Googleing for "word wrap a2ps" will lead you to this article titled: Printing Plain Text, which includes the following enscript example:

$ enscript --header='||Page $% of $=' \
    --margin=72:72:72:72 -1 \
    --word-wrap \
    --media=A4 file.txt

NOTE: (one inch margins on all sides, 1 up, word wrap, A4 page size, right aligned header showing page info).

Check out the enscript --help and man pages for more on the options, or google for additional examples. I've used enscript for years for printing various text files and source code and it "just works", once you get the switching the way you like.

  • Thanks! Enscript works great — I'll have to dig through the man page to find how to add headers, etc, but the breaking is much smarter than in a2ps. Shame-I really like a2ps. Thanks again! – afischer Sep 21 '14 at 16:36
  • ditto -- thanks, enscript works great, and solves my a2ps line-wrap problems – John Forkosh Sep 16 '16 at 1:13

I have struggled with this as well but have found an answer that works for me.

It's a two-step process:

fmt inputfile.txt > outputfile.txt
a2ps outputfile.txt

Of course that can happen all on one line:

fmt inputfile.txt > outputfile.txt; a2ps outputfile.txt

And if you like you can also rm the outputfile.txt.

I've done this several times now and the formatting works just great in default modes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.