I've been playing with iBooks Author all morning and I haven't had any luck embedding code snippets. Does anyone else have any ideas?
A few things I've tried:
- A custom widget. This won't work, because widgets just have image previews and have to be tapped to be read. I'll use these for runnable examples of code (at least for CoffeeScript/JavaScript/ClojureScript), but not for formatting code within the flow of text
- Text boxes – Getting these to appear similarly in portrait & landscape orientation has been painful so far.
- A paragraph style. It looks like this is where I'm going to start next. With the inspector, "Text -> More" seems to hide what I want in terms of background shading and disabling hyphenation.
I'm copy-pasting syntax-highlighted code from textmate using the copy as RTF bundle, but iBooks Author isn't respecting the colors. Any ideas on syntax highlighting?
Best Answer
There is a way more simple way to do this... I'm using iBooks Author 2.0 it has a "Paste and Retain Styles" option that works like a charm.
I edit the code snippets in Xcode then select and copy the section I want:
Then control click where I want to paste it into my book:
Done! The snippet is included with syntax highlighting:
Pro Tip 1: Take time to set up Xcode to use the font you want so you don't have to fiddle with it once the code is pasted into iBooks Author:
Pro Tip 2: Here are some other useful settings for your code snippet paragraphs, keep the lines together and disable auto-hyphenation.