## Thursday, 12 February 2015

### Scrivener + Mendeley + LaTeX and references

There is a comment under my PhD Tools blog post asking about the workflow and using a reference manager with Scrivener. As I said in the comments, as far as I’m aware there isn’t a good and easy solution to that, although some workarounds have been suggested (I’ll try to find them and post links).

First, if you don’t know how LaTeX deals with references, it’s fairy simple. I store my references in Mendeley, assigning a unique cite-key to each paper. The library can be exported as .bib file, which will be automatically updated every time you add a new reference in Mendeley (it’s a one time setup, which is great). Imagine you have a paper written by Smith et al. in 2005. My cite-key for that reference would be Smith_etal2005. I tell LaTeX where it can find the .bib file (I give it the path to that file), so that it can access all the data.

When I write in LaTeX and want to cite this particular paper I use the cite-key Smith_etal2005 and a bit of code that tells LaTeX that this is a reference - it would look like \citep{Smith_etal2005}. LaTeX then goes to the .bib library, pulls out the full reference and sticks it in the “References” section at the end of the document. In the body of the text itself the reference is output as it should be i.e. "some text about the thing (Smith et al., 2005)”.

The beauty of this is that if I were to remove the reference from the body of the text LaTeX will automatically remove it from the reference list at the end. It saves me worrying about having references in text, but not in the reference list and vice versa. I really like it and plan on keeping using LaTeX and Mendeley combo to format and output my documents, likely including the thesis.

Now I am adding Scrivener to the mix. Scrivener will be used mainly for note-taking, early drafts, re-drafting, reverse outlining etc. Anything that doesn’t need to be formatted and look pretty will be done in Scrivener, saving me dealing with the majority of LaTeX syntax in everyday life and formatting once the text is ready to be seen by the outside world. Having said that I don’t want to wait with inputting all reference till the last minute, it’s just so much more efficient to deal with them as you go!

There are two options here.

(1) I can input references in the-LaTeX-way, as I go, just like I would have done if I were writing in LaTeX itself (i.e. use the \citep{Smith_etal2005} in Scrivener). Then, I can simply export (or even copy-and-paste) that document from Scrivener to LaTeX for outputting, compile it and voila! references are sorted.

(2) Alternatively, I could set up Scrivener with Multimarkdown (which is a syntax that allows you to write in plain text and then convert to a more complex format e.g. HTML), write using MMD to keep it simple and avoid having to put LaTeX-like bits of code in (the \citep{} in this case). It is then possible to export from Scrivener to LaTeX through MMD; all MMD specific syntax will be changed to LaTeX specific syntax.

I feel like after the initial set up the second option i.e. using MMD would be cleaner. But then again, I don’t really have issues with using LaTeX-style citation syntax, so that’s what I have stuck with for now, as I only needed to write fairly short pieces of text. For anything of a length greater than 5000-6000 words it might well be worth spending a couple of hours sorting MMD out and getting used to it*.

If you are interested in learning more about any of the above, check out the links below. If that’s not enough - google! There seems to be dozens of tutorials on those things out there already, hence my post is rather simple, no need to re-invent the wheel.

BibDesk, Multimarkdow, Scrivener (those are way more detailed than this blog post too):
http://timbrandes.com/blog/2012/02/28/howto-write-your-thesis-in-latex-using-scrivener-2-multimarkdown-3-and-bibdesk/
http://timbrandes.com/blog/2014/04/08/optimize-bibdesk-multimarkdown-and-scrivener-for-a-nice-scientific-bibliography-and-citation-workflow/

Some good posts on having words too: https://onhavingwords.wordpress.com/2013/03/19/scrivener-multimarkdown-latex/
Using LaTeX code in Scrivener: https://onhavingwords.wordpress.com/2013/07/27/any-latex-scrivener/
Also replacements, if you are really into it all now! https://onhavingwords.wordpress.com/2013/10/06/replacements-latex-scrivener/

On Multimarkdown, from its creator: http://fletcher.github.io/peg-multimarkdown/mmd-manual.pdf

*but it’s not just because of the references, it’s because of the heading, subheading and other bits and pieces.

1. One thing I'll mention with copy/paste from Scrivener to LaTeX is depending on your version, sometimes things like apostrophes are dropped for some reason. Definitely something to keep an eye out for if you go down that route.

1. Thanks, that's good to know! I'm assuming that can be circumvented by using the MMD route, do you know?