An Approach to Exporting MMD to LaTex


  • Yes
  • No

0 voters

Dear Scriveners,

since I want to have finished my project before the release of scrivener 1.0 I tried to find solutions to export from scrivener Windows to LaTeX. This might also work for other formats but I did not test this. Since some others might want do do the same I want to share this dirty hack. If it is of no interest I’ll of course stop it.

I want to edit this post every time I find better solutions or additional information. So if some of the admins feels like, please make it sticky.

The Problem:

Scrivener Beta can not export to Latex via MMD yet.

Solution: Scrivener is able to export plain text and therefore Multimarkdown

How: since scrivener will of course not export any MMD itself one has to use the complete set of MMD commands to produce the output.

Document setup:

To be able to use MMD there has to be a first Document in the Draft Folder that carries the metadata (In standard scrivener these data is set in the document properties). So it should look like:

Title: Yourtitel
Author: The Author
LaTeX XSLT:latex-snippet

Of course you can put any valid MMD Meta Data as described at

Two things are important:
No blank lines infront of the metadata
The line defining XSLT Template. Without that line the output of MMD2latex will produce a whole latex document using the memoir style. If you want to use a different style etc you have to change the output texfile by hand every time you export from scrivener. The latex-snippet template generates the latex code starting right after \begin{document} until /end{document}. You can include this via \input or \include into a main document where all the definitions of your document like style, bibtec file/ style, macros are placed.

Example master document



%%% ------------ bibliography ------------------------


The latter enables that you don’t have to change any files to have a full texable document without eny editing.

*Create e.g. yourdocument_main.tex “Master File”.
*Compile your document to plain text from scrivener to yourdocument.tex
*Include your document yourdocument.tex into the Master file

Document Structure:

Since scrivener whill not export your documents structure at all in plain text you have to define the structure within scrivener using mmd. To do this I put just the heading into every “node-document” using mmd syntax like:




Time Savers:

Since I do compile the document quite often I use a windows batch file to enable generating a .tex file by doubleclick on the batchfile which I place in the directory where the .txt is exported to. It is really simple but works:

rem changes to the drive mmd is placed since it can not be run from different locations
CD \Programme\Multimarkdown\bin
rem cd to location of mmd script. change path to your need
rem for debugging purpose
perl D:\fullpathtoyourdocument\document.txt
rem run mmd2LaTeX on the file you want to parse

rem let me see the output[/code]

Problems and dirty hacks:

As far as I see Scrivener exports cp1525 instead of utf-8. I asked for an option to change this behaviour but this of course is a minor important feature and might be useless as soon as MMD Export works. So if you export e.g. french or german text using non ascii letters like ä,ö,ü,ß, > mmd can not parse the file. What I do is use a small python script to change the encoding which is really dirty because you need both, python and perl on your computer:

# python
path='input.txt' 	#input file name
path2='output.txt' 	#output file name

f= open(path, 'rb') 
content= unicode(, 'cp1252') 
f= open(path2, 'wb') 

I want to replace this with a perl script (also not nice since it looks like you have to use additional perl moduls) or better the iconv.dll (I don’t know how to use it yet)

Just start this python script located in the directory, where your text is placed in the beginning of your batch file by adding:

rem change to drive
CD D:pathcontainingyourfile
rem change to directory
rem for debugging purpos
python D:\pathtopythonscript\
rem run script

I hope this is of use to any of you.



Great tips (and nice screen name too; love that film).

Little update about the character encoding hack:
the usage of iconv.dll seems to be quite complicated (must be integrated into a program). So I stick with the python script and might recode it in perl someday.

I will not put additional effort in the character encoding thing since Lee assigned UTF8 export will be addressed.

Best Regards,