Syntax highlighting source code in Word and PowerPoint

  • Published 2005-03-20 (3 years, 5 months ago)

I recently held a presentation which had several listings of XHTML and CSS code. Source listings are not terribly exciting to read, so I wanted to make them more readable and pretty by using syntax highlighting. I had already written about highlighting source code for the web, so I wondered if there was some easy way to include colored code snippets in my PowerPoint presentations.

I did some research and found out that what I needed was a decent text editor that could export source code as colored HTML or RTF, that can be imported into PowerPoint and Word. To my pleasant surprise I discovered that I could use the SciTE editor based on the same Scintilla lexers used to colorize source code on fauskes.net.

SciTE

This is what the Scintilla web site has to say about SciTE:

SciTE is a SCIntilla based Text Editor. Originally built to demonstrate Scintilla, it has grown to be a generally useful editor with facilities for building and running programs.

SciTE is not the most advanced editor around, but it has some attractive features:

  • It is free and open source
  • It is small and easy to install. Just unzip an run
  • Supports syntax highlighting of many languages, including XML/XHTML, CSS, PHP, C/C++, Python, Perl, Ruby, Matlab and many others
  • Can copy text to the clipboard as syntax colored RTF

The last feature is very useful for pasting syntax highlighted source code into Word and PowerPoint. SciTE is available from the Scintilla download page.

Example

Now it's time for a step by step example on how to put a syntax highlighted HTML code into a PowerPoint presentation.

Step 1. Load your code into SciTE

Load or write your source code in SciTE. You may have to select the correct language from the Language menu. Figure 1 shows an example of a syntax highlighted HTML document.

Figure 1. Syntax highlighted HTML.

Step 2. Copy source code to the clipboard as RTF

Select some of the source code and copy it to the clipboard as RTF using the Edit > Copy as RTF menu. See Figure 2.

Figure 2. Copy selected source code as RTF

Step 3. Paste into Word or WordPad

Now you can paste the colored text into Word or WordPad.

Figure 3.

Step 4. Paste into PowerPoint via Word or WordPad

Important: PowerPoint can't paste RTF text copied directly from SciTE (don't ask me why). Instead you have to paste the text into Word or Wordpad, copy it again to the clipboard and then you can paste the code into PowerPoint. Remember to use Paste Special from the Edit menu, and select Formatted Text(RTF).

Figure 4. Paste source code into PowerPoint as formatted text (RTF)

Step 5. Adjust font properties if necessary

The result may look like Figure 5. You may want to increase the font size or switch to a monospaced font if you are not satisfied with the results.

Figure 5. A gorgeous looking source listing

Concluding remarks

You now have another tool for making great-looking PowerPoint presentations. Use it wisely.

There's only one thing I'm not happy with. SciTE does not support LaTeX right out of the box. I think it's possible to configure SciTE to support LaTeX, I just have to figure out how.

Comments

  • #1 Lorenzo Bettini, November 28, 2006 at 1:56 p.m.

    I came here by chance by reading tex newsgroup (and surely liked your site which I bookmarked).

    I just wanted to let you know about GNU Source-highlight, as an alternative to your way of highlighting code.

    I'm using it also to insert highlighted code snippets in my blog, see, e.g., http://tronprog.blogspot.com/2006/10/gnu-source-highlight-25_09.html, also using this other tool, Code2Blog.

    Keep up the good work :-)

  • #2 Kjell Magne Fauske, November 28, 2006 at 2:36 p.m.

    Thanks for the tip Lorenzo. I'm thinking of rewriting the source highlighting on my web site. I'm not quite satisfied with my current solution. I've used the pure Python source highlighter Pygments for my PGF/TikZ examples gallery, and I'm very satisfied. It integrates nicely with my Django-based web site.

  • #3 me, May 15, 2007 at 6:04 p.m.

    there is another method/trick. just view the sourcecode in your favorite editor(with syntax highlight) and take a screenshot.

Comments are disabled for this entry