MMD Headers

Ro
RobertB
Posts: 142
Joined: Sat Mar 31, 2007 5:36 pm
Platform: Mac

Mon Mar 29, 2010 1:00 pm Post

The following applies to TextMate but may be applicable to Scrivener. Fletcher has offered assistance but I thought I would pose my questions here because others may benefit from any solutions.

Ok, I'm trying to customize the headers for the article.xslt. I basically need:

Name Course Date

As my headers and the page number centered in the footer starting with page 2.

And I have discovered the following:

\def\mypagestyle{headings}
\markright{My Name\hfill Course\hfill \today\hfill}

The problem is that the page number is also inserted on the far right of the header when a PDF is generated.

My questions that I have searched for but can't seem to find a real answer (or at least one I understand):

1) Is there a way to use Metadata in the \markright code? Something like:

\def\mypagestyle{headings}
\markright{\author\hfill \title\hfill \today\hfill}

So that the Metadata for Author and Title from document are used? I've tried the above and it doesn't seem to work.

2) I can't figure out how to have the header above without the page number at the top right. It is inserted automatically after the date. I would like the page number to be centered in the footer.

Any help or pointers greatly appreciated.

User avatar
AmberV
Posts: 24407
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Mon Mar 29, 2010 1:23 pm Post

All of the meta-data gets converted into variables automatically. You can find a list of them in the generated LaTeX pre-amble, search for \def\myauthor{Your Name} and you should see a block of them all. \mytitle is the other one you are looking for.

It sounds like you are wanting to create your own custom page style. This should get you started:

Code: Select all

\makepagestyle{simple}
\makeevenhead{simple}{\rightmark}{}{\leftmark}
\makeoddhead{simple}{\rightmark}{}{\leftmark}
\makeevenfoot{simple}{}{\thepage}{}
\makeoddfoot{simple}{}{\thepage}{}
\pagestyle{simple}
\markright{\myauthor\hfill\mytitle\hfill\today}


The just set your pagestyle to `simple`
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Ro
RobertB
Posts: 142
Joined: Sat Mar 31, 2007 5:36 pm
Platform: Mac

Mon Mar 29, 2010 2:04 pm Post

Man, Amber that is a great help!!

So, I am using this and it is formatted the way I want:

\def\myauthor{Author}
\def\mytitle{Title}

\def\mychapterstyle{default}
\def\mypagestyle{simple}
\makepagestyle{simple}
\makeevenhead{simple}{\rightmark}{}{\leftmark}
\makeoddhead{simple}{\rightmark}{}{\leftmark}
\makeevenfoot{simple}{}{\thepage}{}
\makeoddfoot{simple}{}{\thepage}{}
\pagestyle{simple}
\markright{\myauthor\hfill\mytitle\hfill\today}

However, the Author and Title are not pulling in the metadata. Is there something else I should be doing?

Thank you so much for your assistance! I was beginning to pull out whatever hair I have left (and it isn't much)!

User avatar
AmberV
Posts: 24407
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Mon Mar 29, 2010 4:15 pm Post

Hmm, this worked for me. Make certain you are defining the markright after the variable declarations. I put all of the above right before the document env start.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Ro
RobertB
Posts: 142
Joined: Sat Mar 31, 2007 5:36 pm
Platform: Mac

Mon Mar 29, 2010 4:33 pm Post

Well, it is pulling in "Author" and "Title" but not those values from my MMD document. Very Weird...

User avatar
AmberV
Posts: 24407
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Mon Mar 29, 2010 4:54 pm Post

Is there a reason why you are setting these two variables again to "Author" and "Title" in the code sample you posted? In the LaTeX file I have generated, if I put "Something Something" as the MMD title, I get a line:

Code: Select all

\def\mytitle{Something Something}


At around line 71 in the source file. If you are placing:

Code: Select all

\def\mytitle{Title}


After that, then yes, it will appear as "Title" in the rendered copy. There shouldn't be any need to supply these, as the generated LaTeX file already has a few crucial variables assigned before the part where it consults the MMD meta-data. In brief, the preamble should (excluding irrelevant stuff) have the following bits in this order:

  • Default variable fall-backs declared.
  • MMD Meta-data variables inserted
  • Declaration of custom pagestyle
  • \begin{document}
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Ro
RobertB
Posts: 142
Joined: Sat Mar 31, 2007 5:36 pm
Platform: Mac

Mon Mar 29, 2010 5:18 pm Post

Amber,

There is no reason that I am declaring those again. I guess I am having trouble understanding how to declare the MMD variables in the preamble.

Ro
RobertB
Posts: 142
Joined: Sat Mar 31, 2007 5:36 pm
Platform: Mac

Mon Mar 29, 2010 5:33 pm Post

Ok, If I convert to LaTex I do see that my title and author metadata are being included. For some reason the TexMate command to convert to PDF (from the MMD bundle) is not pulling in this information using my custom xslt (basically article with the bit of code you provided above).

User avatar
AmberV
Posts: 24407
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Mon Mar 29, 2010 5:34 pm Post

You shouldn't have to declare anything at all. The XSLT takes care of declarations for you. So long as your pagestyle declaration comes after that section; right before the document environment starts, you shouldn't need to do anything else.

Update: Ah, I am not familiar with the TextMate MMD->PDF tool. I've always just created a .tex file from the MMD and then handled it from there in case anything needed to be tweaked with the tex file.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Ro
RobertB
Posts: 142
Joined: Sat Mar 31, 2007 5:36 pm
Platform: Mac

Mon Mar 29, 2010 7:47 pm Post

Amber. I had this working perfectly (except for the Metadata issue) and then lost the file I was editing and no I can't get it to work. This is the xslt I'm using to generate the header and footer. This is the complete file. For some reason, it is now being ignored totally and a title page is being generated. I have declared this file as my 'Latex XSLT' in my MMD document. I can't find anything wrong with it and thought maybe your trained eyes might fare better?

Code: Select all

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:html="http://www.w3.org/1999/xhtml"
   version="1.0">

   <xsl:import href="memoir.xslt"/>
   
   <xsl:output method='text' encoding='utf-8'/>

   <xsl:strip-space elements="*" />

   <xsl:template match="/">
      <xsl:apply-templates select="html:html/html:head"/>
      <xsl:apply-templates select="html:html/html:body"/>
      <xsl:call-template name="latex-footer"/>
   </xsl:template>

   <xsl:template name="latex-document-class">
      <xsl:text>\documentclass[oneside,article]{memoir}
\usepackage{layouts}[2001/04/29]
\usepackage{xmpincl}   % Seems to be required to get the pdf to generate??

\makepagestyle{simple}
\makeevenhead{simple}{\rightmark}{}{\leftmark}
\makeoddhead{simple}{\rightmark}{}{\leftmark}
\makeevenfoot{simple}{}{\thepage}{}
\makeoddfoot{simple}{}{\thepage}{}
\pagestyle{simple}
\markright{\myauthor\hfill\mytitle\hfill\today}

\def\mypagestyle{simple}

</xsl:text>
   </xsl:template>

   <xsl:template name="latex-begin-body">
      <xsl:text>%
% Main Content
%


% Layout settings
\setlength{\parindent}{1em}

</xsl:text>
   </xsl:template>

</xsl:stylesheet>

User avatar
AmberV
Posts: 24407
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Mon Mar 29, 2010 8:09 pm Post

I'm not around a computer with a TeX distribution installed, so I cannot test this all the way to the end, however I had no difficulty getting MMD to use the supplied XSLT. I saved it as `test.xslt` into the correct directory, and then added:

Code: Select all

LaTeX XSLT: test.xslt 


To the test file, and got the correct results. However, I would suggest some alterations. I would create an xsl:template for "latex-title" and paste the pagestyle dec in there instead of the "latex-document-class" template. This makes certain it gets produced below the variable definitions as recommended above, and it also wipes out the default which has a \maketitle call in it. That is where you are getting your separate title page.

Final result:

Code: Select all

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:html="http://www.w3.org/1999/xhtml"
    version="1.0">

    <xsl:import href="memoir.xslt"/>
   
    <xsl:output method='text' encoding='utf-8'/>

    <xsl:strip-space elements="*" />

    <xsl:template match="/">
         <xsl:apply-templates select="html:html/html:head"/>
         <xsl:apply-templates select="html:html/html:body"/>
         <xsl:call-template name="latex-footer"/>
    </xsl:template>

    <xsl:template name="latex-document-class">
         <xsl:text>\documentclass[oneside,article]{memoir}
\usepackage{layouts}[2001/04/29]
\usepackage{xmpincl}    % Seems to be required to get the pdf to generate??


</xsl:text>
    </xsl:template>
   
    <xsl:template name="latex-title">
      <xsl:text>
      \makepagestyle{simple}
      \makeevenhead{simple}{\rightmark}{}{\leftmark}
      \makeoddhead{simple}{\rightmark}{}{\leftmark}
      \makeevenfoot{simple}{}{\thepage}{}
      \makeoddfoot{simple}{}{\thepage}{}
      \pagestyle{simple}
      \markright{\myauthor\hfill\mytitle\hfill\today}

      \def\mypagestyle{simple}
      </xsl:text>
   
    </xsl:template>

    <xsl:template name="latex-begin-body">
         <xsl:text>%
% Main Content
%


% Layout settings
\setlength{\parindent}{1em}

</xsl:text>
    </xsl:template>

</xsl:stylesheet>


I'm not positive this will work, but again I'm not near a TeX station to test the final rendering of it.

When doing these things, I really recommend using Cmd-Opt-L on the MMD file to produce a raw TeX file. This lets you examine the layout of the file to make sure everything is in the right order. Going straight to PDF occludes potential problems, like setting up a pagestyle before meta-data variables have been declared.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Ro
RobertB
Posts: 142
Joined: Sat Mar 31, 2007 5:36 pm
Platform: Mac

Mon Mar 29, 2010 11:46 pm Post

Works like a charm. It must have been an issue with me placing the code outside of the "latex-title" section.

I'm pretty much set now (with this detail anyway... I feel like I just went down a rabbit hole with this).

Anyway, I really appreciate the assistance, Amber.

Thank you!

User avatar
AmberV
Posts: 24407
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Mon Mar 29, 2010 11:50 pm Post

You are welcome!

Yeah, that rabbit hole thing definitely can happen! In my experience, even a casual exposure to the inner workings of MMD can end up being fruitful knowledge, though. You never know when you need a quick class modification and now that you know how to make a wrapper with a few adjustments, it'll be easier the next time.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles