# Including Latex code when compiling MMD --\> Latex in Scrivener 3

**URL:** <https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423>\
**Category:** Markdown & LaTeX\
**Tags:** support, compile, styles\
**Created:** [February 3, 2023, 5:10pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423 "2023-02-03T17:10:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 5:10pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/1 "2023-02-03T17:10:47Z")

</div>

In Scrivener 3, how does one include verbatim Latex code and pass it through the compile process of MMD → Latex? In the old Scrivener, I used to include code like:

However it looks like this is being entirely stripped out in the compile process in Scrivener 3 – it is just omitted from the .tex document.

---

<div class="post-metadata">

**Author:** ![xiamenese](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/xiamenese/32/23720_2.png) [@xiamenese](https://forum.literatureandlatte.com/u/xiamenese)\
**Post date:** [February 3, 2023, 5:39pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/2 "2023-02-03T17:39:18Z")

</div>

Select the code and use Format → Preserve Formatting (give it a shortcut fore ease of use).

🙂

Mark

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 6:18pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/3 "2023-02-03T18:18:37Z")

</div>

I get something like:

\textbackslash{}input{table.tex}

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 6:20pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/4 "2023-02-03T18:20:57Z")

</div>

I just noticed that the code I used in my question above didn’t make it in. What used to work is:

`<!--\input{table.tex}-->`

Note sure if that clarifies the question

---

<div class="post-metadata">

**Author:** ![xiamenese](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/xiamenese/32/23720_2.png) [@xiamenese](https://forum.literatureandlatte.com/u/xiamenese)\
**Post date:** [February 3, 2023, 6:27pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/5 "2023-02-03T18:27:53Z")

</div>

My apologies. I’m not actually a LaTeX user, and I thought that would pass it through as it does my MD codes. I hope AmberV, nontrppo or one of the other LaTeX gurus will be along to help you soon.

---

<div class="post-metadata">

**Author:** ![AmberV](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/amberv/32/13021_2.png) [@AmberV](https://forum.literatureandlatte.com/u/AmberV)\
**Post date:** [February 3, 2023, 6:44pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/6 "2023-02-03T18:44:37Z")

</div>

Using HTML comments is an obsolete method at this point, MultiMarkdown hasn’t used that for some years.

The easiest answer, if you are using one of our build-in LaTeX oriented compile Formats, is to create a style called “Raw LaTeX” in your project, with whatever formatting you want, and style the verbatim text.

If you aren’t using one of those, then double-click on one of them (like “Article (Memoir)”) to duplicate and edit it, and check the Styles pane to see where this “magic” is coming from. If the compiler finds text marked as “Raw LaTeX” in the project, it will enclose the sequence in the necessary syntax to pass-thru the text verbatim.

So you can copy that convention into your own format—or this is more just a one-off thing that doesn’t need so much mechanism to it, just type in what you see in the prefix & suffix fields:

```latex
`\input{table.tex}`{=latex}

```

As you might guess, this new system is a lot more powerful since you can declare the output type that should use the pass-thru. If you compile a document with the above to HTML or ODT, it will be completely ignored in the output.

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 6:51pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/7 "2023-02-03T18:51:36Z")

</div>

thanks, just to clarify, I need to create this style under Format → Style → New Style from selection? As opposed to something that I am doing in the compile window?

---

<div class="post-metadata">

**Author:** ![AmberV](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/amberv/32/13021_2.png) [@AmberV](https://forum.literatureandlatte.com/u/AmberV)\
**Post date:** [February 3, 2023, 6:55pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/8 "2023-02-03T18:55:11Z")

</div>

Precisely. What I do is mark the verbatim text bright red, and then use that menu command to create a character style called “Raw LaTeX”, and go through an apply it to anything else that needs it. Use whatever aesthetic you prefer though.

You don’t need to mess with compile settings _unless_, like I say, you are creating your own compile Format (the list of things in the left sidebar) from scratch, or using one of the basic ones that isn’t aimed at LaTeX use (such as “Basic MultiMarkdown” or “Default”).

Just keep in mind that the Styles list in the compile format looks for matching names of styles used _in the project_. That is how we magically add syntax to text that we mark. It’s a very powerful capability worth becoming familiar with as it can mean reducing clutter in the writing space. If you flip through some of the example styles in those formats, you’ll see what I mean—for example the indexing styles can add the indexing syntax around words you highlight.

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 7:00pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/9 "2023-02-03T19:00:41Z")

</div>

I am using a custom compile format (among other things, I’m working on project started in the old scrivener). I added my ‘Raw Latex’ style to the styles list but on first try I am still getting the same problem. I see the box ‘treat as raw markup’ – does that need to be ticked? (Trying it now, anyway…)

---

<div class="post-metadata">

**Author:** ![AmberV](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/amberv/32/13021_2.png) [@AmberV](https://forum.literatureandlatte.com/u/AmberV)\
**Post date:** [February 3, 2023, 7:05pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/10 "2023-02-03T19:05:10Z")

</div>

Did you copy the prefix and suffix fields from one of the other formats? That is necessary otherwise it won’t do anything.

The “raw syntax” checkbox doesn’t do anything unless you’re using the checkbox that converts RTF style formatting to MMD (it is thus a way to type Markdown into such documents as conversion otherwise escapes MMD punctuation).

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 7:09pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/11 "2023-02-03T19:09:01Z")

</div>

right, I didn’t understand that part of your first comment but now I see that…I think I have it now

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 7:30pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/12 "2023-02-03T19:30:16Z")

</div>

On to the next (related) thing – this works for inclusion of tables and figures, which pretty much by definition go in their own paragraph. But I was also using HTML comments to use table and figure references, such as:

`As shown in table <!--\ref{tab:mytable}-->`

These go within a paragraph and indeed within a sentence. When I select just this text to mark it as my ‘raw LaTex’ style, the whole paragraph acquires this style. Is ‘style’ inherently defined for whole paragraphs? Is there way to define this style for just a short chunk of a pragraph?

---

<div class="post-metadata">

**Author:** ![AmberV](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/amberv/32/13021_2.png) [@AmberV](https://forum.literatureandlatte.com/u/AmberV)\
**Post date:** [February 3, 2023, 8:04pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/13 "2023-02-03T20:04:43Z")

</div>

In that case you’ll probably want a pair of styles, one for whole blocks and another for inline spans (with distinctive names, like “Raw LaTeX Span” or “Raw LaTeX Block”).

You can create a character style by using the same “New Style from Selection” menu command, and making sure to set the **Formatting** dropdown to “Save Character Attributes” in the style configuration window. It will have a different icon in the style menus and lists, just an ‘a’. Then of course create a compile style matching it (it is important to match character styles with character styles and vice versa).

That aside, I did not realise you were looking to implement whole blocks with the first one. There are two different forms of this Markdown syntax that you can use, the one demonstrated below is safer for large blocks of multiple lines, and the other I already showed you is better for inline markings that won’t span newlines:

````
```{=latex}
\begin{figure}[htbp]
\centering
\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{image_name.png}
\caption{The caption of the image}
\end{figure}
```

````

So the special bits here are the triple-ticks on their own lines at the beginning and end, and of course the {=latex} marker on the end of the first.

[raw\_latex\_samples.zip](https://forum.literatureandlatte.com/uploads/short-url/x5tZf3nudcc2wg1Jwvw5QdoeCMQ.zip) (131.7 KB)

The attached project has a couple of working examples, including compile settings, for your reference. Really the only tricky thing here is to make sure that your **Prefix** and **Suffix** fields have a newline after and before, respectively, for the block method shown above. For the syntax to be valid they must fall at the start of a line.

By the way, you are aware that MultiMarkdown already does some of the things you are describing? It can generate figures, tables and you can cross-reference to them using more natural syntax to do so. I get if you want custom syntax though.

One last thing:

> `As shown in table <!--\ref{tab:mytable}-->`

This is an example of where maybe using a style _just for that_ is a good idea as this is the kind of thing you’re probably going to be typing in a lot of. We could cut down what you need to type to: “tab:mytable” into the editor, while the compiler, via the prefix and suffix fields, inserts this around the text:

```nohighlight
Prefix: `\ref{
Suffix: }`{=latex}

```

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 8:05pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/14 "2023-02-03T20:05:12Z")

</div>

Update (for posterity): figured out that this can be done by applying character style, rather than paragraph style, to the in-line text. One thing I am still confused about @AmberV is the best way to create a new character style. When you create a new style it seems to be a paragraph style by default. I got around this by choosing Style → redefine style from selection and redefining one of the existing character styles, but this seems like a bit of a hack.

---

<div class="post-metadata">

**Author:** ![AmberV](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/amberv/32/13021_2.png) [@AmberV](https://forum.literatureandlatte.com/u/AmberV)\
**Post date:** [February 3, 2023, 8:06pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/15 "2023-02-03T20:06:42Z")

</div>

> When you create a new style it seems to be a paragraph style by default.

It’s entirely a matter of what you set it to via the **Formatting** dropdown in the style setup panel upon creation. You can’t convert between para and character styles, which may be the source of confusion. Once you create a style, that dropdown becomes more limited.

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [February 3, 2023, 8:10pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/16 "2023-02-03T20:10:41Z")

</div>

Aha, I see, ‘save character attributes’

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [May 31, 2024, 3:48pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/17 "2024-05-31T15:48:14Z")

</div>

Has anything changed with how Scrivener allows raw Latex to be passed through compiling with multimarkdown? I have been using the steps discussed in this thread from over a year ago, but suddenly cannot get this to work on new documents. I have created Raw Latex and Inline Raw Latex styles and added them to the styles window with prefix: `and suffix`{=latex}. My inclusion of:

\loadFigure{fig:polarization-survey}

renders as

\textbackslash{}loadFigure{fig:polarization-survey}

In the compiled .tex document

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [May 31, 2024, 3:51pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/19 "2024-05-31T15:51:12Z")

</div>

the prefix and suffix did not render correctly above, can’t figure out how to do it in the forum. prefix is single back tick. suffix is back tick followed by {=latex}

---

<div class="post-metadata">

**Author:** ![tvg42](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tvg42](https://forum.literatureandlatte.com/u/tvg42)\
**Post date:** [May 31, 2024, 4:19pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/20 "2024-05-31T16:19:55Z")

</div>

I have now resolved this

---

<div class="post-metadata">

**Author:** ![AmberV](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/amberv/32/13021_2.png) [@AmberV](https://forum.literatureandlatte.com/u/AmberV)\
**Post date:** [May 31, 2024, 4:26pm UTC](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423/21 "2024-05-31T16:26:43Z")

</div>

Yeah, the forum also uses Markdown, so you have to code block if you want to demonstrate something verbatim like this.

```nohighlight
`\loadFigure{fig:polarization-survey}`{=latex}

```

What went wrong, out of curiosity?

[Next page](https://forum.literatureandlatte.com/t/including-latex-code-when-compiling-mmd-latex-in-scrivener-3/132423.md?page=2)
