Using Emacs Org-mode to Draft Papers
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
#+CAPTION: Degradation Plot
#+ATTR_LaTeX: scale=0.75
#+LABEL: fig:degradation
[[./images/DegradationPlot.png]]
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):
\begin{figure}[!tpb]
\centerline{
\includegraphics[scale=0.3]{images/BeerPlot}
}\caption{This is plot looks like a beer.}\label{fig:Beer}
\end{figure}
References
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:
(defun org-mode-reftex-setup ()
(load-library "reftex")
(and (buffer-file-name)
(file-exists-p (buffer-file-name))
(reftex-parse-all))
(define-key org-mode-map (kbd "C-c )") 'reftex-citation)
)
(add-hook 'org-mode-hook 'org-mode-reftex-setup)
Second, include the BibTeX-file by inserting
\bibliographystyle{plain}
\bibliography{ProbePosition}
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).
Tags:emacs english science | Filed on February 26th, 2009 | 6 Comments »
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 [’ ?
By the way, since I open a lot of org-agenda-files on emacs startup and don’t want those complicated LaTeX-modes in all of them, I use the following little hack:
(add-hook ‘org-mode-hook
(lambda ()
(if (member “WRITE” org-todo-keywords-1)
(org-mode-article-modes))))
where
(defun org-mode-article-modes ()
(reftex-mode t)
(bib-cite-minor-mode t)
(and (buffer-file-name)
(file-exists-p (buffer-file-name))
(reftex-parse-all)))
org-todo-keywords-1 is the buffer-local list of todo-keywords, so only files with “WRITE” as a todo-keyword get article modes.
Hi Kevin,
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.
Ps. Sorry for the late response but i migrated the webserver today.
[...] fancy plot? But chill, there is a way to avoid the joyless seeking and re-finding. At least if you draft your papers in org-mode, as i described in a recent [...]
[...] http://www.mfasold.net/blog/2009/02/using-emacs-org-mode-to-draft-papers/ a few seconds ago from xmpp [...]
Het there, I think you’ll call me god when you’ll see this create a free flash website