Skip to main content

Just quickly print something in Emacs

lpr or lp, that are only bourgeois categories.

In Emacs, there are several ways to generate neat prints. Most of them end up creating PDFs. But if you just want to quickly have a printout of the buffer to work with a pencil and highlighter, that can sometimes be a problem. I spent an evening trying to solve that, and eventually succeeded. To remember it, I wrote this blog post.

Basically, there's the command print-buffer, which I habitually invoke with CTRL-p. I expect paper to come out of the printer, containing unformatted text, just like what I see on the screen in the buffer.

Unfortunately, that didn't work for me at all. Emacs uses the Linux command line command lpr for this kind of printouts, and it quickly became clear that it wasn't doing any good on the command line either. Every attempt to print something with it, ended with a message saying that the lpr daemon wasn't running. Every attempt to start it failed. At some point, it dawned on me that maybe lpr is just too old as a printing tool.

Back to the Future

lpr is indeed an older command, stemming from the times when printers were often directly connected to Unix systems. However, it came to pass that the "Common Unix Printing System" (CUPS) was developed, providing modern print management on Unix systems. And a little web search revealed that it comes with its own command line command, lp.

The syntax of the two commands varies slightly. lpr usually simply accepts the filename I want to print, while lp accepts a range of options that allow me to control various aspects of the print job, such as the number of copies, the printer, the paper format, etc.

Emacs kindly provides the option to configure the command it uses under the hood. So, instead of lpr, we say we'd rather use lp:

(setq lpr-command "lp")

Since lp and lpr pass different parameters on the command line, it also doesn't make sense to continue using the lpr standard switches for lp. So, we turn them off:

(setq lpr-add-switches nil)

And boom, everything worked as expected. So I persisted it in my Config


If you're not using an antique Linux system, lpr doesn't make sense anymore and should be replaced by lp. In my humble opinion, that would be a good default by now.

By the way, in the configuration, you can also set your own parameters to pass to lp, which I think will help me achieve double-sided printing as well.