Hacking Scrivener with MMD

I’ve been using Scrivener for the last few weeks, and I have to say I love it. But what I love about it is not the spartan interface (I came to Scrivener from Vim!), but the ability to export into a number of different formats easily and to adjust things like the translation of ellipses, italics, and so forth into whatever “manuscript format” I’m being asked to use. I had been writing just about everything I do (academic monographs, articles, etc.) in LaTeX, but when it was ready for publication, I’d invariably have to go through the tedious process of dumbing down a LaTeX file into RTF (or whatever).

So for me, the big win here is actually MultiMarkDown (which I hadn’t known about). But here’s the thing: How do I adjust the way the MMD files are translated into LaTeX? Scrivener has a nice one-button solution for getting to some other format from MMD, but I’d like to customize it for my particular needs. To put it plainly, I don’t want to use memoir with all the table-of-contents generation and the rest. I just want an ordinary LaTeX file that I can tweak a little as needed (without the TOC, and all of the other stuff). It would also be nice to be able say, “This is a letter, so throw in the basic fields of LaTeX letters.” Right now, I’m taking the generated LaTeX and erasing most of the stuff that was generated.

I’m not asking for a new feature in Scrivener. I’m really asking if I have the ability to write new kinds of translation plugins for the kinds of documents I need? I’m a very experienced programmer, so this wouldn’t be that big a deal, and I’d love to support both Scrivener and MMD. I really think that if I could control the export fully, I’d have the perfect system.

I’m sure the answer to this question is somewhere in the forums, and I hope you’ll all forgive me if this has been asked and answered many times. I’m very excited about MMD, and I really would like to get involved.

Hi,

This is the short answer (although I developed Scrivener, I’m no MMD expert - so hopefully Fletcher or another MMD user will be able to give you more information):

You can choose with XSLT class is used via the MultiMarkdown settings sheet in the File menu. You need to set the XSLT class you want to use against the key “LaTeX XSLT”. Memoir is used by default.

The MultiMarkdown package is included in Scrivener, but you can install it separately to ~/Library/Application Support/MultiMarkdown. Scrivener looks there first; if it’s not found there, then it uses the installation inside the Scrivener bundle. This way you can create your own XSLT classes.

I’m sure you’ve already gone through the docs at Fletcher’s page, so hopefully someone else will give you further information.

All the best,
Keith

There’s probably a lot of introductory material to be found in this section of the forum, but since you asked for it:

  1. Install the latest version of MultiMarkdown and make a backup of ~\Library\Application Support\MultiMarkdown\XSLT\ just to be on the safe side. If anything goes wrong, you can easily restore the default settings.

  2. Learn some XSLT basics.

  3. Now you’re ready to create your first custom XSLT file. I would base it on latex-snippet.xslt, which is a lot easier to understand than the other stylesheets. Duplicate the file, rename it and open it up in your favourite editor (TextWrangler is always a good choice).

  4. latex-snippet.xslt creates “header-less” LaTeX files by default. You can change this behaviour by modifying the root level (<xsl:template match=“/”>) of the stylesheet. Make it look like this:

<xsl:template match="/"> <xsl:text>\documentclass{article}& #10;</xsl:text> <xsl:text>\begin{document}& #10; </xsl:text> <xsl:apply-templates select="html:html/html:head"/> <xsl:apply-templates select="html:html/html:body"/> <xsl:call-template name="latex-footer"/> <xsl:text>\end{document}</xsl:text> </xsl:template>

& #10; (without the white space!) means line break, the rest, I think, should be self-explaining

  1. Now you can go through the rest of the file and change anything specific to memoir.cls back to standard LaTeX syntax.

  2. Change Scrivener’s MultiMarkdown settings to your new XSLT file (LaTeX XSLT: <yourfilename.xslt>)

Wow, this is completely fantastic. I didn’t realize that all of this was based on XSLT (which I have worked with since it came out). I probably should have explored things a little more before troubling you all with this.

I’m so excited. If I can swap out different stylesheets, I really will have the ideal system. This is just great.

Thanks for the detailed instructions. Now all I need is a little extra time to do it!

Let me say once again (since I have both of you on the line), that Scrivener and MMD are a couple of real gems.