Beautifully put snippets on Keynote

I want to make a presentation and make it syntax-highlighting beautifully! Demand should be high

Screen Shot 2013-12-06 at 01.52.02 .jpg

Use Pygments

There is a Python library called ** Pygments ** that can easily generate syntax-highlighting, but it can be easily generated using it.

Install Pygments

pip install pygments

or

easy_install pygments

Highlight with pygmentize

** Pygments ** comes with a CLI called pygmentize, which you can easily decorate from the shell.

Pygments — Documentation — Command Line Interface

To paste it into Keynote, just export it in rich text

pygmentize -f rtf my/beautiful/code.py | pbcopy

You can specify the language as Lexer with the -l option if you want. Normally, it seems that it will automatically detect from the extension even if you do not specify it.

Supported languages are here

Paste into Keynote

When you execute the above command, the highlighted source code is already stored in the clipboard, so all you have to do is paste it into Keynote.

Screen Shot 2013-12-06 at 01.58.47 .jpg

it's beautiful.

Please change the font size and background color as appropriate.

By the way

If you want to highlight the copied snippet on the clipboard as it is, you can just pour it from pbpaste, which is even easier.

pbpaste | pygmentize -f rtf -l python | pbcopy

Recommended Posts

Beautifully put snippets on Keynote
Put Python 3.x on Ubuntu
Put jenv on Amazon Linux