One little thing about the article.xslt in MultiMarkdown that I don’t like are the boring headers. For some reason (and perhaps it’s MLA style to do this), I think having the last name next to the page number looks more professional, more seriously academic, than just having page numbers. So, how can I make Scrivener do that?

It’s not too tricky, but it’s trickier than part A was… I’m indebted, by the way, to Stuart’s post on setting the headers.

Anyway, basically, we want to do three things:

  1. Get the author’s surname somehow
  2. If we don’t have a surname, make a blank
  3. Have some xslt transfer the information to LaTeX

Easy!

Tell Scrivener the author’s last name

The first step is Scrivener specific. MultiMarkdown documents (which are what we’re using to transfer from Scrivener to LaTeX) have Metadata. If you’ve followed the tutorial on the MultiMarkdown site, you’re a pro at this. Let’s assume you haven’t.

In Scrivener, go to File > MultiMarkdown Settings… The “Meta-Data” window drops down. On the left are Keys, and on the right is the value corresponding to the selected key. This is, of course, where you define your Title, Subtitle, Author, LaTeX XSLT, and BibTeX keys, among others. So we’ll create another, called simply, “Surname”.

Click on the “+” on the left, type in Surname, and in the large white area on the right, type in your surname (or that of the author of the document you are writing).

Editing the .xslt

Now get ready… This part is tricky.

  1. Making the .xslt find the surname metadata

    First, we have to open up the xhtml2latex.xslt that we edited in my first tutorial on customizing MultiMarkdown. To whit: in the Finder, type Apple-shift-G and type in:

    ~/Library/Application Support/MultiMarkdown/XSLT

    Open up the file called “xhtml2latex.xslt” in TextEdit or TextWrangler. If you just double click on it, it will open in Safari. Not useful. To open it with a different program “right” or option-click on the file and choose “Open With” in the dropdown menu. Then pick a real text editor.

    Now we need to install some code in the file. Around line 67, you should see:

    <xsl:template match="html:meta">
         <xsl:choose>

    Right after that <xsl:choose>, paste in:

    <!-- surname metadata added for page headers -->
    <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'surname'">
    <xsl:text>\def\surnamecomma{</xsl:text>
    <xsl:call-template name="clean-text">
    <xsl:with-param name="source">
    <xsl:value-of select="@content"/>
    </xsl:with-param>
    </xsl:call-template>
    <xsl:text>, }
    </xsl:text>
    </xsl:when>
    <!-- end surname metadata -->

    It’s important to nail this, so that’s why I encourage copying and pasting. Note especially the line with the , }. that means that it’s going to append a comma and a space to the surname you provide in the Scrivener metadata, automatically.

    Right after the bit you pasted in, a new <xsl:when test should begin that hunts for the name.

  2. Defining a blank surname

    This step is initially easy, but that’s misleading. Now, the xhtml2latex.xslt is good at assuming metadata isn’t defined. So let’s assume that the “surname” key isn’t defined, and just make it blank. Hop to around line 1079, looking for:

    \def\myauthor{Author} % In case these were not included in metadata
    \def\mytitle{Title}
    \def\mykeywords{}
    \def\mybibliostyle{plain}
    \def\bibliocommand{}

    Right underneath, add:

    \def\surnamecomma{}

    Under normal circumstances, we’d be set. However, in part A, remember, we told article.xslt to use memoir-xelatex.xslt, and memoir-xelatex.xslt writes over this part of the code that we just altered. So now we have to REPEAT this alteration on the memoir.xelatex.xslt file, opening it in a text editor and so on. Make note of this repeated step![1]

  3. Defining the header:

    This is the money part. Back in the xhtml2latex.xslt file, about 100 lines down from where you added the \def\surnamecomma{}, you should see:

    \begin{document}

    Right above it, insert:

    \makepagestyle{surname}
    \makeoddhead{surname}{}{}{\surnamecomma\thepage}
    \pagestyle{surname}

    Of course, if you added the biblatex functionality from part A, these new three lines would be between the biblatex addition and \begin{document}.

That should be everything you need to do. Now save and export your Scrivener project, and you should get your fancy last name on the page heading if you defined it, and regular page numbers if you didn’t!

1. What a mess this repeated step is, however I’m not sure how to get it to pass the blank variable in all circumstances. Considering that MultiMarkdown repeats information, I don’t think it’s the end of the world to do things this way. It’s just hell of inelegant.

Tags: , , , ,

Leave a Reply