Take the 2-minute tour ×
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.

Similar to using markdown on Stack Overflow to create monospace output, how can I do that for my programs.

I tried lp filename.txt and was pleasantly please to find that it was able to use the local network printer and print 'as is'

The problem is the output is not mono-spaced.

Is there an quicker option than...

1) copy the text
2) paste into a text doc
3) format the document as mono
4) print it 

I would love to find some option like lp filename.txt -format=mono ;)

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

a2ps was the answer. I installed it with brew:

brew install a2ps

Now I can a2ps myfilename and it works.

Unfortunately it comes out landscape and if I try to make it portrait it's squished over to the left and tiny, only up taking 50% of the page. [upate - found fix to this with parameter -1 (for number of pages to find on one sheet - the default was 2)

However as landscaped it worked and the code has the fixed format style I was looking for.

share|improve this answer
add comment

The shortest path here is probably to use a2ps, it generates monospaced postscript by default. Depending on its setup, it will send the output directly to stdout or lp, override with -o. Also, a2ps recognizes several programming languages and pretty-prints them.

a2ps -o output.ps infile.text

Use --pro=color if color is available:

a2ps --pro=color -o output.ps infile.text

For HTML output I tend to use vim's 2html feature.

share|improve this answer
show 2 more comments

You can use the vim editor to pretty print arbitrary files vim can read. Use the following to create a PostScript file.

vim \
  -c 'hardcopy > output.ps' \
  -c quit <input_file>

If you want a PDF file, add && ps2pdf output.ps to the command line.

You can also write a small script that pastes the current clipboard content into a temporary file, runs vim on the file, prints the resulting file and deletes the temporary file.

share|improve this answer
add comment

Your Answer

 
discard

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.
{"cc_re__cc_re__cc_by_sa_3_0": ["        <li><a href=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.4.17.1557\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group. <br>This site is not affiliated with Linus Torvalds or The Open Group in an"], "copyright__copyright__copyright": ["uit <input_file>\n\nIf you want a PDF file, add && ps2pdf output.ps to the command line.\n\nYou can also write a small script that pastes the current clipboard content into a temporary file, runs vim on the file, prints the resulting file and deletes the temporary file.\n\nshare|improve this answer\nadd comment\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}