Scrivener to LaTeX - help with customising.

I am developing a work flow for a Scrivener -> LaTeX environment, using Textmate for tweaking and PDF conversion, and BibDesk as my bibliography software. I’ve spent the past few weeks honing my LaTeX skills in Texmate to the point where I’m happily generating typeset documents for my moderate needs (a couple of varieties of scientific papers with footnotes, figures, citations and bibliographies).

I’m now back at the Scrivener end, playing with some of the compilation options, trying to figure out the best way to arrive at something similar to the LaTeX template I’ve developed in Textmate.

I’ve played with some of the metadata options at the output stage, and have my outline set up to reflect my section and sub section requirements, but I’m stuck at the point where I need to specify some packages and other refinements. In essence, I think I’m at the stage where I need to be dabbling in XSLT.

I’d be grateful for any insights (aimed squarely at the beginner). I’m no Perl programmer, and although I can see some things in the XSLT files that make sense, there is a whole lot of style sheet mumbo jumbo that I really can’t be bothered with.

Perhaps I don’t need to be playing with XSLT at all? All I really want to do is get my text out of scrivener, and into a LaTeX document with my packages at the top, and my bibliography down the bottom (at least to start with). If necessary, I can copy and paste chunks of text, but it seems worth trying to master at least some of the compile options available in Scrivener for LaTeX.

Any advice gratefully received.

Paul

What I do is create a ‘container’ LaTeX document with the following:

  • preamble: documentclass, packages, options
  • an include statement
  • call the bibliography

In Scrivener’s Compile->MMD-LaTeX->Metadata, I set ‘LaTeX XSLT’ to ‘latex-snippet’. This compiles to a LaTeX file that contains only the actual content of the draft. This file is included in the container document.

Claudine
(long term LaTeX and Scrivener user, forum newbie)

Thanks Claudine - that’s a brilliant idea!

Can I ask you, what is the correct format for the include statement?

Also, I am trying to format section headings without auto-numbering, and with the addition of a TOC pointer, eg:

\subsection*{Background}
\addcontentsline{toc}{subsection}{Background}

I notice that there is a checkbox in the Scrivener compiler labelled “Disable auto-numbering”, however it doesn’t appear to do the above (ie, add the * character).

I guess I can just do a search and replace (or some grep) in Textmate, but I’m keen to exploit all that the Scrivener / MMD system has to offer.

Thanks again,

Paul

Glad to help! The include statement is just:

\include{filename}

The .tex extension in the filename is optional.

I haven’t tried disabling auto-numbering so can’t help with that I’m afraid.

Claudine

I’m interested in doing this as well when I use Journal-provided templates in Latex. Since the Journal provides the Latex shell, I would add the \input command to insert my tex-snippet files from Scrivener…except I can’t quite follow your instructions Claudine…

when ready to compile:

File>Compile and new window appears, and select MMD->Latex (bottom right of new pull down)…then I got lost…

Where exactly is the Metadata and latex-snippet option?

thanks in advance Ann
Scrivener 2.0.4
to Textmate 1.5.10

When you select one of the MultiMarkdown compilation formats, ‘Meta-Data’ will appear under the Compiliation Options on the left hand side of the Compile dialogue. In the Meta-Data section, click on the + sign on the bottom right, then add ‘LaTeX XSLT’ under ‘Key’ and ‘latex-snippet’ in the empty text box underneath.

Are we allowed to post screenshots on this forum? Or links to screenshots?

Same here!

Maybe not… MMD3 (which is in development and nearing beta release) is moving away from XSLT for its LaTeX output, and adopting a scheme which is much more direct, and much more understandable for people who already are familiar with LaTeX.

For example, the release includes a modular .tex file which includes a default package setup:

%
%	Default packages for memoir documents created by MultiMarkdown
%

\usepackage{fancyvrb}			% Allow \verbatim et al. in footnotes
\usepackage{graphicx}			% To enable including graphics in pdf's
\usepackage{booktabs}			% Better tables
\usepackage{tabulary}			% Support longer table cells
\usepackage[utf8]{inputenc}		% For UTF-8 support
\usepackage[T1]{fontenc}		% Use T1 font encoding for accented characters
\usepackage{xcolor}				% Allow for color (annotations)
\usepackage[sort&compress]{natbib} % Better bibliography support

\VerbatimFootnotes

This file can be edited by the user to implement their own favorite package setup.

If this is all you want, MMD3 will give you all of that with no need to parse a single line of XSLT.

That said, MMD3 will still retain a version of XSLT support for LaTeX translation, but it seems to me after playing with it for a while, that LaTeX users will prefer the new scheme, and be able to get most of what they want within a much more LaTeX-familiar environment.

Citation support is good in one sense, but very simple in another. MMD3 uses natbib by default, and the standard [#citekey] MMD syntax is translated into \citep{citekey}. There is no \citep{} vs \citet{} distinction currently implemented. Raw LaTeX can be included in the Scrivener document like this:

 <!--\citet{citekey}--> 

Which means you are actually marking-up the mark-up in your markdown (though BibDesk for example can be made to use this syntax automatically when you drag references to Scrivener). Forewarned is forearmed…

WARNING: MMD3 is still at a developmental stage. Files and documentation are distributed throughout a github repository, and there is a learning curve involved. But for me, it seemed more efficient to get to grips with the new implementation via github, than get to grips with XSLT, which is being backgrounded in the future of MMD->LaTeX in any case.

WARNING: Implementation of MMD3 requires replacement of your ~/Library/Application Support/MultiMarkdown folder with the new implementation. If you want to experiment with it, rename your old MultiMarkdown folder something like MultiMarkdown.ORI or MultiMarkdown.2, so you can get it back if you don’t like what you see.

If you are still interested (!), MMD3 lives at:

github.com/fletcher/peg-multima … evelopment

Basic documentation (which includes installation information — there are Mac and Windows installers available) can be found here:

github.com/fletcher/peg-multima … E.markdown

The LaTeX support files are located here (requires use of ‘git clone…’ command and some knowledge of your LaTeX file structure):

github.com/fletcher/peg-multima … ex-support

and the relevant documentation here:

github.com/fletcher/peg-multima … /README.md

Aieee! Have fun… I’m happy to try and help you out if you get stuck.

Cheers!
Mike

This is true, but anyone that’s going to want to impact the actual LaTeX syntax is going to need to switch on the XSLT stuff with MMD3, as there is otherwise no way to change how individual elements are output. For the document container though, the new system will be quite nice, and way faster. With the manual (about 130k words) I can go from MD to TEX in about 8 tenths of a second, a process which takes about 60 to 70 seconds using Perl and XSLT. But on that same document, there is no way I could use the new MMD3 engine for the manual, as it has about 500 lines of custom XSLT code modifying how the LaTeX is output, supporting custom typesetting like the tip boxes, handling dynamic figure insertion based on platform and document dimensions, custom menu directives, etc.

Another limitation, for Scrivener users, is coloured annotations. If you wish for these to come through as coloured text in the PDF, you’ll need to stick with XSLT as well, because the new system goes straight to LaTeX with no HTML run-around; that means the spans that Scrivener uses will break. This also holds true for any raw LaTeX commands inserted into Scrivener wrapped in HTML comments.

Otherwise, if you have a straight-forward vanilla MMD document and all you need to change is the document class and other preamble stuff, MMD3 is pretty close (or at) release candidate, so it should be safe to dip in.

Thanks all - lots of valuable info here which I will be dipping back into over the coming weeks.

Using latex-snippet.xslt for the time being has solved most of my problems, and particularly as I’m currently writing a paper which requires use of a publisher’s LaTeX template.

I’m also using BibDesk’s drag and drop with \citep at the moment, and everything seems to become coming out right at the other end. Very nice in fact.

MMD3 does indeed appear to solve most of the basic ‘issues’ for LaTeX users who aren’t programmers, so I’m keen to take a look at it in the coming months. Thanks for the heads up, tips and forewarnings from all.

Paul