Custom format replacements

In compiling I would like to be able to replace certain words like MODULE, FOR, IF, THEN, etc with the equivalent in lowercase bold, others such as MAX, MIN, etc with lowercase bold italics, and still others, also in all caps with lowercase italic 75% opaque. Each list of words would have 50-60 entries. Is there a way to do this? (Obviously, I am writing a text on a programming language. We are considering having keywords displayed for publication with various formatting,not exactly syntax colouring as a programming editor would do it, but of a similar nature.

Ideally, I would be able to enter three or four case sensitive named lists in, say, a comma delimited fashion, plus a regexp, say, that would convert any item in a specified named list to its equivalent in the desired format–but only on compiling. While editing, I’d be using the raw text that the language translator employs.

Any thoughts on how this can be achieved? The replacement facility in the compiler does not seem to do formats like bold and italics.


That’s correct, Replacements are purely text level functions. There is currently no way to batch format text either in the compiler or editor. There will be ways to accomplish what you are going for in the next major overhaul, though.

Currently the only feasible (depending upon your definition of that!) approach is to use a scriptable post-processing system like MultiMarkdown, where you could create “syntax” and have the engine do stuff with that syntax on compile. I use a similar mechanism for the user manuals, where interface labels are printed in bold, light blue sans-serif, but in the editor they just look like {{this}}, which means I can easily choose a different look for these sorts of labels down the road, if I wish. Same thing you’re going for, I imagine.

Thanks. So, what is the timeline on that next major revision that will have such a feature?

There’s nothing specifically coming in the next version that does what you want - I assume Ioa is referring to the introduction of styles, but that still wouldn’t let you just assign formatting based on word lists. There are no plans for anything like that, I’m afraid. (The next version is still a long way off with no set release date, it’s just in development.)

Yes, I was thinking along the lines of tagging text with a style so that output could be centrally managed, and then the use of Replacements for lettercase modifications.

Could it be done with GREP at compile time? Does that allow formats? Lists?

It has nothing to do with regular expressions specifically, but if you are exporting to an HTML-based format, then it is possible to directly inject raw code (and thus formatting, or at least stylesheet hooks so that formatting can be added later). However I don’t think this method will suit you, as it requires you to apply Preserve Formatting to all instances of text that will become raw HTML, as the feature that allows you to do this is the HTML Settings compile pane: Treat “Preserve Formatting” blocks as raw HTML. You can place a shorthand code in the text editor that is expanded to a full HTML construct upon compile, all within the confines of the original preserve formatting field.

Reviving this old thread, because I have a similar question.

I have written an entire book ms in Scrivener, and I used the underscore for italics, because that way, I can be sure that I don’t accidentally change formatting. In the past, I’ve compiled my file, exported to RTF, then opened it in Mellel and did a replace feature that would replace the text between underscores with italics: text between underscores.

But I was hoping that there is an easier way to do this and that Scrivener could handle the replacement internally, so I wouldn’t have to go through Mellel. Is there any way to do this, or is such a function still not available?

Have you tried this option, in the Transformations compile pane?

Wow, that’s amazing! Thanks, AmberV. I hadn’t tried that option, because I don’t know what Markdown is. This is great!