Managing papers with Org-Mode and Reftex

Writing papers means reading lots of papers, and I often lose track of all the papers I am reading: Where did I file a certain paper? Which paper did I start reading? Which paper might be interesting?

A reading list would be nice, but such a list should be easy to handle. I have all my papers catalogued in JabRef and use AucTex and RefTex for writing and Org-Mode for my tasks.The solution should therefore combine the strength of all three. I found a nice post on how to this ( and adopted it to my needs.

Here is how my solution looks like (for managing tasks with Org-Mode see one of my previous posts)


  1. For every paper I am writing I have an org-file with my tasks, reading list, notes, and calls.
  2. I have four lists for my reading:
    1. Actual reading
    2. Should read: papers I glanced through and that look promising
    3. Not yet read: lower priority papers to be read
    4. Already read
  3. I insert new papers by using C-c ) (as in LaTeX/AucTex/RefTex). More on that later. Automatically, a link to this paper and the title are inserted (I save all papers as pdf-file and named with the first author name and the year of publication. They are all saved in the same dropbox directory). With “C-c C-c” I can tag the entries for easy searching later on.
  4. If I want to work on my paper, I open the org-file and, if I want to read a paper, I just click on its link and start reading.
  5. If necessary I can make short notes directly under the link.

Org-Mode makes it possible to use RefTex. For this it is necessary to put the information on where the bib-file is (third line in the next figure)


The .emacs file has to be adjusted as follows:

Note: as I can make the reading to a TODO or a MIT (most important task), it will also show up in my daily agenda and I can also start reading from here by clicking on the link:


How to generate nice nomenclatures in LaTeX

If you have to write up your model results, often you have to write down the model documentation. My colleague at work pointed me to a great package in LaTeX that can make your life easier with respect to the nomenclature used. It allows you to produce a glossary with all your variables, parameters and acronyms without much extra work. The package is called “nomencl” and here is an example of a pdf generated with LaTeX:


As you can see, I have acronyms, parameters and variables as well as the reference to where they are used for the first time (if you only use variables and parameters you can even refer to the equation they are used for the first time).  

Using this package is quite easy:


to print the nomenclature.

Symbols can be added in the text like follows (after the equation they appear the first time):

\nomenclature{$vw$}{ Time cost multiple for walking time}

To generate the nomenclature you have to give a specific command. In Emacs you can add the following code to your .emacs-file

When you now hit C-c C-c you can choose the option “Nomenclature” and the necessary files are generated.

If you want to have the distinction between several groups, you just add the following code in your preamble and change the second part according your preferences:

To produce an entry for paramters, you just add [P] in front of the normal entry

One last remark: The entries might not be aligned properly. For this you can add in your preamble:

and choose the width accordingly. The nomenclature entries have rather much vertical space between them. This can be changed by adding one of the following lines to your preamble:

Presentation, Article and Notes in one run using Beamer

Still using Powerpoint for your presentation? Consider using LaTeX with the Beamer package.
Tom Rutherford taught me how to build an efficient stream for a presentation or lecture:
  1. generate the presentation with beamer,
  2. generate the presentation as an article and
  3. clean up all the stuff
All this in one batch file. The presentation is projected on the big screen and the article is used for preparation and for notes, I use during my prepartation (I have a printout of the article next to my laptop during the presentation)
The batch (build.bat) file looks like this:
@echo off
pdflatex beamer
pdflatex beamer
pdflatex print
pdflatex print
del *.toc
del *.log
del *.out
del *.nav
del *.snm
del *.vrb
del *.synctex
del *.aux
cd auto
del *.*
rd auto /Q
and after finishing my slides, I just run it from my shell or my explorer.
The latex commands are run twice, so if there are citations, bibtex is run. I give a serie of lectures and for every lecture I have three files:
  1. lecture.tex:    all the slides to be presented
  2. beamer.tex:   the preamble for generating the lecture as beamer presentation
  3. print.tex:        the preamlbe for generating the lecture as article.
Beamer tex looks like this:
It gets the lecture.tex file as input and grabs the style.tex file for “styling” my presentation.
I added the following features.
Setting a directory for all my figures and for my style file:
I use import, so I can set a directory for all my figures (instead of having them in the same direcotry as my tex files). The directory is set in the lecture.tex file:

The style file resides in its own directory, so I do not have to replicate it and changes are easy done in just one file.
Comments not showing in my presentation, but in my article:
I use the package comment to add notes to my presentation. Beamer allows you to make notes, that will be shown as a parallel slide, so you can have your presentation projected and the other half on your notebook monitor (split screen). This seems to work fine on a Mac or under Linux, but is almost impossible on a Windows machine (there is ony very basis and not very satisfactorysolution called presenter-pdf). I just use the comment package that allows you to add notes that are printed in my article version of my presentation but do not show up in my beamer presentation. In beamer.tex I give the commend to not show the comments:
In print.tex I add the lines to include the comments:
A comment in the lecture.tex follows an \end{frame} command and could look like this:
In the article version, the comments are red and start with a bold “NOTES” above them, so I can concentrate on them, when I am presenting.
Size of graphics
I use the width option for included graphics, so figures also fit if the format of my paper in beamer (landscape) is changed to portrait (article). Example:  [width=0.8\textwidth].
Here you see the presentation:
And here the article format (in the right margin, you see the number of the lecture as well as the slide number).

Auto-Completion in Emacs, LaTeX and Gams

The fun with Emacs is that you can discover new (or old) stuff that makes your life much easier on an almost weekly base. I was reading the manual on Emacs Speaks Statistics and discovered that there is a mode called auto-completion. I googled it, installed it and after some experimenting, I got it running. You can find it here. It comes with autocompletion for some programming languages (Python, Ruby, C+, etc.) but not for LaTeX, so I googled further and discovered an extension called auto-complete-latex (you can download it here.
Here are some screenshots: You just start typing and it suggests a keyword or if you wait a little bit longer it gives you a dropdown llist. You can jump to the next suggestions using the tab-key.
It doesn’t matter if you use capitals or not:
and it also keeps track of words in the actual document. Here an example of my paper on parking. As you see the word “Parking appears, when I typ “par”.
For Gams there is no dictionary, so I wrote one myself and added it to the dictionaries. I only did not manage to start auto-complete for Gams automatically. But this can be done with M-x auto-complete-mode.
;; ac-modes – major modes ac can run on
(add-to-list ‘ac-modes ‘gams-mode)

;; toggle auto-complete in all buffers

(global-auto-complete-mode t)

(with thanks to a reader)
These extensions make Emacs now to a modern text editor.

Bibliography with abstracts in LaTeX

If you ever have written a scientific paper, you probably know how hard it is to remember what was in the papers you cited. Usually you cite them once and forget about them, but if you want to discuss your paper with other scientist, it would be nice to have at least an idea of what you exactly cited.
In LaTeX you have a nice way of producing a bibliography with abstracts. It is quite easy. You only have to use biblatex, an improved bibtex. Information on biblatex can be found at the CTAN repository (just google it). There are also two good articles in German from
Here is an example. Your LaTeX file looks like this, where the file jabref is my bib-file with all my citations (for which I use jabref):
The results looks like:
If you have some annotations, they also will be reproduced.

Using Gams, R and LaTeX I

Wow, I just discovered how easy it is to produce nice LaTeX tables from your Gams results. Usually I capture my model results in some parameters that are exported (using gdx or gdxxrw) to excel. Then I make my tables in Excel and use an excel add-in to export the table to LaTeX (I have written about this add-in in this blog). This works fine, but is tedious because as soon as my results are in excel, I can’t do things automatically and have to click my way to get my LaTeX tables.
Today, I was working on the parking model and wanted to automate my LaTeX tables. I already wrote on how to produce nice plots using R Statistics, but that might have been too geeky for a lot of you (“I don’t do network modelling and Excel or Gnuplot produces plots that will do…”). However, what I show you today is worth trying to start working with R if you are doing your modeling with Gams.
My workflow now looks like this:
  1. Run my model and produce some parameter with results and export the parameters to a gdx file
  2. Read the parameters from the gdx file with R using the R package (gdxrrw).
  3. Recast the data using “cast” and “mold” from the package reshape (see for an excellent introduction (
  4. Use the R package “xtable” (see to produce for each table a separate tex file.
  5. Write my paper and include the tex files with tables.
Let us have a look at the code for every step.
1. Run my model and produce some parameter with results  and export the parameters to a gdx file
Most of this is straight forward. Note that I save my gdx files in my R directory. In this directory I have my R-scripts.
2. Read the parameters from the gdx file with R using the R package (gdxrrw).
Gams Corporation is working on a R-package that allows you to transfer data from R to Gams and the other way around. The package is called gdxrrw (the “rrw” stands for R read and write)  is still work-in-progress, but you can already use it (just download it from (
When you have it installed, you can use it as follows:
The gams parameter is now a R data frame with the following structure:
3. Recast the data using “cast” and “mold” from the package reshape
I want to produce two different tables: one for the model statistisc and one for the road results. I saved all this results in one parameter, so now I have to take a subset of the results for every table.
I defined a subset “modelstatistics” and use them to subset my dataframe using %in%. This gives us the following dataframe
I want to have a table with the parameter as columns and the scenarios as rows. For this I first rename the columns and then I use the cast command:
If I combine this with the xtable command, I already have my LaTeX table:
4. Use the R package “xtable” to produce for each table a separate tex file.
Now we are almost ready: I set some options for saving the LaTeX table (table title, label and filename) and save the file using the print command on the table:
5. Write my paper and include the tex files with tables.
I jump in my paper tex file and add the following line for including the table:
and produce my LaTeX file:
In your xtable-code in the R-script you can a lot of additonal options to format your table.
The great thing is that I can do it all now without having to adjust my tables every time I run a different or addtional scenario. I just add in gams the following line to run the R-script:
And for the Emacs fans: I didn’t have to leave Emacs at all: I run my Gams model, my R code and my LaTeX from within Emacs (and for those with the good eyes: I can even clock this task…)
In a next post, I will write more on the use of cast: you can use this R command for lots of interesting stuff (building tables with the sum, mean, min, max, etc.).

Biblatex and folder contents

I was looking for a way to make nice index for my folders using LaTeX. I usually have lots of papers saved in a folder and I was looking for a way to use my paper references stored in JabRef (an open source bibliography reference manager which integrates neatly with AucTexi in Emacs, see The problem is that I want to have the title of the author, year and the title of the paper (who remembers something like Arrow 1955?), so I looked for a way to print the paper titles. BibTex and all the citation packages don’t seem to manage, but then I stumbled on bibllatex (see
On the homepage you find the following description of biblatex:
“Biblatex is a complete reimplementation of the bibliographic facilities provided by LaTeX in conjunction with BibTeX. It redesigns the way in which LaTeX interacts with BibTeX at a fairly fundamental level. With biblatex, BibTeX is only used (if it is used at all) to sort the bibliography and to generate labels. Formatting of the bibliography is entirely controlled by TeX macros (the BibTeX-based mechanism embeds some parts of formatting in the BibTeX style file. Good working knowledge in LaTeX should be sufficient to design new bibliography and citation styles; nothing related to BibTeX’s language is needed.”
Biblatex allows you to cite the title using \citetitle{bibtexkey}. Using this and, after some surfing, a little bit more LaTeX code, I managed to use LaTeX to produce something like:
Looks nice!


Compiling LaTeX files to pdf: a second try

In a previous topic, I showed how to use a macro to kill your pdf-reader when you compile LaTeX files. Most pdf-readerss do not allow to refresh a pdf-file after compilation, so you have to close the file in the pdf-reader before compiling. My solution was to kill the pdf-reader completely. A reader of my blog wrote that you can use Sumatra, a free pdf-reader, which allows to refresh your pdf-file.
I decided to give it a try, but I wanted to keep my normal pdf-reader for all other pdf-files, because it has lots of options like commenting etc. I regularly use.
Another thing that bothered me with my pdf-reader is, that I could not jump back to Emacs (inverse-searching). Sumatra has this option.
Here are my settings in Emacs:
Sumatra will not reopen if you add the option -reuse-instance:
 Do not forget to set the inverse search command in the options of Sumatra to:
     c:\program files\emacs\bin\emacsclientw.exe +%l “%f”

Template Mode for Emacs

If you write a lot of R-, Stata-, Gams and/or LaTeX-files templates can make your life more relaxed. Emacs doesn’t have a template system (well there is auto-insert, but I did not find enough information on how to use if for templates). I used to have some templates in a directory and usually I would start with them (and forget that I should save it under another name…). The disadvantage is that you have to jump around in the file to fill out the information you want to have at the top of the file (like project name, topic, file name etc.). Today I discovered templatemode (see It works like a breeze and makes my writing life much easier.
I have templates for the above mentioned file types. The Gams template looks like this:
Now if I start a new file, TemplateMode asks me if I want to use the Gams-template, it inserts all the information between >>> and <<< or asks for information to insert. For example DIR, DATE will grab the directory and the date. At the end of the template file you see pairs of words. These words define the interactive part. Templatemode asks me for the project name with Project:, the job with Job: and the Gams title with Title:.
The line with the Version Control Information grabs information from my verison control system as soon as I commit the file (and is not part of templatemode).
This is how a new Gams file would look like:
Installation is easy and you can find lots of examples in the directory.

Killing an open instance of pdf viewer when compiling latex

If there is one thing that is annoying when you us pdflatex in Emacs, it is the behavior of Adobe or another commercial product. If you haven’t closed the pdf-file, Emacs or better LaTeX will complain that the pdf-file is still open. I found some tricks in the internet, but I did not manage to implement them properly (you can for example use sumatrapdf, but I wanted to keep my original pdfreader on my computer).
Finally, I decided to use my macro/script program winautomation ( I bought this program a few months ago after getting tired of the open source program Autohotkey (which is quite good, but you have to program a lot). Winautomation is just point and click. I wrote a lot of macros that make my life much simpler. For example, I have some scripts that start my subversion backup on my servers, some scripts that open the explorer in a certain directory, a script for logging in at the university, etc.
For the problem above, I did two things: I wrote a script that checks if the pdf-viewer is open, and closes it and integrated it in an Emacs macro.
Here is the script in winautomation:
In Emacs I recorded a macro with C-x ( and C-x ) in which I run a shell command:
      Alt-x shell-command Enter
      d:\inbox\closepdf.exe             (this is the script I wrote with winautomation)
      C-c C-c                                 (starting latexing)
After some trial-and-error, I now have a Emacs-keyboard macro that exactly does what I want: it closes the pdfviewer program using the winautomation-script and compiles my tex file to pdf.
I changed my settings for latex to always produce a pdf-file by putting the following line in my .emacs
      (setq TeX-PDF-mode t)
so now I don’t have to bother about the proper file-format for figures (no converting to ps, etc.).
The last thing I had to do was assign a key to my macro in Emacs. This is done by first naming the keyboard macro I recorded using “Alt-x name-last-kbd-macro” and after that save the macro in my .emacs file with Alt-x insert-kbd-macro and attach a key to it:
Here is the code snippet for the .emacs file
Of course, all this is also possible with autohothey or AutoIt,