Raw Latex escaping doesn't seem to passed to multimarkdown correctly

I have a scrivener document which includes some of my latex. (eventually this will just be the front matter which I don’t want to be included in the compile format–because it will change from book to book. Right now it’s still in the testing phase)

\begin{document} \frontmatter \pagestyle{empty} % Half-Title \vspace*{144pt} \begin{center} {\LARGE \mytitle} \end{center} \cleartorecto % Title Page

That document is a section type I have labelled “latex”, and is associated in my mmd–>latex compile format with a section layout which merely adds [code]

[/code] before the contents and [code]

[/code] after the contents.

When I compile to latex I get a .tex file which contains:

[code]```{=latex}

\textbackslash{}begin{document}

\textbackslash{}frontmatter

\textbackslash{}pagestyle{empty}

% Half-Title

\textbackslash{}vspace*{144pt}

\textbackslash{}begin{center}

{\textbackslash{}LARGE \textbackslash{}mytitle}

\textbackslash{}end{center}

\textbackslash{}cleartorecto

% Title Page[/code]

which, of course, doesn’t compile properly.

If I compile to mmd, I get:

\`\`\`\{=latex\}

\\begin\{document\}

\\frontmatter

\\pagestyle\{empty\}

% Half-Title

\\vspace\*\{144pt\}

\\begin\{center\}

\{\\LARGE \\mytitle\}

\\end\{center\}

\\cleartorecto

% Title Page

Since I don’t know the inner workings of the compile process or of mmd, I don’t know if I’ve included enough information here.

I’m either missing something basic about how Scrivener handles raw latex, or there’s a problem here. I’m hoping it’s the former…

It seems to be working fine for me, but one important detail that seems to be omitted from your post is that it looks like from your output example you might have the compile option set to convert a rich text based project to MMD? If so, you’ll need to bear in mind that option is primarily for those that do not know anything about Markdown or LaTeX, but are wishing to gain access to that workflow via a project written for word processor style usage.

You can mix workflows a bit (both in the main editor and in your compile settings), but it will take some additional setup. I should preface by saying that I’m mainly just putting this out there for the record, for now. None of this actually does anything, and some steps won’t even be possible to emulate given how heavily under construction the MMD side is yet:

  1. Firstly, you would want to create a “raw markup” style, in the Styles compile format pane. This will be used simply for that Treat as raw markup checkbox. The purpose of this flag is to switch off all RTF conversion for the text it is applied to. That includes the line padding and special character escaping that you see done here.
  2. So back in Section Layouts, you would need to apply this style to all three areas that generate text:
  • In the main Formatting pane, you would enable Override text and notes formatting, and then from the Format Bar, apply the style to all main body text used by this Layout.
  • And of course, in both the Prefix and Suffix fields, you would use the Format Bar to apply the style to any text you type in.

Like I say, the UI for doing that isn’t even intact, so keep that capability bookmarked for future reference.

⠂─────── ⟢⟡⟣ ─────── ⠂

Now in another direction entirely (and it also doesn’t work :neutral_face: ), which makes the previous explanation a bit academic (but useful for other practices): since it looks like you’re using this capability to handle the insertion of a preamble, you may be unaware of a built-in capability in Scrivener for doing that.

  1. Edit your compile Format.
  2. In the LaTeX Options pane, select “Custom” as your document class.

The rest should be fairly self-explanatory. The only tricky part is that the preamble is split into two, to allow MMD to set up metadata like \mytitle in the middle. So the kind of example code you have would go into the second tab, after that stuff is established. The first tab would be for things that must come before anything else, like the document class declaration.

You will find a practical demonstration of this approach with our built in “Modern (Custom LaTeX)” compile format, by the way. I designed that one to emulate the look of the “Modern” format, that can be used with RTF compile and so forth.

Overall I would say that is preferable to the approach you are taking because it puts the document look and feel information into a logical place rather than hacking into the outline, and it also keeps it in the Format, which as you explain, is an important concept if you want to make this something you can apply easily to any project, and for projects to be able to hot swap looks easily. This makes it even better because now you don’t need “compatible” projects with Section Types and outline structure set up to insert preambles.

Thanks so much, Amber.

You convinced me that all of this stuff could just go into the compile format, so I removed it from the manuscript and put it there instead.

So far this all seems to be my problem, not a real bug, so I’ll just describe what’s happening in hopes you can throw some light on it:

When I now compile, Scrivener saves the latex code I put into the latex options window fine, but the .tex file is the only file compiling produces at this point and there are no latex links inside that file for latex input or latex footer.

When I open up my compile format to look at the latex options again, it says “None (Use Metadata)” instead of “Custom”.

When I change it to “Custom” all of the code is still in there, but no matter how many times I save it, and look again, it always reverts to “None”, and nothing from that window shows up in the tex file or any other files. I’m assuming those two things are related, though they might not be.

I opened the Modern format to see what it looked like, producing a “Modern (Custom LaTeX) copy”, but didn’t change anything in it, and I’m getting the exact same behavior when I compile with that copy. No -begin or -footer files produced, no Latex Input lines in the single tex file.

I then tried a compile with the original Modern format (instead of the copy). That produced a tex file with Title, Author, and Latex Input lines, and three other files (mmd6-scrivecustom-begin.tex, etc.).

I then made a second copy of the modern format, and this time I saved it without even looking at anything (I had opened the latex section to see the code there on the first copy before saving it, but had not changed anything.) This copy worked exactly like the original, producing all three extra files, latex input to them in the main file, etc.

I’m at a loss at this point, and not at all sure whether this is a bug, or something I’m doing inadvertently.

Thanks for any help on this.

Apologies! I should have more clearly emphasised that this method does not work in the current build. You are doing everything correctly, and it really should be as easy as you’d think. There are multiple bugs that prevent any feasible workaround given the settings you are using, unfortunately:

  • The LaTeX Options panel does not save the document class as you set it, meaning none of those options actually work. There are futher bugs beneath that primary problem that would prevent them from fully working as well. Thus this panel is best ignored entirely for now.
  • So at least it does default to “none” giving you the option to set up metadata yourself instead of having Scrivener set it up, except that Metadata is converted as though it were rich text, meaning the lines are spaced out breaking the block. So you can’t use any of its dedicated metadata panels to use a non-automatic approach.
  • “Treat as raw markup” style setting does not work, which is what you could have used as a workaround, by placing all metadata into an “as-is” document at the top of the draft and wrapping it in a style to protect it from RTF conversion.

So I don’t think there is any way you can actually do this with the compiler. At a certain level, you can of course, because all the compiler is doing is automating a few steps that you’d ordinarily have to do by hand (i.e. setting up a typesetting folder with .tex files using the proper MMD naming convention, creating an .md file, and using multimarkdown.exe to process it to .tex).

A slightly better approach would be deleting all metadata in your compile settings and making sure to edit the “LaTeX Options” setting so that it gets lost (from whatever the preset had hard-coded), you’d then be producing a “snippet” .tex file, which you could then paste into a boilerplate file that has everything all set up except for the part the Draft generates.

Sorry for the misdirection. I am mainly describing what is intended in the design, and what should work when all of this is patched up. It not’s really a functional system at the moment, unless you only use it at a very basic level.

That completely clears up my confusion.

Thank you again.