If you are okay with writing a .bat file that automates doing that kind of repetitive stuff for you, then what you can do is go into the Processing pane of the Format Designer, while editing, and aim it at your .bat file. In this way, it would be pretty simple to make it so clicking ‘compile’ results in a PDF file, once you have the various files and such assembled in predictable places.
And for Mac users reading this: when you arrive in the Processing pane you’ll find an embedded shell script example that does a simple PDF typesetting routine, and all you have to do is turn the pane on to try it.
I have figured out how to do 1 successfully using the Compile Format Designer/Styles options. I have figured out how to do 2 using the Compile Format Designer/Replacements options. The problem seems to be that when I apply both 1 and 2, all $ characters, including the ones inserted during 1, get escaped, making inline equations totally wonky.
First order, just to ensure you are not making extra work for yourself, the LaTeX project template’s default compile Format actually comes with an “Inline Equation” example, and quite a few other examples as well that you might find of use. It might be easier to fork your modifications from that base rather than starting from scratch, if that is what you are doing. The part that makes it “Memoir” is actually pretty small, and found entirely within the Text Layout pane. It is intentionally extremely vanilla so that it can be used as a starting point for whatever you prefer or require.
All right, so as for escaping some things but not all things, this isn’t really a Scrivener trick so much as a macro-making trick in general, manual search and replace trick, or really any tool where you have a sequencer that executes changes one after the other, rather than a scripting language. You can’t say “if this is in there don’t do that, otherwise do this”, so you have to employ that kind of logic manually with the order in how things are done.
So first, make your Inline Equation prefix and suffix settings wrong, and wrong in a way that won’t be confused with anything else, like SCREQMARKER
instead of $
. Then, you will want the following two replacements in this order (though they don’t have to be together):
- Replace:
$
With: \$
(No options.)
- Replace: SCREQMARKER
With: $
(You could add case-sensitive just to make sure that doesn’t accidentally change something else.)
Mac copy and paste...
<Replacements>
<Replacement>
<Replace><![CDATA[$]]></Replace>
<With><![CDATA[\$]]></With>
</Replacement>
<Replacement>
<Replace><![CDATA[SCREQMARKER]]></Replace>
<With><![CDATA[$]]></With>
</Replacement>
</Replacements>
The Inline Equations’ dollar signs don’t actually exist at the point when the Replacement that escaped dollar signs runs, they are only inserted after the second replacement runs.
The other approach is what rms posted above, and that is to use Regular Expressions (which do have a fair bit of logic to them, even though they do not understand their context, such as “I am running in a style prefix”). In the example case of the screenshot above, second row, the stipulation being made is that only dollar signs followed by a digit will be escaped.
Will that work for you? Maybe not, as some inline equations might start with a digit!