What is the simplest way to escape raw latex syntax for MMD to latex compilation?

For my situation I already have latex boilerplate configured in a separate environment where I setup my bibliography system and handle installation of various latex packages etc.

I am interested in compiling scrivener documents to latex, but all I really want is:

  • the simplest possible compilation to ‘barebones’ latex files, e.g. with section headings and simple formatting for, e.g. bold text;
  • to preserve raw latex as is;
  • I then have a separate latex build process for handling bibliographies etc. (hence the raw latex)

For example, I’d like to use \parencite{AuthorYear} for referencing via biblatex, but compilation will prepend \textbackslash.

I use a named character style for this. I block out the text I need to pass through raw, and then in the compile Format, create a same-named style in the Styles pane that has a prefix and suffix for the MMD LaTeX pass-through code.



(Yes, just a single backtick.)



The result becomes:


This method should work for both MMD6 (not embedded in Scrivener yet; consider upgrading manually) and Pandoc.

And of course you can embellish styles for other purposes with these as well. For example you might dodge the whole syntax matter entirely by creating a style called “Cite” instead of “Raw LaTeX”, and configuring it like so:

[size=80]Using Styles to generate LaTeX & MMD syntax[/size]

It’s up to you how much of that you want to move into the compiler. And also note that option to delete the styled text, toward the top. If you need to compile this as anything other than latex, you can strip out all of the LaTeX code and even the ID tags in the editor itself. You could just as easily generate a DocBook XML tag here.

I am new to Scrivener and only some LaTeX experience. I ended up just putting the preamble and footer in texts and set Compile as-is so I end up with a single tex file. In the compile replacements replace \ with <—\—> (make sure those are two dashes) and similar for ^,%, and anything else that fails in the tex file. Not elegant but that worked for me except for a problem with one - randomly being converted to two.


The named style with a corresponding style in the compilation options did the trick.

I then set the latex options to “None” to reduce the complexity of the output to just the compiled .tex file.

If you’re interested in an approach that bypassing any front end syntax via Markdown parsing, and basically just treat Scrivener like a pure plain-text editor for writing LaTeX, check out this thread, and the example project template I’ve been working on.

The HTML comment method for inserting LaTeX through MMD will no longer work with the next version of Scrivener. We’re upgrading the core engine to MMD6 and so the method I described above will be better if you’re starting a new project right now.

Here is another post on the general approaches Scrivener provides.

Yeah you can stash your boilerplates into the compiler with the “custom” setting, but if you’ve already got that all set up in your texmf folder or wherever, just getting the content out with “none” is good.

For my workflow I rely on MultiMarkdown version six (installed on mac via brew) and the workflow currently performs exactly as I want it to. I use markdown wherever possible but latex specific text is escaped, e.g. for equations and bibliography. My philosophy is to process latex specific steps separately through latex after the compilation step.

Is there a way to find out what exactly the impending changes are for the next scrivener? I’m hoping it won’t undo my current workflow as this would be hugely disruptive.


Scrivener has just been updated to use MMD6 internally and follow its conventions, nothing more. So when you go from MMD > LaTeX, the newer versions of the .tex files ("mmd6-”) get output rather than the older ones, and the metadata uses the new “Latex Leader” and “Latex Begin” keys rather than the old “Latex Input” ones (or “Latex Config” where appropriate). It also moves captions placed above tables and puts them below the tables since captions above tables are no longer supported in MM6. MMD > ODT has been added as a file format and MMD > RTF removed. XSLT support has been removed. A LaTeX preset for “Tufte (Book)” has been added. And I believe that is everything that was needed to make Scrivener MMD6-compatible.