Inserting any LaTeX code in Scrivener

As noted in an earlier post, using math mode in Scrivener is very easy. Using MultiMarkdown – which can be found here – the MultiMarkdown to .tex compiler recognises the syntax and performs the conversion seamlessly.

However, for more complex LaTeX code, there is another route. This post describes how to insert any LaTeX code in the body of your Scrivener document. Again, we use the MultMarkdown to .tex compiler so that any formatting in the document is preserved, but we take advantage of the ability to direct the compiler to process text in HTML tags.

Including LaTeX code in the Scrivener document:

The syntax for this is

<!– LaTeX code –>

For example,

<!–\title{Introduction}–>

<!–\newpage{}–>

<!–\tableofcontents{}–>

<!–${e}^{i\pi }+1=0$–>

Creating a TeX file:

File > Compile…

From the Compile for drop-down menu, select MultiMarkdown to Latex (.tex).

From the Format as drop-down menu, select Custom.

Under Contents, choose which documents are to be added by selecting the check-boxes in the Include column. (If this isn’t visible, select the down arrow on the right of the Format as drop-down menu.)

From the LaTeX menu, choose Custom as the LaTeX document class to include custom header information, e.g. \usepackage{ }, if any special packages are used.

From the Meta-Data menu, check the box labelled Use XSLT post-processing. On hovering over this option, the information states, “this option tells MultiMarkdown to process text included within HTML tags in the source document”, as shown below (click for larger image).

It is this option that processes the HTML enclosed code. Whilst other options stay the same between one Compile and the next, this box has to be checked every time.

Select Compile.

Importing into LyX:

I use LyX to fine-tune my .tex documents. To import:

File > Import > LaTeX (plain)…

Select the .tex file