Prevent \end{document} in MMD - LaTeX Export


i’m new to Scrivener and try to setup my Scrivener LateX Environment. So far i got most things working (MMD in ~/Library/Application Support/, Bibdesk Drag’n’Drop, …)

My Problem is that i try to use the following setup:

LaTeX file head.tex with all my settings that includes a content.tex file with \include{content.tex}.
content.tex is the file to which i try export from scrivener.

After the export process there is a \end{document} in the content.tex file. Because of that \end{document} the rest of my head.tex (after include{content.tex}) is not processed.

Have you any suggestions how to prevent scrivener from writing \end{document} at the end of my content.tex file?


That’s not really a Scrivener issue. I believe MMD does this automatically (otherwise your Latex doesn’t compile).

Your workflow isn’t ideal for Scrivener and MMD in my experience. I would recommend moving the main document into Scrivener, and using MMD’s custom files to handle the header/footer portions.

There is a nice way to do this with MMD3, and maybe I should blog about how I set it up because it is too detailed for a comment.

Probably the easiest thing to do for your situation is to use a command line replace to remove the offending \end{document}, something like:

sed 's/\\end{document}//' <content.tex > fixed.tex

and then use \input{fixed} in your document.
NOTE: I have not tested that extensively.

I agree, you generally want to work the other way around, actually with MMD 3. You include the head and foot files, rather than the other way around. This can be easily accomplished via the “LaTeX Input” and Footer meta-data fields. An example would be:

LaTeX Input: preamble.tex Title: Name of Document Author: Your Name Date: Today LaTeX Input: begin-document.tex LaTeX Footer: footer.tex

The preamble should be devoid of anything that needs meta-data info, naturally. The begin-document one should include any title page rewrites etc that require MMD generated meta-data. Footer is self-explanatory. Scrivener and MMD will insert everything in your Draft folder in between the begin-document.tex and footer.tex files.

If you are using MMD2, then that is another matter entirely. That system generates a complete top to foot .tex file using the XSLT language, and it would not be suitable for \input, unless you use the latex-snippet.xslt file, which just generates the book matter and nothing else.

Thank you for your answers. The way to import the preamble works for me.