Automating writing LaTeX papers even further

In an earlier post I wrote on how to use R to produce all kind of figures and tables for a LaTeX paper. This time, I will show, how to automate this process even more.

My work flow consists of a batch file, that runs my model, sends the results to R, produces my tables and figures and sends these to my paper: If I change my model, I just have to run this batch file, and the results in my paper are automatically adjusted. One smaller problem is that I often write in my text on a specific value from a table (for example, the minimum time used). Every time I change my model, I have to check these entries by hand (of course, I could use knitr, but that is on my list for the future and at the moment, I want to keep my R-files separate from my LaTeX files).

Here is a neat trick, to automate this process. Suppose I have calculated the reduction in time in my model and exported the results to R. In my paper I have the following  sentence:

“As you can see in Table 1,in the scenario “Cruising” the reduction in driving time is 12.4%.”

In my R-script, I have the R-Code that produces this value or takes the value from my model results directly. Now I use some simple R-commands to produce a LaTeX file that can be included in my paper:

In my LaTeX-paper, I now just change the sentence to:

This produces the same sentence as before. However, if I change my model, the minimal reduction is changed and automatically adjusted.

Removing extra blank lines in Emacs

If you want to get rid of extra blank lines in your text files, you can use the search and replace commands with regular expressions. However, for whatever reason, this does not work properly on my Windows machine.

Fortunately, I found a nice function definition at stackoverflow which does the job:

http://stackoverflow.com/questions/4419576/delete-extra-blank-lines-in-emacs

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 stackoverflow.com, 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.