Tables with footnotes in LaTeX

Once in a while, I need a table in LaTeX with some footnotes below the table. Doing an internet search I found a nice solution using the package threeparttable. Here is a small example with the nuclear power plants in Switzerland:

image

The LaTeX code for this table is self-explaining (note the special structure: table – threeparttable – tabular):

Efficient desktop environment under Windows 10 using virtual desktops and Vdesk

You probably know the feeling: You are working in your editor and want to jump to Emacs or another program opened on your computer. You Alt-Tab your way through Chrome, Word, Tetris, and lots of other programs and then you move to fast and just click past Excel. Here is a typical desktop when I am working.

2017-05-07 16_19_35-

You could use your mouse and just click on the window showing when you press Alt-Tab or click on the small icon in the task bar. But I don’t like using the mouse and love to have everything below my finger tips.

Windows 10 has a nice feature to have virtual desktops. You can have multiple desktops with specific programs opened. For example, one virtual desktop with outlook, skype and other programs relating to communication, one with your code editor for programming and writing as well as Excel, etc. Here is an introduction to working with virtual desktops.

One problem is that you can’t save these virtual desktops, so you have to install them again when you restart your computer. Vdesk is a free, nice utility to do this for you. Just install it and write a small script (you can find all the technicalities here. Just save the code in a batch file and add it to your autostart folder. This folder can be found by running the command “shell:autostart”:

2017-05-07 16_42_12-Run

Here is a small example of a script (“vdeskstart.bat”) that produces two virtual desks:

vdesk create:2
desk on:2 run:”C:\emacs\bin\runemacs.exe”
timeout /T 25
vdesk on:1 run:”C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE”

(the timeout is necessary as Emacs needs about 25 seconds to start).

This creates at start-up two virtual desktops and opens Emacs and Chrome in the first and Outlook in the second virtual desktop. You can now work in a virtual desk with your favorite coding tools, switch easily if you want to do some emailing. The coding virtual desktop now only has the programs in the background you really need.

Jumping to the other virtual desktop is easy. Just hit Ctrl-Windows and arrow left or right and you cycle through the desktops. Or you hit on the task view icon in the task bar and click, and you will see your virtual desktops you can choose from:

2017-05-07 16_30_00-Posteingang - renger@vannieuwkoop.ch - Outlook

More on problems with HiRes screens

In one of my previous posts, I showed how to adjust the properties of the executable of a program under Windows 10 that has a fuzzy look: Right-click on the executable and choose “”the “ Compatibility” tab where you have to activate the “Disable display scaling on high DPI settings”. This trick works fine for non-windows programs. However, Outlook or Excel still look terrible.

If you go to http://windows10_dpi_blurry_fix.xpexplorer.com/ you can download a free, small utility, where you can set your overall DPI-Settings back those from Windows 8 (which doesn’t have this problem).

2017-02-01 13_50_48-XP Explorer - Windows 10 DPI Fix

Just click on “Use Windows 8.1 DPI scaling (our fix)” and you are set.

Generating headings for project files

I use the free software AutoHotkey (AHK) for automation of many things. One of those things is generating headings for my project file. I developed a simple AHK-script that asks me for the project name, the topic and then inserts the heading with additional information like my name, my E-mail address and a keyword for subversion.

The script is quite simple and I have adopted it for headings for several project files (tex, R and gams). The only difference being the characters used to comment out a line.

Here is the script

The line with ::tplt:: shows the characters that when typed start the template script (in this case for a tex-file). The lines with “Inputbox” produce a box where I can enter information

message

In this case, I enter the project name. What follows is the input box for the subject and then some additional information. Note, that the command “send” needs a variable (between %-values), therefore, everything  without variables should be on the same line.

Here the result for a new gams project file:

gams

You can easily adapt this script for your own use.

Blurry look of programs on your high display screen

My new ThinkPad T460s is lighter (1.4kg instead of 1.8kg), thinner and has more memory (20Gb) than my previous one (T430s). It has a much better screen with 1920 x 1080 pixels. This last feature is nice, but some of my programs get a fuzzy look as they are not yet adapted to this kind of display.

For example, Evernote is not ready for scaling on high DPI settings. If you look in the discussions on this issue, for programmers this seems to be a rather daunting task. Evernote explicitly does not promise anything in that direction (and it is an issue since 2013…).

The problem is resolved quite easily (although you probably have to do it again after updating the program):

  • search for the executable on your computer (in this case Evernote.exe)
  • right click on the file name and choose properties
  • in “properties” choose “compatibility” and (if the program is set up for all users), choose “Change settings for all users” and click on “Disable display scaling on high DPI settings”.

settings

Afterwards, your Evernote (or other programs with the same problem) are crystal clear again.

Using Powershell to clean up the animations your LaTeX file

In a previous post, I talked how to animate your Beamer presentations and how to print them as slides and article for the audience. One problem with a presentation with animations is that every element of an animation means one more slide. If you want to give the presentation to the audience so they can write on their slides using their ipad or touch screen notebook, they will complain that only one of the animated slides is complete.

The easiest way to remedy this, replace all overlays, \pause, etc. from your LaTeX file and print it like this. One could do this easily in Emacs and write a macro for this. This time I chose another way to do this using Powershell, the awesome windows scripting language.

First, I define a function that will show me a file picker. Then I will use this file picker to get the LaTeX-file that should be cleaned up. From the file chosen, I save the path in a variable $FolderPath and get the name of the file. This information is used to save the file as the original name with “_NA” (for no animation).

Then I read the content and replace all occurences of \pause, <+-.> <digit-> and \only by a space using regular expressions. After this I save the file in the original place using the _NA-addition. The only thing I had problems with was the encoding (Powershell saved it in the wrong format), so I had to add “–Encoding Default” as option.

That’s all. Of course, this could be done with any scripting language.

Tricks with Beamer: Animations and Print-Outs

If you use Beamer for presentations, you might want to use “animations”: either show list elements successively or build up a diagram. Beamer has some nice possibilities for doing this:

  • In lists (enumerate, itemize) you can use the overlays. Just add <1-> after the first \item and this item will show up first. For the second item you just add <2->, etc. You can also let them disappear again by giving a range (e.g. <2-3>, which means that this item will appear at the second and third slide, but will disappear again after that. If you want all the list elements to appear one after another and you don’t want do write down the elements one by one, you can use [<+->] just after your \begin{itemize}.
  • For other parts you can use \pause.
  • For diagrams made with tikz, you can enclose the parts of the diagram using \only<1->{ draw commands } with the same syntax as the overlays mentioned above. 

  If I give a lecture, I use a trick by Tom Rutherford, to print out my presentation in slides- and article form. My lecture is always in the file lecture.tex. I than have two additional tex files: beamer.tex and print.tex for producing pdf-files in slide- and article format. This way, students can either use the slides and write on them using their ipad, or use the article and print it out for in class.

The files look like this for the slides:

and for the article:

And here are the first pages:

beamer

article

Backing up your subversion repository on a remote Windows server using batch files

My subversion repository is on a server by Webfaction (probably the best and cheapest way to host your repository. I have 100 Gigabyte space). I used to have a backup script that would save the backup on the same server, which then was transferred to my Windows 8 computer. Because I wanted to replace the complete backup with a new one, I ran into problems, as the backup procress was taking to much of the server CPU. Support pointed me to svnradmin, which is a tool comming with the command tools of tortoisesvn (otherwise you will find these tools on Collabnet).

I searched the net and found some nice scripts to run this process automatically. I have two batch files. The first one runs the complete backup which is run once, the second one is a daily backup, that checks if there are new revsions and then starts to backup these.

The first batch file (fullbackup.bat) looks like this:

I agree: this looks rather cryptic. The first line takes the first 3 items from the output of the date/t DOS-command is something like: 16.07.2015 (depending on your settings, this might be differt). The for command now reads this and separates this information in three parts (i,j,k) where the delimiter is given as “.”.  This information is assigned to the variable “datesvn” and will be stored as 20150716. The second line does the same kind of trick with the time. The third line gets the actual revision on my computer. I than set the filename where everything should be saved to the directory the batch file resides (in this case, it would be something like “d:\svnbackup\SVN_20150716_1305_rev1_3995.dmp”. The next line does the actual dump using svnrdump. Now I have a full backup I can build on. The last line saves the number of the last revision to a file. This whole process can take a couple of hours, if you have a big repository. You can also adjust this script, so you split the backup for revisions ranges like 1:1000, 1001:2000, etc.

The second batch file will check if there are new revisions and if necessary start an incremental backup:

It looks for the last revison in the text file, checks if there are new revisions and then runs the same kind of procedure as before. This batch file can be run on a regular basis using the task scheduler from Windows.

Automatic operator formatting mode in Emacs

Emacs has a nice new mode called electric-operator developed by David Spepherd. It helps when you write code by formatting all operators in a predefined way. For example, in R it adds spaces around the operator signs, when you write 1+1, this is automatically converted into 1 + 1.

You can define your own way of formatting for other modes. For gams-mode you add the following to your .emacs file

First you set gams-mode as a mode on which electric operator can work.Then you add some rules. After that you set a hook so electric-operator is automatically started when you use Gams (or ESS).

A special formatting is necessary for the comments in GAMS as they start with the same symbol as the multiplication. With the help of David, I could add a function gams-mode-* that changes the “*” used as a comment in “* “ and otherwise in “ * “.  It checks if the “*” symbol is at the beginning of the line and in that case will not add a space in front of it.

It probably needs some more tweaking, and I will keep you posted on improvements.

Note taking with LaTeX for learning

Summarizing a text book is easy in LaTeX, but sometimes I want to learn the summarized text. Reading the summary over and over again is not very efficient, so I came up with the typical solution, where you can hide the main part of the summary and can check your knowledge by asking yourself questions based on keywords in the margin. Here is an example, where I started summarizing the R package data.table:

image

Now I use hide the main text and can ask myself the questions:

  • Express the data.table in SQL-form?
  • How to create a data.table?

Add the following to your latex file (note that I load also the packages lstlisting and some other packages not mentioned here):

Some remarks:

  • I changed the vertical distance of the paragraphs, so it automatically skips a line (if you summarize with lots of text this is probably not a good thing, but if you summarize R commands like in the example, you don’t want to have to add linebreaks after every paragraph.
  • I removed the indent for new paragraphs for the same reason.
  • I added the package color so I can show the margin notes in the color red (using the renewcommand for the marginfont.

In the text you can now add a margin note by adding: