Formatting programming code?

Hi there,

I did a quick search in the forums but the only result that matched was someone asking a question with no answers; here goes:

If I am writing a technical book, where there will often be example code in it - I would like that example code to be formatted differently to the main book’s text. Is this possible with Scrivener?

If so, how do I mark a block of text as something that should be formatted differently to Scrivener? Typically code examples in technical books are mono-spaced, for example - but setting a ‘random’ block of text to a different font in the Editor won’t effect it when compiling…

Thanks for any help,
Matt

To set things up:

  1. Format a block of text as you want the code to look in the final book.
  2. Select the text and apply Format > Formatting > Preserve Formatting (this tells Compile to leave this block of text exactly as it is, even if the font and formatting is overridden for text in general).
  3. With the text still selected, use Format > Formatting > New Preset From Selection and create a preset that saves all formatting including font and font size.

Once your preset is set up, you can just select any text you want formatted this way and then pick the formatting preset you created from the format bar to apply it.

Hope that helps!

All the best,
Keith

Awesome, thanks for the help!

-Matt