17

I give a lot of code heavy presentations with Keynote. Syntax highlighting makes these readable.

In the past I've used web based syntax highlighting tools, and then pasted the easier-to-read code into my presentation.

When I upgraded to iWork '13, which includes Keynote 6.1, pasting content strips the font style and color.

For example, if I take this colorful code from GitHub and paste it into Keynote it removes all the formatting as shown here:

enter image description here

Is there a way to get syntax highlighted code into these presentations?

4
  • Jenny, could you tell us what highlighter you are using to view and copy the code? Commented Mar 13, 2014 at 0:24
  • Added an example source (GitHub) and a screencap of the result.
    – mimming
    Commented Mar 13, 2014 at 1:30
  • What browser are you using? Commented Mar 13, 2014 at 2:43
  • @Alan I was using Chrome 34 when I observed this behavior
    – mimming
    Commented Mar 13, 2014 at 18:19

5 Answers 5

13

The 'short' answer

... is that different apps copy formatted text to the clipboard in different ways, and different apps support pasting from different formats. Typically you'll get some kind of 'plain text' format, as well as maybe HTML or RTF formatted text in the clipboard, and it's up to the pasting app to choose which it likes best.

Keynote 6.1 definitely supports some kind(s) of formatted text pasting, as I can get this to work with Safari. But it doesn't seem to work with Firefox or Chrome (at the time of writing). From a bit of testing, it seems the Apple apps all play nicely together (no surprise there), and a few others will copy/paste to/from the Apple apps too (including Microsoft Office products). Unfortunately when you copy from Chrome, you only get plain text & HTML-formatted text copied to the clipboard, so it would appear Apple's iWork apps don't support pasting HTML formatted text.

So if copy/paste doesn't include formatting, you can either:

  • Try a different browser to copy from, such as Safari; or
  • Find an intermediate app to paste into (which 'speaks' both HTML formatting and can re-copy into a format Keynote/etc understand), such as Apple's own TextEdit.app

Surprisingly, Apple's own TextEdit.app will happily paste formatted text from Chrome, and it can be re-copied to the clipboard and pasted with formatting into Keynote/Pages/etc.

Depending on your point of view, this may seem a limitation (or fault) in Chrome/Firefox or in Pages/Keynote/etc, but in the end they simply don't speak the same formatting languages (at present).

I'd encourage anyone experiencing this to send feedback to the developers on both 'sides' in the hope of getting this fixed—either with Chrome/Firefox supporting RTF/RTFD copying (or whatever is most standard/appropriate beyond HTML), or by Apple's iWork apps supporting the pasting of HTML content.


More than you want to know about copying to the clipboard

When you copy some text to the clipboard, depending on the application, it may get copied in a few formats. You can see these using Apple's Clipboard Viewer application (requires building in Xcode).

For example, copying from Google Chrome, the clipboard gets populated with four separate copies of the information I copied—two plain text (public.utf8-plain-text, NSStringPboardType), and two HTML formatted (public.html, Apple HTML pasteboard type).

Copying from other apps gives various combinations of format types, with some other common ones being 'TEXT' (CorePastboardFlavorType), com.apple.traditional-mac-plain-text, Apple PDF pasteboard type, Apple PICT pasteboard type, public.rtf, NeXT Rich Text Format v1.0 pasteboard type, NeXT RTFD pasteboard type, com.apple.flat-rtfd, com.apple.iWork.TSPNativeData, com.adobe.pdf, com.adobe.indesign-import-ustl, and so on...

As you can see there are a variety of plain text formats (with various encodings like UTF8/UTF16), RTF types, PDF and Adobe types, image types. There's also a bunch of metadata types that describe the application that copied the data (e.g. com.apple.iWork.TSPNativeMetadata), or the features of the copied text (e.g. com.apple.iWork.TSPDescription), and what appear to be separated text and style data (ustl and TEXT as CorePasteboardFlavorTypes, and their com.adobe.indesign-import- equivalents).

I don't know any way of seeing which format types are supported by which applications for pasting, but using the Clipboard Viewer you can quickly see which format types are generated on copying.

5
  • This was it. In my case it was the intersection of Keynote 6.1 and Chrome. Further testing reveals that content copied from Safari 7 works, but Chrome 34 and Firefox 27 do not :(
    – mimming
    Commented Mar 13, 2014 at 18:18
  • I'd suggest you submit a bug report to both Chrome and Firefox (or vote for existing bugs/feature requests). You'll get a few more supporters if you link to the relevant bugs on here I'm sure too. Commented Mar 15, 2014 at 12:51
  • I've tried with a dozen other sources for the copy from just as many vendors, and it seems like only copying from Apple software works. Content copied from non-Apple software also seems to work when pasting to each other. In other words, it seems like an Apple bug, but I'm not going to take the time to investigate any further (or file bugs).
    – mimming
    Commented Mar 17, 2014 at 19:01
  • Investigated a bit more, it's not as simple as "only Apple to Apple", since MS Word and Apple's TextEdit both work with pretty much everything... but also suspect this could be called an Apple bug since they aren't supporting pasting from HTML text in iWork apps. Commented Mar 17, 2014 at 23:45
  • Thanks for this. I was attempting to copy code from Xcode into Pages. It's a little bit frustrating to have to use TextEdit as an intermediary, but at least now I can do it! Saved me a bunch of head-bang-against-the-wall instances! ;-)
    – mbm29414
    Commented Dec 17, 2015 at 15:46
7

This is probably the online highlighter you are using.

I use http://markup.su and it works fine with Keynote 6.1 - it autodetects a number of languages and has a number of "themes".

If it isn't the highlighter then it may be your template or browser. I was able to take your code and paste it from markup.su in Safari into Keynote perfectly.

enter image description here

5
  • markup.su highlights stuff great, but pasting into a text field or the text property of a shape in Keynote 6.1 continues to strip the color and style. :\
    – mimming
    Commented Mar 13, 2014 at 1:25
  • 1
    That's strange as it tested fine for me an hour or two ago. Just a copy from Safari and then a paste into Keynote worked for Python and Perl. Commented Mar 13, 2014 at 2:19
  • It works on Keynote 6.5.3 too! (Y) Commented Feb 14, 2016 at 6:34
  • 1
    It works on Keynote 6.6.1, but you have to copy it from Safari.
    – luzny
    Commented Mar 3, 2016 at 15:18
  • Yeah it has to be copied from Safari. Chrome won't work.
    – Jason Gao
    Commented Dec 18, 2016 at 22:09
3

If you don't like the idea of pasting your code online, consider installing the Pygments python package and generating your highlighted syntax at the command line:

pygmentize sms_me_last_line.sh

Copying from Terminal and pasting into Keynote worked for me. But it took me a while to find the formatting control for removing the background text color. (Click Format in the toolbar to show the formatting options, click Text, click Style, then click on the gear to show advanced formatting options. In that pop-up you will find "Character Fill Color".)

3

I'm using Vim. I found this plugin super useful: https://github.com/zerowidth/vim-copy-as-rtf

In This way I can keep my codes the same look when I was writing and presenting them.

2

It's a bug in Keynote '13:

Pasting rich text from Xcode to Keynote works when you paste in an existing text box.

It doesn't when you paste into a new text box.

2
  • Is there a workaround for this except typing text in it first?
    – Rob
    Commented May 14, 2014 at 13:57
  • The most convenient I've found is to just create a text box, select it, and paste into it.
    – mz2
    Commented May 14, 2014 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .