Get rid of tabs in Emacs

If you work with other on text files, you often run into the problem that one of the programmers is using tabs set to 4, another to 8 spaces. For this reason, I always save my files without tabs. In Emacs there is a command to do this “untabify-buffer”, but I usually forget to do this.

Searching the internet I found the following code at, to do it automatically as soon as you save the file.

You can define your own hooks for other modes.

If you would use the untabify-buffer as a common hook, you can run into problems, because every file will be untabified.

Using org-mode in outline-mode

I have written about using org-mode in gams-mode in an earlier post. Gams-mode lets you structure your gams file using headings and subheadings. These headings can be (partially) collapsed. The structure of your file could look like this:


You can now cycle through the structure using Shift-Tab. Tab opens a section:


This is a great help in complex files.

Gams-mode has another great outline feature for the listing file. Instead of putting a normal comment with a “*” in front, one writes a display statement that starts with a “@” (see the code above). We now see a nice heading in our listing file.


However, what is really fantastic, is the display of the actual loop state in the outline mode (in the listing file you can easily search for the loop element, but in the outline mode this is not possible). Now you can see the loop status in the above code after the “LOO” . Hitting “space” the listing will be shown in another window.

Matrix inversion in Excel

Even the newest version of Excel has a limit on taking the inverse of a matrix. The maximum size is 52×52 (don’t ask me why this limit exists). What you get if you use minverse(your matrix) for a big matrix is this:


Fortunately, there is a nice add-in programmed in C that does the trick. It was developed for Excel 2007 and earlier but it works fine in the newest version (2013).

You can download it from and it works like the inverse function in excel. Instead of minverse(….) you use minverse.ext(…).

PS. If you want to take the inverse of a matrix in excel, you mark the region, where the inverse should appear and then enter minverse(your matrix) and hit Ctrl-Shift-Enter (like for all array-operations in Excel).


and after hitting Ctrl-Shift-Enter you get this:


Getting rid of some annoyances when opening or saving in Excel 2013 (and Word, Access)

The new Office version (2013) has lots of new features, but also some annoyances. Especially saving and opening files need much more clicks.

If you want to open a file, Excel opens with a start screen. Disabling this one is easy: just go to File-Options-General Tab and disable “Show the Start Screen…”.

If you want to save a file, this is what appears in Excel


Now you have to click on Browse to search the directory you want to save your files. It goes faster as follow, if you set the following options (see arrows) and set your favorite directory:


Afterwards, it will look likes this if you want to save (Ctrl+S is the short-cut for that):


Note, that if you use Ctrl-O for opening a file, you get the same results (instead of the “Backstage view”).

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:

Switching between Emacs color themes

Emacs has lots of different color-themes. Depending on the light and my own mood, I would like to change between my two favorite themes, the “standard” light theme and a dark one.
This is the color-theme I use for my LaTeX files (“sitaramv-nt”):
But for my model files, I like the dark color-theme (“dark-laptop”), but sometimes the light one.
I searched the internet and found some code that allows me to switch easily between the themes using F11:

Migrating to R 3.0.0: TikzDevice and gdxrrw

I am an avid user of R. Most of the time, I use R for preparing nice plots and tables for my LaTeX papers. For my plots, I use TikzDevice and for my tables I use xtable. Gams, my modeling software, developed a nice interface for using data from Gams in R and the other way around (see When I upgraded from R 2.15 to R 3.0, I had some problems on my windows 8 machine, especially with TikZDevice. I finally managed to get it installed. The necessary trick is described on “The Stata Things” (!!!, )
Here is what you have to do, to get TikzDevice up and running:
  • Install R 3.0
  • Update your packages, using the command: update.packages(checkBuilt=TRUE)
  • Install Rtools ( and adjust your path (sytem variable PATH) by adding the bin-directory of Rtools (something like C:\Program Files\Rtools\bin)
  • Download tikzdevice from
  • Run the following commands in the R Console
  • remove.packages(“tikzDevice”)
  • install.packages(“Path to where the file on your computer is/tikzDevice_0.6.3.tar.gz”, repos = NULL, type=”source”)
For Gams users: download the gdxrrw 0.3.0 (not 0.2.0) from the homepage ( ). Extract the files in your R library and add the following line to your (in the directory etc of your R-installation), where you have to set the gams directory properly.
.First <- function() {
     a <- R.Version()$arch
     if (a == “x86_64”)  igdx(“C:/program files/gams_64/23.9.4”)
     else                igdx(“C:/program files/gams_32/23.9.4”)
PS. I like the fortunes package. It produces nice quotations when you start up R. Just install the package and add the following lines to your
   if (interactive())
Here an example
I wish to perform brain surgery this afternoon at 4pm and don’t know where to start. My background is the history of great statistician sports legends but I am willing to learn. I know there are courses and numerous books on brain surgery but I don’t have the time for those. Please
direct me to the appropriate HowTos, and be on standby for solving any problem I may encounter while in the operating room. Some of you might ask for specifics of the case, but that would require my following the posting guide and spending even more time than I am already taking to
write this note.
  — I. Ben Fooled (aka Frank Harrell)
     R-help (April 1, 2005)

GAMS and Excel: writing and checking results with automatic closing and opening

I often use the Gams utility gdxxrw to write the results of my model simulations to Excel. In the testing phase, if you don’t know some nice tricks, this means a lot of closing and opening Excel: If the result file is open in excel, you get an error, when you try to write results to the Excel file, so you have to close Excel first and rerun your simulation. After writing the results to Excel you have to reopen the file again. Lots of keystrokes…
However, gdxxrw lets you reduce the number of strokes, by using the gdxxrw utility xlstalk.
For the problem above, you could write the following:
       execute ‘xlstalk -S results.xlsx’
       execute ‘gdxxrw.exe results.xlsx i=results.gdx ….’
       execute ‘xlstalk -O results.xlsx’
The first line saves the file results.xlsx and closes it (if open) and closes Excel. The second line is the command line for writing the results to the file. The last line opens the file in Excel.
Using this lines, you can run your model over and over again without manually closing and opening Excel.

Using Windows Desktop Search to search for text in files with another extension than "txt"

I use Windows Search quite often on my notebook to look for a file, E-Mail or a program. In Windows you just hit the Windows Key and start typing, which is very convenient.
If you want to start a program you just start typing the program name and hit enter Excel, hit the key and type “exc” and enter, and off you go.
The normal search (files or text within files) is also very powerful. Here is a site which explains the syntax: and here is a good article on how to use it.
One problem with Windows Search is, that it doesn’t do a text search in my Gams files. I was looking for a file with the word “CPLEX” in it. I knew, I wrote that file last year, but it did not show up in my search. The solution is telling Windows Desktop Search that it should also index the file contents of Gams files. You can do this by going to your Control Panel, click on Indexing Options and then on Advanced Options. Look for the “gms” extension and change the indexing form “Index Properties Only” to “Index Properties and File Contents” (see below). I also removed a lot of file types, I never want to search for.
Here is an example of the windows desktop search in Windows 8 (I searched for the term “urban” in Gams files):