Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

PyCharm, Pygments, and Keynote Syntax Highlighting

DZone's Guide to

PyCharm, Pygments, and Keynote Syntax Highlighting

Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

I’m prepping talks for a few conferences. I think I’ve got my workflow down for syntax highlighting slides in Keynote on my Mac.

1. pip install pygments, not in a virtualenv but in your default Python.

2. Make a Bash script like:

#!/bin/bash
/usr/local/bin/pygmentize -f rtf -O "style=friendly,fontface=Courier Bold" "$1" | pbcopy

Make sure it’s chmod’ed executable and on your path. Now you can do pyg myscript.py and then paste the syntax-highlighted code into Keynote. The result is pretty nice; at some point I may make a Pygments style optimized for presentations:

Pygments output

3. In Keynote, turn off all auto-correction:

Keynote auto-correction

4. Bonus round: PyCharm integration. In PyCharm’s preferences, choose “External Tools,” hit the “+”, and fill out the dialog like so:

PyCharm Edit Tool

You can leave “Open Console” checked while you’re getting things working.

Finally, in the “Keymap” section of PyCharm’s vast settings dialog, search for “pyg” in the filter box, right-click on it, and assign a hotkey of your choice to the tool. I chose Command-Y because it was bound to some weird function I don’t use.

PyCharm assign hotkey

Now whenever you’re editing a file in PyCharm, you can save it and hit Command-Y, then switch to Keynote and paste.

Readers, if anyone can tell me how to adjust the default font size in Pygments for RTF output specifically, that’d be great.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of A. Jesse Jiryu Davis, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}