Home > python, windows > Insert syntax highlighted source in Powerpoint

Insert syntax highlighted source in Powerpoint

You want to have syntax highlighted source in Powerpoint.

First, create an RTF file from the source:

pygmentize -f rtf -o hello.rtf hello.py

Open the RTF file in Word, select the source, then insert it in Powerpoint.

I made a basic script to automate the conversion. Usage:

py2rtf hello.py

The script is available here.

Update (20131030)
What if you want to insert colorized code in HTML?

$ pygmentize -f html -o index.html color_me.py
$ pygmentize -f html -S default >style.css

The parameter of -S (here: default) is the name of the color scheme. Available color schemes:

>>> from pygments.styles import get_all_styles
>>> list(get_all_styles())
['monokai', 'manni', 'rrt', 'perldoc', 'borland', 'colorful', 'default', 'murphy', 'vs', 'trac', 'tango', 'fruity', 'autumn', 'bw', 'emacs', 'vim', 'pastie', 'friendly', 'native']

Then include style.css in index.html:

    <link rel="stylesheet" type="text/css" href="style.css">
  1. February 23, 2016 at 14:16

    You might want to add that it may be necessary to edit /usr/local/bin/pygmentize to make sure the version numbers match. Otherwise people may be put off the idea if they get a pkg_resources.DistributionNotFound error.

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: