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:

image

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

image

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.

image

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:

image

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 http://www.xcell.excelabo.net/english 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).

image

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

 image

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

image

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:

image

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

image

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 (http://tincman.wordpress.com/2011/01/04/research-paper-management-with-emacs-org-mode-and-reftex/) 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)

image

  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)

image 

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:

image

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:

image

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:
Add:

and

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 http://support.gams.com/doku.php?id=gdxrrw:interfacing_gams_and_r). 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” (!!!, http://enoriver.net/index.php/2013/04/12/keeping-knitr-happy-after-upgrading-to-r-3-0-0/ )
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 (http://cran.r-project.org/bin/windows/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 http://r-forge.r-project.org/R/?group_id=440
  • 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 (http://support.gams.com/doku.php?id=gdxrrw:interfacing_gams_and_r ). Extract the files in your R library and add the following line to your Rprofile.site (in the directory etc of your R-installation), where you have to set the gams directory properly.
.First <- function() {
     library(gdxrrw)
     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 Rprofile.site
   if (interactive())
   fortunes::fortune()
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: http://msdn.microsoft.com/en-us/library/aa965711(v=vs.85).aspx and here is a good article http://www.howtogeek.com/73065/learn-the-advanced-search-operators-in-windows-7/ 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):
 
 
 
 

Upgrading to Windows 8 in only 5 minutes

A few months ago I installed Windows 8 on my workstation (Microsoft was offering a cheap upgrage, so being Dutch and always looking for cheap offers, I bought the upgrade). My workstation had some problems, and I did  not want to set it up from scratch with Windows 7 again. It runs fine since then. It has some nice features and no issues until now.
windows-8-wallpaper_171433-1920x1200.jpg (800x500 pixels)
The Microsoft offer is still valid until the end of January, so I decided to upgrade my Windows 7 notebook too, as I will use this one probably for the next 3 years (Lenovo T430s). I just upgraded and did not install Windows from scratch. It took me 5 minutes (most of the time the upgrade did not need any action from my side). No issues at all. All Windows software (for example, visual studio) was updated automatically.
The only thing I don’t like, is the opening desktop (tiles everywhere and no touchscreen) without the start button, so I installed Start8 (it costs 4.99$) and now I have my “normal” Windows 7 desktop (with some nice modifications back again:
Important update:
One important warning: I just discovered, that the path system variable is almost empty after installing and I had to manually adjust it, so my command line scripts for Powershell, Gams and other programs can run. So before you upgrade: copy your path system variable and put it back in place after the upgrade!