"Surname, pagenum" header in LaTeX via Metadata in Scrivener

(adapted from: http://www.1984produkts.com/donkeyhottie/archives/2008/05/16/customizing-multimarkdown-to-make-scrivener-easier-part-b/)

One of the nice things about the mla.sty is that the mla environment includes a field for “surname,” so you can get the (to me) more professional “Surname, pagenumber” headers on all pages after the first. I figured replicating this would be a good chance to make use of the MMD Metadata in Scrivener.

In your Scrivener project, open the MMD settings and define a key called “Surname” with your surname as the value.

Next, you have to edit xhtml2latex.xslt in three places (as well as in one place in memoir-xelatex.xslt, if you’re using XeLaTeX)

  1. Around line 67, you should see:

<xsl:template match="html:meta"> <xsl:choose>
Right after that xsl:choose, paste in:

[code]
<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>

[/code]

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.

  1. Around line 1079, you should see:

\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{}
REPEAT this on memoir.xelatex.xslt, looking for the similar part of the file

  1. Around line 1150 of xhtml2latex.xslt:

Where you see:

\begin{document}
Right above it, insert:

\makepagestyle{surname} \makeoddhead{surname}{}{}{\surnamecomma\thepage} \pagestyle{surname}
That’s it!

Thanks for sharing this! That’s very helpful.

BTW: Is there a way to specify MMD Meta-Data that overrules Scrivener’s MMD Settings? When I import MMD files in Scrivener there’s always a new document called “Meta-Data” in the binder with all the settings from the MMD file in plain text. It would be great if Scrivener could reuse this data. It’s probably best to write in pseudo-code what I envisage:

begin Compile Draft if Text "Meta-Data" exists import keys from Text "Meta-Data" else import keys in Markdown Settings ... end

no prob. It dawns on me that I was assuming a person writing a “onesided” document here like a term paper. To get the header to appear recto and verso:

\makepagestyle{surname} \makeoddhead{surname}{}{}{\surnamecomma\thepage} \makeevenhead{surname}{\surnamecomma\thepage}{}{} \pagestyle{surname}
though in my head, that would look very weird. Hopefully enough string management is given in the example to show an intermediate user how to make a nicer even-page header.