Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The goal is to print a set of *.cpp files on a network printer, but... in a way that the (color) printer prints the files like they appear in the c++ editor including the colors and highlighting. And all of this from the command line.

I succeeded in sending all the files to the network printer but they are (of course) all printed in black and white (text) format.

I used : lp -d 'printername' *.cpp

Is there a way to open the files in something like emacs and pass the print command to emacs from the command line?

BTW: I'm on mac OS X.

share|improve this question
possible duplicate: unix.stackexchange.com/questions/43520/… – ixtmixilix Mar 6 '13 at 22:29
Check out an example here of what @Bernhard speaks of. While it is SQL and not C++, the principle should be the same. – Emanuel Berg Mar 8 '13 at 1:14

I would be highly surprised if you can do such a thing directly with lp. The following is the easiest solution I could think of.

There is a LaTeX package that can help you a lot: minted. You could write a script, that generates a .tex file (probably by \input{}) and uses this package for syntax-highlighting. Then you compile it, to obtain a .pdf with the colors that you wish. Sending it to printer is than the remaining step.

share|improve this answer

I think enscript might help you. I don't use it for code-formatting myself, but I do use it to print timestamps on text files I print.

I have a shell script in my ~/bin directory that will save it as a PostScript file that I can then print (directly printing, is of course an option). If that is helpful to you, I have it in a Gist here: https://gist.github.com/ryanaghdam/5103528. It takes a text file as the first argument ($1).

It is not installed on Mac OS X by default, but is available in Homebrew.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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