Disabling Smart Quotes for Code Span and Code Block

This might be a long shot, but maybe someone has a solution nonetheless.

I generally like the Smart Quotes (“x” substitution for “x”) feature and have it enabled in the macOS System Prefs and in the Scrivener general Prefs under Auto Correction > Punctuation.
However, when including snippets of code in a Scrivener document, I need to disable them (bc. otherwise the code gets messed up with typographic quotes).
So I was thinking, is there a way to disable Smart Quotes when I am typing into a strech of text that is marked as either Code Span or Code Block?

I would really like to be able to specify this somehow in Scrivener as well! For code, math, metadata[1] etc., smart quotes or other correction options simply breaks stuff. Elsewhere, it is typographically useful and saves the author time[2]. Unless someone else has a cool trick to deal with this (sure hope so), I think this should be a wishlist item.

As a feature, I think it would best be placed in the Styles system as an option, “Disable Corrections” which would be OFF by default so that default Scrivener default behaviour would remain unchanged. 8)

[1] Broken metadata due to case correction and substitution is one of the major reasons I get asked for help with Scrivener+Markdown output errors.
[2] Note for Markdown users, “smart typography” is usually present in such tools. However I still prefer that the “source” in Scrivener uses correct typography rather than relying on another tool… Currently this just means manual management

My “solution” for this…

As I always write in MMD, I have smart quotes turned off and have got the following curly quotes (when needed) hardwired into my brain, remembering that OPTION means OPEN, and adding SHIFT means CLOSE:

Open: OPTION [

Open: OPTION ]
Close / apostrophe: OPTION SHIFT ]

Another forum member mentioned this some years ago (don’t remember who). Took a day or two to adopt, but now it’s just ingrained.

If I’m understanding the issue, something to try…

First, in Scrivener Preferences > Corrections > Punctuation > tick box for––Disable smart quotes in script mode…(There’s also a setting there for disabling smart dashes and ellipses in script mode.)

Then, before entering a Code Span or Block, enable script mode by keying––Command 8. When through with Code, key––Command 8––to exit script mode.

[Script mode and its settings can be accessed via the Format menu > Scriptwriting.]

Thank you all for the feedback and the two workaround solutions of either disabling autocorrections altogether and manually typing typographic quotes, or entering/exiting script mode. Both work, but involve extra steps. Hence I’m following @nontroppo’s suggestion and have just posted a wishlist item here:

Please continue that thread in the wish list section for further input.

Even if smart quotes are turned on, users can still type straight quotes:

CTRL QUOTE for a single straight quote

SHIFT CTRL QUOTE for a double straight quote

Basically, just add CTRL to the keystroke to escape the smart-quote engine whenever you need to.


For code blocks there is a fairly simple and not particularly onerous solution, which perhaps may help in the meantime?

You’re dealing with a discrete block of text, and Scrivener is designed to deal with discrete blocks of text… So every time you have a code block, split it out into its own document in the Binder and give it an identifiable label/status/metadata (e.g. ‘Code’)

Then create a collection of documents matching ‘Code’, select all the documents in it as a scrivening, cmd-a to select all the text and Edit > Transformations > Convert Quotes to Straight Quotes, and you 're done.

Once you’ve done the initial splitting of the text and set the dynamic saved search collection up, cmd-a and transform will take seconds to do, and will probably be a lot less hassle than having to use the smart quote shortcuts every time.

You could of course set up a document template specifically for the code blocks with ‘Code’ already assigned to make it quicker in future as you continue to write. (BTW, if you enter some into the template, then give it your code style and highlight the dummy text, then when you create a new code document, you can start typing straight away and it will have your code style already applied. This only seems to work if you highlight the dummy text in the template when you create it.)

This approach will let you be more flexible with the compilation as well, because you can assign a specific section type to the code documents and therefore a different layout, to those sections in the final output. It doesn’t matter how short the code blocks are.

The difficult one is the code span — I can’t think of a way round that, sorry, but I hope the code block as document idea helps a bit.