5

I'm trying out Scrivener, as I intend to write some technical material. I'm a Software Developer and what I intend to write is programming related.

I still wasn't able to figure out how can I insert code snippets in Scrivener so they look nice.

Here's an example of a code snippet:

// A Hello World! program in C#.
using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

Here is an example of how I want it to look, with syntax highlighting:

enter image description here

Is this possible with Scrivener? I know I could just insert images of the code, but I don't want to follow this approach, as when I export the PDF it can make the life of the reader much harder (maybe a reader just want to copy and paste), and it can also make my life much harder, as if I want to change a code snippet I can't just edit within scrivener.

It's worth mentioning that I'm using Scrivener for Windows.

2

A quick Google reveals some possible solutions:

  • "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."
  • Another commenter on the same link points out that, if you're using LaTeX for your final output, there are "packages for LaTeX that can do code highlighting within verbatim environments".
  • "Scrivener 3 has Styles. You can use the Code Block style which switches to a monospaced font suitable for code. When you compile the document, the exact font used can be chosen in the compile settings except for HTML and Epub export where it will use HTML Code tags."

The first option (or LaTeX) seems the better one in my opinion. As a commenter on the first link remarks, Scrivener is a writing program, not a layout program, so you'll likely need to rely on other tools that integrate.

  • 2
    I guess that's what I get for using DuckDuckGo. Anyway, I'm using Scrivener for Windows, so #3 it's not really an option. But I like the take that Scrivener it's a writing program, not a layout one. I'll try to keep everything simple and just write, later down the road explore another options to style everything. Thank you. – ItsMeArthur Jul 22 '18 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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