Skip to content

How do I create a MultiMarkdown document?

Fletcher T. Penney edited this page Apr 6, 2011 · 19 revisions

How do I create a MultiMarkdown document?

The general concept in MultiMarkdown is that it should be easy for someone to type a plain text file that is human-readable, and then use the MultiMarkdown program to convert that text file into a more complicated computer language such as XHTML or LaTeX. This allows you to create high quality output without having to spend hours and hours fiddling with font sizes, margins, etc.

The first step in learning to use MultiMarkdown is to learn how to use Markdown. MultiMarkdown is an extension to Markdown, and builds off of the basic fundamentals used in Markdown.

I recommend starting by familiarizing yourself with the Markdown basics and syntax pages.

Once you're familiar with the basics of Markdown, it will be relatively easy to pick up the advanced features included in MultiMarkdown.

Metadata

It is possible to include special metadata at the top of a MultiMarkdown document, such as title, author, etc. This information can then be used to control how MultiMarkdown processes the document, or can be used in certain output formats in special ways.

Title:	 A Sample MultiMarkdown Document  
Author:  Fletcher T. Penney  
Date:	 February 9, 2011  
Comment: This is a comment intended to demonstrate  
		 metadata that spans multiple lines, yet  
		 is treated as a single value.  
Test:	 And this is a new key-value pair  

The syntax for including metadata is simple.

  • The metadata must begin at the very top of the document - no blank lines can precede it.

  • Metadata consists of the two parts - the key and the value

  • The metadata key must begin at the beginning of the line. It must start with a letter or number, then the following characters can consist of letters, numbers, spaces, hyphens, or underscore characters.

  • The end of the metadata key is specified with a colon (':')

  • After the colon comes the metadata value, which can consist of pretty much any characters (including new lines). To keep multiline metadata values from being confused with additional metadata, I recommend indenting each new line of metadata. If your metadata value includes a colon, it must be indented to keep it from being treated as a new key-value pair.

  • While not required, I recommend using two spaces at the end of each line of metadata. This will improve the appearance of the metadata section if your document is processed by Markdown instead of MultiMarkdown.

  • Metadata keys are case insensitive and stripped of all spaces during processing. This means that Base Header Level, base headerlevel, and baseheaderlevel are all the same.

  • Metadata is processed as plain text, so it should not include MultiMarkdown markup. It is possible to create customized XSLT files that apply certain processing to the metadata value, but this is not the default behavior.

  • After the metadata is finished, a blank line triggers the beginning of the rest of the document.

Complete documents vs "snippets"

In order to include metadata information such as a title, the XHTML document created by MultiMarkdown must be "complete." This means that it starts with something that looks like:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

If you include metadata in your document (with two exceptions), then you will generate a complete document. If you don't include metadata, then you will instead generate a "snippet." The snippet will just include the relevant portion of XHTML, but will not include the <head> or <body> elements.

Metadata that is only intended to affect the way MultiMarkdown process the output will not trigger a complete document. Currently, this means you can use Base Header Level or Quotes Language and still output a snippet if you don't include any other metadata.

Document formats other than XHTML don't have distinctions between complete documents and snippets. Any included and relevant metadata will be included if present.

"Standard" Metadata keys

There are a few metadata keys that are standardized in MultiMarkdown. You can use any other keys that you desire, but you have to make use of them yourself.

My goal is to keep the list of "standard" metadata keys as short as possible.

Author

This value represents the author of the document and is used in LaTeX documents to generate the title information.

Affiliation

This is used to enter further information about the author --- a link to a website, an employer, academic affiliation, etc.

Base Header Level

This is used to change the top level of organization of the document. For example:

Base Header Level: 2

# Introduction #

Normally, the Introduction would be output as <h1> in XHTML, or \part{} in LaTeX. If you're writing a shorter document, you may wish for the largest division in the document to be <h2> or \chapter{}. The Base Header Level metadata tells MultiMarkdown to change the largest division level to the specified value.

This can also be useful when combining multiple documents.

Base Header Level does not trigger a complete document.

Additionally, there are "flavors" of this metadata key for various output formats so that you can specify a different header level for different output formats --- i.e. LaTeX Header Level, XHTML Header Level, and ODF Header Level.

Copyright

This can be used to provide a copyright string.

CSS

This metadata specifies a URL to be used as a CSS file for the produced document. Obviously, this is only useful when outputting to XHTML.

Date

Specify a date to be associated with the document.

Quotes Language

This is used to specify which style of "smart" quotes to use in the output document. The available options are:

  • dutch
  • english
  • french
  • german
  • germanguillemets
  • swedish

The default is english if not specified. This affects XHTML output. To change the language of a document in LaTeX is up to the individual.

Quotes Language does not trigger a complete document.

LaTeX Footer

A special case of the LaTeX Input metadata below. This file will be linked to at the very end of the document.

LaTeX Input

When outputting a LaTeX document it is necessary to include various directions that specify how the document should be formatted. These are not included in the MultiMarkdown document itself --- instead they should be stored separately and linked to with \input{file} commands.

These links can be included in the metadata section. The metadata is processed in order, so I generally break my directives into a group that need to go before my metadata, a group that goes after the metadata but before the document itself, and a separate group that goes at the end of the document, for example:

latex input:		mmd-memoir-header
Title:				MultiMarkdown Example
Base Header Level:	2
latex mode:			memoir
latex input:		mmd-memoir-begin-doc
latex footer:		mmd-memoir-footer

You can download the LaTeX Support files if you want to output documents using the default MultiMarkdown styles. You can then use these as examples to create your own customized LaTeX output.

TODO: include more details about this

LaTeX Mode

When outputting a document to LaTeX, there are two special options that change the output slightly --- memoir and beamer. These options are designed to be compatible with the LaTeX classes of the same names.

ODF Header

You can include raw XML to be included in the header of a file output in OpenDocument format. It's up to you to properly format your XML and get it working --- MultiMarkdown just copies it verbatim to the output.

Title

Self-explanatory.

XHTML Header

You can include raw XHTML information to be included in the header. MultiMarkdown doesn't perform any validation on this data --- it just copies it as is.

As an example, this can be useful to link your document to a working MathJax installation (not provided by me):

xhtml header:  <script type="text/javascript"
	src="http://example.net/mathjax/MathJax.js">
	</script>

Cross-References

Image and Link Attributes

Tables

Footnotes

Citations

Definition Lists

Math

MultiMarkdown 2.0 used ASCIIMathML to typeset mathematical equations. There were benefits to using ASCIIMathML, but also some disadvantages.

When rewriting for MultiMarkdown 3.0, there was no straightforward way to implement ASCIIMathML which lead me to look for alternatives. I settled on using MathJax. The advantage here is that the same syntax is supported by MathJax in browsers, and in LaTeX.

This does mean that math will need to be entered into MultiMarkdown documents using the LaTeX syntax, rather than ASCIIMathML.

To enable MathJax support in web pages, you have to include a link to an active MathJax installation --- setting this up is beyond the scope of this document, but it's not too hard.

Here's an example of the metadata setup, and some math:

latex input:	mmd-article-header  
Title:			MultiMarkdown Math Example  
latex input:	mmd-article-begin-doc  
latex footer:	mmd-memoir-footer  
xhtml header:	<script type="text/javascript"
	src="http://example.net/mathjax/MathJax.js">
	</script>
		
		
An example of math within a paragraph --- \\({e}^{i\pi }+1=0\\)
--- easy enough.

And an equation on it's own:

\\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \\]

That's it.

Here's what it looks like in action (if you're viewing this document in a supported format):

An example of math within a paragraph --- \({e}^{i\pi }+1=0\) --- easy enough.

And an equation on it's own:

\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]

That's it.

Glossary

Raw XHTML

You can include raw (X)HTML within your document. Exactly what happens with these portions depends on the output format. You can also use the markdown attribute to indicate that MultiMarkdown processing should be applied within the block level HTML tag. This is in addition to the --process-html command line option that causes MultiMarkdown processing to occur within all block level HTML tags.

For example:

<div>This is *not* MultiMarkdown</div>

<div markdown=1>This *is* MultiMarkdown</div>

will produce the following without --process-html:

<div>This is *not* MultiMarkdown</div>

<div>This <em>is</em> MultiMarkdown</div>

and with --process-html:

<div>This is <em>not</em> MultiMarkdown</div>

<div>This <em>is</em> MultiMarkdown</div>

However, the results may be different than anticipated when outputting to LaTeX or other formats. Normally, block level HTML will be ignored when outputting to LaTeX. The example above would produce the following, leaving out the first <div> entirely:

This \emph{is} MultiMarkdown

And this with --process-html:

This is \emph{not} MultiMarkdown
This \emph{is} MultiMarkdown

You will also notice that the line breaks are different when outputting to LaTeX, and this can cause the contents of two <div> tags to be placed into a single paragraph.