Embedding code snippets in iBooks Author
Solution 1:
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.
Solution 2:
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.
- Edit the code in MacVim
- Make sure syntax highlighting is on:
- Hit escape
- Type ":syn on" and hit return (don't type the quotes)
- 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
- Export the buffer as HTML
- Hit escape
- Type ":TOhtml" and hit return (don't type the quotes)
- This will open a second buffer with the HTML of your text in it. Save it via ":w" and hitting return
- Open the file in your browser
- Copy the contents
- Paste inside iBooks Author
When I did this, I got a text box with the highlighted code in it.