Usefull
- 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 fletcherpenny.com
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
\documentclass[a4paper,11pt]{book}
\begin{document}
\input{yourdocument}
%%% ------------ bibliography ------------------------
\newpage
%\bibliographystyle{plain}
\bibliography{yourbibtexfile}
\end{document}
The latter enables that you don’t have to change any files to have a full texable document without eny editing.
Steps:
*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:
#Heading1
##Heading2
###Heading3
…
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:
[code]C:
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
ECHO “%CD%”
rem for debugging purpose
perl mmd2LaTeX.pl D:\fullpathtoyourdocument\document.txt
rem run mmd2LaTeX on the file you want to parse
PAUSE
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(f.read(), 'cp1252')
f.close()
f= open(path2, 'wb')
f.write(content.encode('utf-8'))
f.close()
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:
D:
rem change to drive
CD D:pathcontainingyourfile
rem change to directory
ECHO "%CD%"
rem for debugging purpos
python D:\pathtopythonscript\change_encoding.py
rem run script
I hope this is of use to any of you.
Cheers,
Markus