When I define a path as metadata the path does not get exported to latex file correctly

I define a meta data in scrivener 3 on MacOS as follows

imgrootpath = /Users/username/scrivener/Projects/project1/images

When I do compile MMD latex I get on top of my .tex file

\def\imgrootpath{\slash Users\slash username\slash scrivener\slash Projects\slash project1\slash images} instead of

Tried to escape the / with \/, wrapping in "" etc without success.
Also tried to do regex replacement by adding a respective rule in the compile definitions. Still no success.

It appears that on the way from scrivener → MMD → LaTeX something is modified and slashes are replaced by \slash .

What am I doing wrong?
I simply need to pass a path (via meta-data definition) to the .tex-file which I then use in the tex-file to expand the images with its root-path location. Wanted to put it in scrivener metedata, so that if I move the folder in future I can simply adapt to the new one by simply changing the metadata in scrivener …

Any tipp is highly welcome - despite being a software developer I am quite new to scrivener and started using it to mix writing and text rendering with LaTex … is it a bug or am I missing something?

The number one thing to always check is to make sure this is actually Scrivener doing what you think it is. I can assure you that Scrivener does not have the first clue about what LaTeX is, by itself, and would not know that \slash might be something worth putting anywhere. So in this case it is easy to deduce that MMD is the culprit, but sometimes the answer is not so clear.

So the first test you should always do is compile to plain MultiMarkdown, check the .md file and see if it looks like you expect it to, and then use multimarkdown -t latex -o test.tex input.md (or whatever you want for the filenames), to see if that conversion is where the behaviour is coming from.

I think in this case you will find this is an impossible to avoid MMD behaviour (frustratingly, I’ve run into it as well in the past). For example you can test this very easily on the command line:

$ multimarkdown -t latex
Title: Test Special Characters in Metadata
TestOne: /Path/to/file.jpg
TestTwo: `/Path/to/file.jpg`{=latex}

# Heading

Some \regular text.

Some `\regular`{=latex} text.

Hit Ctrl-D twice to terminate the buffer, and you’ll get the following output:

\def\mytitle{Test Special Characters in Metadata}
\def\testone{\slash Path\slash to\slash file.jpg}
\def\testtwo{`\slash Path\slash to\slash file.jpg`\{=latex\}}


Some \textbackslash{}regular text.

Some \regular text.


So here you can see the method one uses to pass raw LaTeX through to the output, as demonstrated in the two “paragraphs” following the heading. The first paragraph lets us talk about LaTeX by escaping syntax, and the second paragraph lets us use a custom macro.

But these don’t work in the Metadata block.

1 Like

Thank you for your fast response, AmberV.
Right. So, this means I cannot intercept this directly. What workaround did you take?

Since I completely configured the output without using Font-/Backmatter I can just think of putting in a paragraph at the ver beginning of my document for the purpose of doing some document global ‘settings’ (=text); something like:


Not elegant, but it works (just tested).
Thanks again.

Oh yeah, I should have mentioned what I did. That’s basically how I handled the problem. I took the extra step of putting it into my actual preamble .tex files though, which I include via MMD metadata (using the “LaTeX Config” setup).

For my purposes that was fine for what I needed anyway, since what I was trying to do was more design oriented than document specific. But yeah, otherwise for something like this that needn’t come before \begin{document}, you can just stash them as normal text items in the binder and use the pass-thru syntax to keep MMD from messing with them. As to whether that is elegant or not, I guess it depends on your perspective. If you take a look at the dedicated LaTeX project template in Non-Fiction (the one designed for non-Markdown users), you’ll find it makes extensive use of the notion of putting preamble stuff right in the binder. It’s part of the document after all, whether we see it in the end or not.

If you find yourself doing more than one line of that, you can use the fence quote method as well: