LoginSignup
48
49

More than 5 years have passed since last update.

Keynoteに美しくスニペットを貼る

Last updated at Posted at 2013-12-05

プレゼンテーションを作ってて、綺麗にsyntax-highlightingさせたい!という需要は高いはず

Screen Shot 2013-12-06 at 01.52.02 .jpg

Pygmentsを使う

Pygmentsという、syntax-highlightingを簡単に生成できるPython製のライブラリがあるのですが、それを使うと簡単に生成できる

Pygmentsのインストール

pip install pygments

or

easy_install pygments

pygmentizeを使ってハイライト

Pygmentsには、pygmentizeというCLIが付属しているので、それを使ってやると、shellから簡単に装飾できる。

Pygments — Documentation — Command Line Interface

Keynoteに貼り付けるためには、リッチテキストで書き出してやれば良い

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

必要に応じて-lオプションでLexerとして、言語を指定できる。通常は指定しなくても拡張子から自動判別してくれるっぽい。

対応言語はこちら

Keynoteに貼り付ける

上記のコマンドを実行すると、すでにクリップボードにハイライトされたソースコードが格納してあるので、あとはKeynoteにペーストするだけ。

Screen Shot 2013-12-06 at 01.58.47 .jpg

美しい。

適宜、文字サイズや背景色を変更してください。

ちなみに

クリップボードにあるコピーしたスニペットをそのままハイライトさせたい場合は、pbpasteから流し込んでやるだけで良くて、さらにお手軽です

pbpaste | pygmentize -f rtf -l python | pbcopy
48
49
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
48
49