Multimarkdown front matter after ToC in MMD->Latex workflow

I am compiling a PhD dissertation using the multimarkdown to Latex feature. I want to add an acknowledgements section after the title page and before the ToC.

I have created an “acknowledgments” document, and designated it as front matter in the compile window. However, when i compile it, the acknowledgements appear after the ToC.

How do I move the acknowledgements page in the right position. I have tried placing the <$toc> tag at different places but that does not have any impact

Firstly, what you want to do is a little bit of a challenge because there is some spaghetti ordering issues between how MMD works and what it would take to get main content somehow outside of that and into areas that ordinarily aren’t written to in the preamble. But I’ll come back to that, because first it is necessary to clarify where Scrivener stops and MultiMarkdown begins.

Background on how this works

First, some background, and how to get started on customisation. The appearance of the \tableofcontents command in the output isn’t coming from Scrivener (in fact this question has very little do with Scrivener), or even the MultiMarkdown converter for that matter.

It’s in the .tex boilerplate files that are \input from the main .tex file you compile. If you want to shuffle the order of how things appear in the front matter, you will need to create you own variation of these files, and that part itself is fortunately quite easy to do. The example comes in a somewhat modular package, so you can create a fork of the three main .tex files and keep most of the \input statements within them the same.

I’ve written an introduction on how to create custom LaTeX designs with Scrivener+MultiMarkdown. This will walk you through downloading the ingredients you’ll want to work from and set up your texmf folder, and how to set up MMD’s metadata block so that it uses your custom setup (which ultimately is a matter of setting up Scrivener to set up MMD).

As an aside, the Front Matter feature with Pandoc/MMD is solely for conveniently swapping out different sets of files depending on the output. It does not indicate to MMD where to start front matter and begin main matter, because there is nothing in Markdown that would do that anyway (that is again, a matter of where the \mainmatter marker is in the .tex file that contains it).

For an example, after setting up the texmf folder as described in that post, have a look at the memoir-book/mmd6-memoir-book-begin.tex file. Toward the bottom of this is where you’ll find both the \tableofcontents command the \mainmatter command. Above here is where you would want to place your acknowledgements.

Ordering problem and solutions

Now that you’re looking at how this all fits together first-hand, you will see the issue I brought up at first. Everything MMD puts into the compile .tex file will come after the \input{mmd6-whatever-leader} and \input{mmd6-whatever-begin} and commands. To effectively get content from that file, into the boilerplate before it, would be a impossible because it only writes the “middle” .tex file that calls on the boilerplate. There is a bit of a chicken and egg problem here.

Make it part of the boilerplate

A very simple approach: if this content will not change much, then you could save it as ‘acknowledgements.tex’, then add \input{acknowledgements} in the appropriate place of your custom *-begin.tex file. It would then effectively be a part of your boilerplate rather than something coming out of the compiler, and should be removed from the front matter or draft folder.

Refer to the user manual, §21.5.1, Compile Folder, for setting up a persistent compile folder rather than it making a new folder every time. This is how you will place .tex files like this, or images for imprint logos and such.

Custom metadata

Open a compiled .tex file and examine the top, you’ll see something interesting going on with metadata. For short things you could get away with using MMD’s custom metadata to create commands that can be used elsewhere.

For example, if you create a line in the Metadata compile option tab called ‘Dedication’, and then in the text field below, type in some text for the dedication, then you could put \clearpage\dedication into the boilerplate file. Since MMD will declare these metadata commands in the main .tex file before it inputs the last preamble file, this is how you can use data from your project or compile settings in the boilerplate. This is how your title page gets populated from the fields in the Metadata tab.

But, if the acknowledgements are a more typical two or three pages of written text, using the metadata system for that would be pretty awkward, especially since no Markdown parsing will be done in it—it will be effectively plain-text. You also have to follow strict rules to keep multi-paragraph text valid in a metadata field. So I would only go this route if it is very short.

Taking over boilerplate roles in Scrivener

Lastly, and this may be the best for what you are trying to do, you can reduce how much the final .tex input file is doing, and take over its role earlier on in the Markdown content. The default templates all assume the first line of text in your output should follow \mainmatter, but that’s just a matter of how the text is typed into these .tex files. You can dedicate the first part of your binder to preamble, and start the \mainmatter yourself, cutting that stuff out of the custom .tex files you make.

So, by making it so that your custom *-begin.tex doesn’t actually do anything after the title page, and you put all of that into your Scrivener front matter folder, in the right order around the stuff you want turned into proper front matter sections.

Just be sure to tell MMD that’s what you’re doing, because it will otherwise assume you are writing a book about LaTeX and escape all the special characters:

```{=latex}
\tableofcontents
\listoftables

\mainmatter
```

The fence quotes around it, marked with the LaTeX language notation, will tell MMD to pass-thru the contents directly into the output, if converting to .tex (otherwise delete it so it doesn’t end up in HTML or whatever).

If you do a lot of that, you might want to make a Section Type + Layout that handles the fence quotes stuff for you.

This is an approach I have used myself for a few things, particularly beta releases of manuals, where I want a beta notice to be very prominently positioned after the title page.

1 Like