I have occasion to need to print code (Horrors!!! ;) ), and i was wondering what editor or tool would i use to print that code out with proper formatting and syntax highlighting
I recently compared the 2 solutions already mentioned : vim & pygments. They both give great results, but there is how you can practically use them quickly:
pygments does not provide direct export to PDF. Hence, the simplest solution I found was to export to HTML and then use wkhtmltopdf. You can combine both operations using the following bash script:src2pdf () {
local noext="${1%.*}"
pygmentize -O full -o "$noext.html" "$1"
# enabling line wrapping in blocks
perl -i -wpe '/$/&&($_.="pre{white-space:pre-wrap;}\n")' "$noext.html"
wkhtmltopdf "$noext.html" "$noext.pdf"
rm "$noext.html"
}
vim, it's as simple as this: TERM=xterm-256color vim '+hardcopy >out.ps' +q code.src
I found out that the $TERM environment variable can affect the output colors, so I prefer to set it explicitly.
And finally, you may need to tweak your .vimrc a little:set printfont=:h9
set printoptions=number:y,left:5pc