snippets of source code

Hi all,

for my current book project I plan to use Scrivener. An essential requirement here is the ability to handle formatted snippets of source code, approximately the way geshi or other syntax highlighter/formatter do it in the context of a blog.

Any ideas?

Thanks in advance,
Peter

EDIT: Sorry, scrub that … I’ve just realised this is the MMD forum. I’ll leave it to the experts to help you.

This is the MultiMarkdown forum, so I’ll start by saying that I don’t think MMD is going to be a good choice for your project. You can get code blocks with fixed space font, but there’s nothing out of the box which matches GeSHi’s layout (disclaimer: I’ve only looked at the front page of the GeSHi site).

Within Scrivener itself you could set the formatting for the code manually (changing the colours mainly), and then have that passed through the compiler unchanged (use the ‘Compile as is’ tick box for each file to set that). You could also set up your code snippets in a syntactic editor then copy and paste into a Scrivener document, rather than try to replicate that formatting in Scrivener. Each snippet could sit in its own document in the binder, so you could compile those in their prepared format, but then let the rest of the text follow your chosen compile settings.

All that said, Scrivener is designed as a writing program not a layout program, so you may find it isn’t going to fit this particular requirement of your project.

Are you using LaTeX for your final output? There are definitely packages for LaTeX that can do code highlighting within verbatim environments (which is how MMD will set your code span and block text) in the .tex file. It’s as simple as adding \usepackage{listings} and then renewing the verbatim environment to include that (I think that would be the best approach).

If you are going for a more traditional word processor route, there might be something for OpenOffice. It strikes me as the type of thing someone would write a plug-in for. And of course if you are web publishing you can use something like GeSHi itself with MMD’s HTML output.