MultiMarkdown

How do I use MultiMarkdown?

There are several ways to use MultiMarkdown, depending on your needs. You can use the multimarkdown command line tool, you can use MultiMarkdown with several applications that support it directly, or you can use a drag and drop approach.

Command Line Usage

First, verify that you have properly installed MultiMarkdown:

multimarkdown --v

If you don’t see a message telling you which version of MultiMarkdown is installed, check out Troubleshooting.

To learn more about the command line options to multimarkdown:

multimarkdown --h

Once you have properly installed MultiMarkdown:

multimarkdown file.txt

will convert the plain text file file.txt into XHTML output. To save the results to a file:

multimarkdown file.txt > file.html

A shortcut to this is to use MultiMarkdown’s batch mode, which will save the output to the same base filename that is input, with the extension .html (or .tex for LaTeX output):

multimarkdown -b file.txt

A benefit of batch mode is that you can process multiple files at once:

multimarkdown -b file1.txt file2.txt file3.txt

If you want to create LaTeX output instead of XHTML:

multimarkdown -t latex file.txt

For OPML (not implemented in v6 yet):

multimarkdown -t opml file.txt

For a regular OpenDocument text file:

multimarkdown -t odf file.txt

And for a Flat OpenDocument text file:

multimarkdown -t fodt file.txt

There are also several convenience scripts included with MultiMarkdown:

mmd file.txt
mmd2tex file.txt
mmd2opml file.txt
mmd2odf file.txt

These scripts run MultiMarkdown in batch mode to generate XHTML, LaTeX, OPML, or ODF files respectively. These scripts are included with the Mac or Windows installers, and are available for *nix in the scripts directory in the source project. They are intended to be used as shortcuts for the most common command line options.

Command Line Options

There are several options when running MultiMarkdown from the command line.

multimarkdown -c, multimarkdown --compatibility

Compatibility mode causes MultiMarkdown to output XHTML that is compatible with that output from the original Markdown. This allows it to pass the original Markdown test suite. Syntax features that don’t exist in regular Markdown will still be output using the regular MultiMarkdown output formatting.

multimarkdown -e "metakey", multimarkdown --extract "metakey"

The extract feature outputs the value of the specified metadata key. This is used in my convenience scripts to help choose the proper LaTeX output mode, and could be used in other circumstances as well.

multimarkdown -t html|latex|memoir|beamer|opml|odf

This option specifies the format that MultiMarkdown outputs. The default is html. If you use the LaTeX Mode metadata, then MultiMarkdown will automatically choose memoir or beamer as directed without using these command line options. Using that metadata will also allow the various convenience scripts to choose the correct output format as well.

Other options are available by checking out multimarkdown --h, but the ones listed above are the primary options.

TODO: need to describe more options

Advanced Mode

MultiMarkdown version 2.0 had to first convert the source file to XHTML, and then applied XSLT files to convert to the final LaTeX format. Since MultiMarkdown 3.0 can create LaTeX directly, this approach is no longer necessary.

The one benefit of that approach, however, was that it became possible to perform a wide range of customizations on exactly how the LaTeX output was created by customizing the XSLT files.

If you install the Support files on Mac or Linux, you can still use the advanced XSLT method to generate LaTeX output. For the time being, this approach doesn’t work with Windows, but it would be fairly easy to create a batch script or perl script to implement this feature on Windows.

Keep in mind, however, that because of the more advanced mechanism of handling LaTeX in MultiMarkdown 3.0, you can do a great deal of customization without needing to use an XSLT file.

The mmd2xslt script will convert a plain text file into LaTeX that is virtually identical with that created by the regular LaTeX approach.

There are a few differences in the two approaches, however:

  • Once a MultiMarkdown file is converted to XHTML, it is impossible to tell whether the resulting HTML was generated by MultiMarkdown, or if it was included as raw XHTML within the source document. So either way, it will be converted to the analagous LaTeX syntax. The multimarkdown binary on its own will not convert XHTML into LaTeX.

  • The whitespace that is generated will be different under certain circumstances. Typically, this will result in one extra or one fewer blank lines with the the XSLT approach. Generally this will not be an issue, but when used with it may cause a newline to be lost.

  • The default XSLT recognizes class="noxslt" when applied to XHTML entities, and will discard them from the output.

  • An XSLT can only be applied to a complete XHTML document, not a “snippet”. Therefore, if you want to use the XSLT method, your file must have metadata that triggers a complete document (i.e. any metadata except “quotes language” or “base header level”).

Recommendations

I recommend that you become familiar with the “basic” approach to using MultiMarkdown before trying to experiment with XSLT. The basic approach is faster, and easier, and the results can still be customized quite a bit.

Then you can experiment with modifying XSLT to further customize your output as needed.

If you have XSLT files that you used in MultiMarkdown 2.0, you will likely need to modify them to recognize the XHTML output generated by MultiMarkdown 3.0. You can use the default XSLT files as a guide to what is different.

Mac OS X Applications

There are several applications that have built-in support for MultiMarkdown, or that can easily use it with a plug-in.

Using MultiMarkdown with TextMate

If you want to run MultiMarkdown from directly within TextMate, you should install my MultiMarkdown bundle. This is a modified version of the original Markdown bundle for TextMate that includes better support for MultiMarkdown.

This bundle will work with MultiMarkdown 2.0, or with MultiMarkdown 3.0 if you install the MultiMarkdown-Support files (available from the downloads page).

Using MultiMarkdown with Scrivener

Scrivener is a great program for writers using Mac OS X. It includes built in support for MultiMarkdown. If you want to use MultiMarkdown 3.0 with Scrivener, you need to install the Support files in ~/Library/Application Support/MultiMarkdown. The MultiMarkdown-Support installer is available from the downloads page and will install these files for you.

Drag and Drop

You can use the Mac OS X drag and drop applications to allow you to convert MultiMarkdown to other formats by dragging and dropping files in the Finder. They are available from the downloads page, or by running make drop from the command line in the multimarkdown source directory.

MultiMarkdown and Finder “Quick Look”

Starting in Mac OS 10.5, the Finder has the ability to show a “QuickLook” preview of the contents of a file. I have two QuickLook generators that allow the finder to preview the contents of a MultiMarkdown text file as an XHTML preview. One works on plain text files, and one works on OPML files.

NOTE: There is an open source version of the QL generator here, but the closed source one is better.

Using MultiMarkdown in Windows

You can use the same command line approach with Windows as described previously. While there aren’t drag and drop applications per se for the Windows system, you can use Windows Explorer to create links to the binary and specify and desired command line options to change the default output format. This will effectively allow you to create drag and drop applications for Windows.

MultiMarkdown and LaTeX

Of note LaTeX is a complex set of programs. MultiMarkdown doesn’t include LaTeX in the installer — it’s up to the user to install a working LaTeX setup on their machine if you want to use it.

What MultiMarkdown does is make it easier to generate documents using the LaTeX syntax. It should handle 80% of the documents that 80% of MultiMarkdown need. It doesn’t handle all circumstances, and sometimes you will need to hand code your LaTeX yourself.

In those cases you have a few options. MultiMarkdown will pass text included in XHTML comments along to the LaTeX as raw output. For example:


You can also include your desired LaTeX code in a separate file and link to it:


If you have questions about LaTeX itself, I can’t help. You’re welcome to send your question to the MultiMarkdown Discussion List, and perhaps someone will be able to offer some assistance. But you would be better off asking a group dedicated to LaTeX instead.

If the problem is that MultiMarkdown itself is generating invalid LaTeX, then of course I want to know about it so I can fix it.

MultiMarkdown and OPML

MultiMarkdown is well suited to plain text files, but it can also be useful to work on MultiMarkdown documents in an outliner or mind-mapping application. For this, it is easy to convert back and forth between OPML and plain text MultiMarkdown.

To convert from a text file to OPML:

multimarkdown -t opml -b file.txt

or:

mmd2opml file.txt

The resulting OPML file uses the headings to build the outline structure, and puts the text within each section as a not for the corresponding level of the outline using the _note attribute. NOTE: not all outliners support this attribute. On Mac OS X, OmniOutliner is a fabulous outliner that supports this field. If you’re into mind mapping software, iThoughts works on the iPad/iPhone and supports import and export with OPML and the _note attribute.

To convert from OPML, you can use various commands in from the MMD-Support package:

opml2XHTML file.opml
opml2mmd file.opml
opml2LaTeX file.opml

NOTE: These scripts require a working installation of xsltproc, and the ability to run shell scripts. This should work by default on most installations of Mac OS X or Linux, but will require these applications to be installed separately on Windows.

MultiMarkdown and OpenDocument

It is also possible to convert a MultiMarkdown text file into a word processing document for OpenOffice.org or LibreOffice. This file can then be converted by one of those applications into RTF, or a Microsoft Word document, or many other file formats. (If you’re not familiar with these applications, they are worth checking out. I don’t understand why people use Microsoft Office any more…)

multimarkdown -b -t odf file.txt

or

mmd2odf file.txt

MultiMarkdown 2.0 had partial support for outputting an RTF file, and could do it completely on Mac OS X by using Apple’s textutil program. MMD 3 no longer directly supports RTF as an output format, but the Flat OpenDocument format is a much better option.

NOTE: LibreOffice can open these Flat OpenDocument files by default, but OpenOffice requires that you install the OpenDocument-Text-Flat-XML.jar file available from the downloads page. To install it, create a new document in LibreOffice (or open an existing one), then go to the Tools->XML Filter Settings menu option. Use the “Open Package…” button to import the downloaded .jar file.

(BTW - if you “customized” your version of LibreOffice to remove features, don’t be surprised if this doesn’t work, and try following the OpenOffice instructions.)

Advanced Use

It is possible to use an XSLT file to customize the OpenDocument output from MultiMarkdown. I suppose you could also write an XSLT to convert OpenDocument into LaTeX, similar to the default ones that convert XHTML into LaTeX.

You can also create an XSLT that converts the OpenDocument output and modifies it to incorporate necessary customizations. While a little tricky to learn, XSLT files can be quite powerful and you’re limited only by your imagination.

Limitations

There are several limitations to the OpenDocument format:

  • images are not fully supported — they work best if you specify a length and a width in “fixed” units (not ‘%’), or do not specify any dimensions.

  • citations are not supported — I would like to be able to do something here, but I suspect you will need to use an external tool for the time being

  • math features are not supported, though I hope to be able to implement this at some point in the future