Scientific papers are mostly written in LaTeX, a markup language for typesetting. With LaTeX, a document is programmed rather than edited in a WYSIWYG-way. There is a great deal of specialized editors or editor modes (e.g. AucTeX) simplifying the creation of LaTeX documents. In many cases, however, you just want to quickly write down what’s in your head instead of getting stuck in the details of LaTeX markup. I found that Emacs org-mode is very well suited to fill that gap. You can efficiently draft a scientific document that can directly be converted into LaTeX code which you can beautify later on. I’ll show you here how.

Installation

First, you have to install org-mode for Emacs as described here. Org-mode is included in Emacs since version 22.1 and the latest version can be obtained from the a git repository via

git clone git://repo.or.cz/org-mode.git

Be sure to use the latest version for this tutorial as there really is some active development going on and some of the features I use were included just recently.

The First Document

Begin by opening a new files with a “.org” extension. Paste the following lines into that document

The Impact of Beer Consumption on Scientific Collaboration
#+AUTHOR: Mario Fasold
* Introduction
** Previous Work
Some studies relating scientific output and beer have previously been done.
#+BEGIN_QUOTE
In Europe, most alcohol is consumed as beer and, based on well known negative effects of alcohol consumption on cognitive performance, I predicted negative correlations between beer consumption and several measures of scientific performance.
#+END_QUOTE
([[www.zoologie.upol.cz/osoby/Grim/Grim_Oikos_2008_on-line.pdf]])
* Results
** What beer should you drink
+ Becks
+ Czech Budweiser
+ Duff

The first line contains the title of your document. It will be used by each of the exporters, e.g. LaTeX or HTML. Note that there was a bug in the latex exporter, leading to duplicated text after the table-of-contents if the first line of the document was a headline. Leaving the fist line empty is the suggested workaround here.

The export can be controlled by various parameters that can be set anywhere in the org-document. The syntax is “#+OPTIONS: toc:nil”, for example (available options). Some export options that might be useful to create a paper draft include

#+AUTHOR: the author (default taken from user-full-name)

#+DATE: A date, fixed, of a format string for format-time-string

#+EMAIL: his/her email address (default from user-mail-address)

Using the very simple org-mode markup, the document then defines some sections, subsections, textblocks and formulas. Note that only the first three outline levels (* – ***) are used for headlines by default. Using the markup you can easily define lists, include other files, enter footnotes, define literal and source code blocks (and even use Emacs font-lock for those areas) and more. For example, a text literal is inserted via

#+BEGIN_EXAMPLE
Some example from a text file.
#+END_EXAMPLE

and the following passes code directly into latex

#+BEGIN_LaTeX
All lines between these markers are exported literally
#+END_LaTeX

Another honored mention be the org-tables mode which lets you create and edit and tables in a dead-easy manner (try to swap a table column in AucTeX…).

Figures

Papers and their drafts can’t live without images in most cases. The following syntax allows since december to insert one

It’s a little buggy still, for example, no underscores seem to be allowed within filenames for now. For more complex cases, you can just write the LaTeX-code (org-mode will recognize many identifiers):

You may also want to include references while drafting the paper. Luckily, you can use RefTex-Mode (included in Emacs) to scan your BibTeX-file (containing the bibliographies) and easily insert a reference to an entry of that file. First, activate RefTex in org-mode by inserting the following lines into .emacs:

at the end of your org-document. When you want to insert the reference just invoke “C-c )”, enter a search term (e.g. auther name) and select the right one from the search results. Note: When first opening the org document, RefTeX will ask you to give him the name of the “master” which is the .tex-file corresponding to your org-file.

You can also use org-mode to collect notes about all the publications you are reading. Stick to this description to find out how you could manage bibliographies and PDF-documents in a nice way.

Outlook

Org-mode is a very versatile and extensible mode for Emacs. If Emacs is considered an Operating System, consider Org-mode as the Emacs for that system! I find org-mode particularly handy to draft papers. Include images, formulas, tables and references with ease, without the hassle of dealing with LaTeX markup.

Additionaly, you might use org-mode to organize related links, documents and data. With org-R you can even do any computations (e.g.statistics) and plots in-line using R – no need to fragment your information! Also, expect to see nice features appearing for org-mode frequently. I would be glad to hear how you use org-mode to collect information and do science!

Ps. Someone even wrote his complete diploma thesis with org-mode. He describes his experience here (his org-file is a good example, too).

24 Responses to “Using Emacs Org-mode to Draft Papers”

I use org-mode for writing papers and my master’s thesis, haven’t used reftex-mode much yet, but it looks very useful. I do use bib-cite-minor-mode though, which works very well in org-mode (when \cite{foo} is selected, the minibuffer shows citation info).

Two questions:
- why use load-library instead of just (reftex-mode t)?
- why redefine the key of reftex-reference (`C-c )’) to
reftex-citation, which is already bound to `C-c [’ ?

I’ using load-library instead of (reftex-mode t) (or (turn-on-reftex)) as i don’t really want to activate the reftex minor mode within org-mode. Doing so, would overwrite various keybindings of org-mode, for example C-c ]. Which also answers your second question: C-c ] is already bound to org-remove-file but C-c ) isn’t.

So what i essentially do is to enable the reftex-citation function in org-mode, while you activate the reftex minor mode. Hence i there is no need for the little hack for me. However, I would say it’s a matter of taste which version to use.

Works like a charm! I’m getting tired of keeping my notes in org-mode, then going and composing a separate LaTeX document to summarize my findings. I think I’m going to use this for the bulk of writing my dissertation.

Hello, could you just show what’s the Org source with some citations? I can’t get this working. Failing with messages such as “tex-main-file: Wrong type argument: stringp, nil” while everything should be there, as described here and in the link to “this description”. BTW, Emacs never asks me about the master file. Maybe that’s the clue, but…???

The code for using the BibTeX bibliography is shown in the blog post and inserting a reference via C-c ) produces something like “\cite{Fasold2010}”. Unfortunately, I cannot see what might lead the error you are having. But you are right, as long as Emacs does not ask for the TeX Master, the org-mode hook is not working correctly. Check if oy see “Loading reftex…done” in your messages buffer.
And if problems persist, you might want to consider one of the alternative approaches described here.

[...] followed a few guides on how other people used org-mode and reftex to do so. Specifically this post, and this email. My hope with this initial post is to pull the bits together, show what I built on [...]

[...] a cite{Key} LaTeX command instead of an org-mode command [[cite][key]]. However, by adapting Mario’s code for RefTeX integration with Org, I came up with this simple piece of elisp that fixes this issue [...]

Mario; excellent blog. I want to get the same functionality working, but am stuck.
I’ve only just discovered org-mode in the last few weeks and am now drafting my first paper using org-mode and the export to tex feature, but I can’t get this org-mode reftex integration to work. I have a similar problem to Fabrice.
reftex is working fine in tex mode, I have the following in my .emacs

I’ve tried exporting to latex then re-opening the .org file but I still get the same error. I’ve tried all the different variants mentioned in the links but always end up with the same error. Has anyone any ideas what’s going on? Can anyone help?

I was doing some more poking around last night (I really want this to work) and I have a workaround. But I don’t think it’s normal behaviour.

When I first open the org file I get the
File mode specification error: (wrong-type-argument stringp nil)
error and “C-c )” is described as undefined. If I then export to latex “C-c C-e l”, I can then use the reftex functionality within the org file. Excellent.

But if I close down the org file and reopen the C-c ) fails again until I re-export to latex.

So I can get the functionality but I feel this is not correct behaviour.

Interesting, for me it works under different tested emacs versions. My first guess is that this problem is related in the way you instantiate org-mode. I run the follwing lines in my .emacs before defining the hook

I have the same, except for the first line. I don’t have that directory and when I try and > locate “org-mode/lisp” I get no hits. I’ve tried the same setup on my laptop (ubuntu) as opposed to my work machine (fedora ) and I get the same problem. Stange.

Not to worry, I’m happy enough cause I can just refresh the .tex file and all is good. Often my emacs session will stay open for days anyway.

Marios Braindump » Using Emacs Org-mode to Draft Papers I was suggested this blog by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my trouble. You’re amazing! Thanks! your article about Marios Braindump » Using Emacs Org-mode to Draft PapersBest Regards Yoder