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 http://biblatex.dominik-wassenhoven.de/dtk.shtml.
 
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 (http://www.jstatsoft.org/v21/i12/paper)
  4. Use the R package “xtable” (see http://cran.r-project.org/web/packages/xtable/xtable.pdf) 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 (http://support.gams.com/doku.php?id=gdxrrw:interfacing_gams_and_r).
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 http://jabref.sourceforge.net/). 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 http://ctan.org/pkg/biblatex).
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 http://emacs-template.sourceforge.net/details.html). 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 (www.winautomation.com). 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,

Update of Gams-Tex

Edson Valle sent me an update for Gams-Tex (see my blog from 28. Januari) where he showed how to add new keywords to the Gams-Tex file (here done for the MPSGE keywords):
 
Just add the following lines to the gams theme file (theme_gams.tex) after the moreKeywords={
$PROD, $DEMAND, $AUXILIARY, $COMMODITIES, $SECTORS, $CONSUMERS, $MODEL, $REPORT,
It’ll become automatically case insensitive due to the options selected.

Gams code in LaTeX documents

Edson Valle recently wrote a style for the package listings from LaTeX. It allows you to format Gams code nicely in your LaTeX documents.
Here is a small example taken from his post to the Gams mailing list:
Scalar X /1/;
Scalar Y;
Y = 2*X;
Display “This is the famous Y”, Y;
In your LaTeX document this would look like:
The only thing you have to do is write a file gams.tex with the style and include this file in your LaTeX document before \begin{document}.
Information on the package Listings can be found here: ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf
The gams.tex file should look like this:
\usepackage{listings}
%author Edson Cordeiro do Valle edsoncv at gmail dot com

\lstdefinelanguage{GAMS}{
morekeywords={
ABORT , ACRONYM , ACRONYMS , ALIAS , ALL , AND , ASSIGN , BINARY , CARD , DISPLAY , EPS , EQ , EQUATION , EQUATIONS , GE , GT , INF , INTEGER , LE , LOOP , LT , MAXIMIZING , MINIMIZING , MODEL , MODELS , NA , NE , NEGATIVE , NOT , OPTION , OPTIONS , OR , ORD , PARAMETER , PARAMETERS , POSITIVE , PROD , SCALAR , SCALARS , SET , SETS , SMAX , SMIN , SOS1 , SOS2 , SUM , SYSTEM , TABLE , USING , VARIABLE , VARIABLES , XOR , YES , REPEAT , UNTIL , WHILE , IF , THEN , ELSE , SEMICONT , SEMIINT , FILE , FILES , PUT , PUTPAGE , PUTTL , PUTCLOSE , FREE , NO , SOLVE , FOR , ELSEIF , ABS , ARCTAN , CEIL , COS , ERROR , EXP , FLOOR , LOG , LOG10 , MAP , MAPVAL , MAX , MIN , MOD , NORMAL , POWER , ROUND , SIGN , SIN , SQR , SQRT , TRUNC , UNIFORM , LO , UP , FX , SCALE , PRIOR , PC , PS , PW , TM , BM , CASE , DATE , IFILE , OFILE , PAGE , RDATE , RFILE , RTIME , SFILE , TIME , TITLE , TS , TL , TE , TF , LJ , NJ , SJ , TJ , LW , NW , SW , TW , ND , NR , NZ , CC , HDCC , TLCC , LL , HDLL , TLLL , LP , WS , /,PROD: },
sensitive = false,
morecomment=[f]*,%
morecomment=[s]{$ontext}{$offtext},
morecomment=[s][\color{green}]{/}{/},
morestring=[b]”,
morestring=[b]’
}
\lstset{
basicstyle=\fontfamily{pcr}\fontseries{m}\selectfont\footnotesize,
commentstyle=\color{gray}\itshape,
keywordstyle=\color{blue}\bfseries,
stringstyle=\color[rgb]{0.5,0,0.5}\itshape,
showstringspaces=false,
numbers=left,
numberstyle=\color[rgb]{0,0.5,0.5}\fontfamily{pcr}\fontseries{m}\selectfont\tiny,
numberblanklines=false,
showlines=false,
belowskip=\bigskipamount{},
breaklines=true,
%stepnumber=2,
tabsize=6,
%extendedchars=true,
%float=h,
frame=tb
}

Excel-Addin for converting Excel tables to LaTeX tables

Although I am not a great fan of the Microsoft software, I have to admit that Excel is great. Sending tables from Excel to Word is easy but I work in LaTeX and then it can be time consuming. Fortunately there is a nice add-in for Excel that allows you to copy your Excel table to LaTeX. It is called Excel2LaTeX and developed by Joachim Marder and Andrew Hawryluk and can be downloaded from http://www.ctan.org/tex-archive/support/excel2latex/. I tested it with Excel 2010 and it works fine.
 
When you download the file Excel2LaTeX.xla you can either open it when you need it or if you use it often save it in your Excel add-in directory.
Most of the text formatting, border lines  and even multi-column cells are retained.
Text formatting (bold, italic) is retained and multi-column cells are supported. The LaTeX code can be copied to the clipboard or saved as a LaTeX file, which then can be included in an existing LaTeX document using the \input command.
 
Here a small example: First the excel table:
 
 
and here the code generated by Excel2LaTeX
 
% Table generated by Excel2LaTeX from sheet ‘Estimation LES’
\begin{table}[htbp]
\centering
\caption{Add caption}
  \begin{tabular}{rrrrrrr}
  \addlinespace
  \toprule
  {\bf } & \multicolumn{ 6}{|c}{{\bf from the Estimation}} \\
  \midrule
  {\bf Good} & {\bf Alpha} & {\bf Constant} & {\bf Number of hh} & {\bf R-Adjusted} & {\bf s.e. Alpha} & {\bf s.e. Constant} \\
  agr   & 0.01  & 68.79 & 8262  & 0.29  & 0.00  & 3.75 \\
  fd    & 0.03  & 329.83 & 8262  & 0.20  & 0.00  & 16.15 \\
  mnf   & 0.14  & -365.17 & 8262  & 0.67  & 0.01  & 52.49 \\
  ppp   & 0.01  & -16.51 & 8262  & 0.32  & 0.00  & 8.54 \\
  ene   & 0.03  & -26.40 & 8262  & 0.46  & 0.00  & 24.08 \\
  crp   & 0.02  & -45.15 & 8262  & 0.72  & 0.00  & 6.41 \\
  nmm   & 0.00  & -4.34 & 8262  & 0.29  & 0.00  & 1.51 \\
  \bottomrule
  \end{tabular}
\label{tab:addlabel}
\end{table}


And here the table in LaTeX (don’t  forget to include the package booktabs).