Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Could you provide a short snippet showing what colors are not being respected? Failing that, perhaps two small pictures showing the intent and the result? – bmike Jan 26 '12 at 17:02
up vote 6 down vote accepted

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: enter image description here

Then control click where I want to paste it into my book: enter image description here

Done! The snippet is included with syntax highlighting: enter image description here

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: enter image description here

Pro Tip 2: Here are some other useful settings for your code snippet paragraphs, keep the lines together and disable auto-hyphenation.

enter image description here

share|improve this answer

I just tried the trick I use to get syntax-highlighted code into Keynote, and I think it works, though I don't have an iPad handy to export the book and try it.

  1. Edit the code in MacVim
  2. Make sure syntax highlighting is on:
    1. Hit escape
    2. Type ":syn on" and hit return (don't type the quotes)
    3. If you don't see syntax highlighting, you may have vim mis-installed or are using a language that doesn't have a highlighting file installed by default; search github and you'll probably find something
  3. Export the buffer as HTML
    1. Hit escape
    2. Type ":TOhtml" and hit return (don't type the quotes)
    3. This will open a second buffer with the HTML of your text in it. Save it via ":w" and hitting return
  4. Open the file in your browser
  5. Copy the contents
  6. Paste inside iBooks Author

When I did this, I got a text box with the highlighted code in it.

share|improve this answer
Thanks @davetron5000, I'll try this out later. – Justin Searls Feb 1 '12 at 1:06
BTW, I did this extensively in a book I wrote in iBooks Author and it worked great. Link to iBooks Store:… – davetron5000 Apr 24 '12 at 20:16
@davetron5000 I tried opening your link and got notified that the item is not available in India. I am wondering if that was unintended and if the book is still available. – lorefnon Jan 11 at 18:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.