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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Function Get-OpenFile($initialDirectory)
{
	[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
	Out-Null
	$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
	$OpenFileDialog.initialDirectory = $initialDirectory
	$OpenFileDialog.ShowDialog() | Out-Null
	$OpenFileDialog.filename
	$OpenFileDialog.ShowHelp = $true
}
$InputFile = Get-OpenFile
$folderPath = Split-Path -parent $InputFile
$NameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($InputFile)
$SaveFile = $folderPath + "\"  + $NameWithoutExtension + "_NA.tex"
(Get-Content $InputFile) |
Foreach-Object { $_ -replace '\\pause', ' ' } |
Foreach-Object { $_ -replace '\x3C\d\x2D\x3E', ' ' } |
Foreach-Object { $_ -replace '\x3C\x2B\x2D\x3E', ' ' } |
Foreach-Object { $_ -replace '\x5Conly\x3C\d*\x2D\x3E', ' ' } |
Out-File -Encoding Default $SaveFile

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:

1
2
\documentclass[compress,xcolor=dvipsnames,english,10pt]{beamer}
\input{lecture.tex}

and for the article:

1
2
3
\documentclass[a4paper,9pt]{extarticle}
\usepackage{beamerarticle}
\input{lecture.tex}

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:

1
2
3
4
5
for /F "tokens=1,2,3 delims=. " %%i in ('date/t') do set datesvn=%%k%%j%%i
for /f "tokens=1,2 delims=: " %%i in ('time/t') do set t=%%i%%j
for /f "tokens=2" %%i in ('svn info -rHEAD https://svn.modelworks.ch^|find "Revision"') do set last_rev=%%i
set "outFilename=%~dp0SVN_%datesvn%_%t_rev%1%_%last_rev$.dmp"
svnrdump dump https://yourrepository:port &gt;  %outFilename%

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
@echo off
FOR /F "tokens=1" %%i in (last_rev.txt) do set backup_number=%%i
for /f "tokens=2" %%i in ('svn info -rHEAD https://svn.modelworks.ch^|find "Revision"') do set last_rev=%%i
if %last_rev% == %backup_number% goto :eof  
REM /a is necessary to calculate the new value of the start point 
FOR /F "tokens=1" %%i in (last_rev.txt) do set /a start_rev=(%%i + 1)
for /f "tokens=2" %%i in ('svn info -rHEAD https://svn.modelworks.ch^|find "Revision"') do set last_rev=%%i
for /F "tokens=1,2,3 delims=. " %%i in ('date/t') do set datesvn=%%k%%j%%i
for /F "tokens=1,2 delims=: " %%i in ('time/t') do set t=%%i%%j
set "outFilename=%~dp0SVN_%datesvn%_%t%_rev%start_rev%_%last_rev%.dmp"
@echo %outFilename%
svnrdump dump https://svn.modelworks.ch:443 --incremental -r%start_rev%:%last_rev% &gt;  %outFilename%
@echo %last_rev%   &gt; last_rev.txt

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(require 'electric-operator)
(apply #'electric-operator-add-rules-for-mode 'gams-mode
electric-operator-prog-mode-rules)
 (electric-operator-add-rules-for-mode 'gams-mode
   (cons "=E=" " =E= ")
   (cons "=G=" " =G= ")
   (cons "*" #'gams-mode-*)
   (cons "**" " ** "))
 
(add-hook 'gams-mode-hook #'electric-operator-mode)
(add-hook 'ess-mode-hook #'electric-operator-mode)
 
(defun gams-mode-* ()
  (cond ((bolp)  "* ")
        ;; Othewise act as normal
        (" * ")))

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

1
2
3
4
5
6
7
8
9
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}%
\usepackage{geometry}
\usepackage{marginnote}
\usepackage{color}
\newgeometry{top=1.5cm, bottom=1.5cm, outer=5cm, inner=2cm,
heightrounded, marginparwidth=4cm, marginparsep=0.1cm}
\renewcommand*{\marginfont}{\color{red}\sffamily}
\makeatother

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:

1
\marginnote{your text for the margin}

Column guide in Emacs

Many professional editors have a column guide. For example, below you see in the Powershell editor a veritcal line at column 80.

image

This marker comes in handy, if you want to print your files. In Emacs I usually check for the column 80 in the status line.

image

However, I usually forget to check, and when I print out stuff or publish, I got line breaks where I don’t want them. Passing the 80th column for comments is not a problem, as a simple Ctrl-q forces Emacs to break the lines nicely and add comment symbols at the beginning.

image

But after hitting Ctrl-q, Emacs produces this:

image

There is, however, a package, that mimics column guide seen in other editors. The package is called “fill-column-indicator”. Installing this package will do the trick. After installing, you only have to add the following lines to your .emacs file:

image

I added two hooks, so the column rule appears automatically in Gams and ess.

More information can be found here: http://www.emacswiki.org/emacs/FillColumnIndicator

Using file templates in Emacs

A good practice in modeling is to place information related to the project your are working on, the subject, the data and your personal information like E-mail address at the top of your file. In Emacs you can define skeleton functions that will prompt for the information and put it in the file. Below is an example for a file with as comment symbol “**: (the $Id: $ is for my version control system, that automatically will add the information on the last commit in this line).

image

Below you see how to make a function using skeleton. As I don’t want to repeat myself, the function asks as an input the comment symbol(s) that should be used. I now can use the function for different programming languages (R uses “#” , C++ uses two forward slashes, GAMS “*”, etc.). You can add the time and date by using the command “current-time-string”. All other inputs that have skeleton-read in front of it, are also prompted for. If you need the template for your whole project team, you could just make the author and contact field also input-dependent.

image 

More information can be found at: SkeletonMode. (note that this is part of Emacs since version 22).

PS. The function puts an extra comment symbol at the end (not shown). This is a bug in my function. Any ideas how to get rid of this are welcome.

Using Org-mode to keep track of your project files

For every project I work on I have a org-file. Every file has the following structure:

  • Tasks
  • Repeat
  • Wait
  • Notes
  • Calls
  • Reading

I use remember-mode to capture tasks, notes and calls. Under the heading “Repeat” are tasks that are repeated on a regularly base. Under “Wait” are reminders for things I wait for (like a reply on an e-mail, an order, a call, etc.). These waits are also captured using org-remember (I have written about that in an earlier post). Under the heading “Reading” I have links to papers I am currently reading (using Bibtex; see an earlier post on that).

Sometimes it is nice to have information on the files in one of the project directories, if possible with links. This can be done with org-fstree. Just add (require ‘org-fstree) in your .emacs-file after installing. You now can add the following line somewhere in your org-project file:

#+BEGIN_FSTREE: d:/inbox/Gams

This will give me all the files in the directory d:/inbox/Gams with a direct link (this is my folder for answering questions in the Gams forums).

image

You can update this by putting the cursor in this line and hitting C-c C-c. The documentation gives you information on the options:

“#+BEGIN_FSTREE: <dir> :<optionname1> <optionvalue1> :<optionname2> <optionvalue2> …

Options are:

  • :non-recursive t , to suppress recursion into directories
  • :exclude-regexp-name <list of regexp strings> , exclude file/directory names matching either of the given regexp expressions
    • :exclude-regexp-name (“.*\\.pdf$” “.*\\.zip$”), excludes files/directories ending with either “.pdf” or “.zip”
    • :exclude-regexp-name (“^\\.git$“) , excludes files/directories named “.git”
    • – :exclude-regexp-fullpath <list of regexp strings>, same as :exclude-regexp-name but matches absolute path to file/directory
  • :relative-links t , generates relative instead of absolute links
  • :show-only-matches t , only files that are being linked to show up
  • :only-directories t , only directories are listed
  • :only-regular-files t , only regular files are listed
  • :dynamic-update t , [EXPERIMENTAL] dynamically update a subtree on visibility cycling.
  • :links-as-properties t, sets the links as properties Link1, Link2,… for use in column view [Does not work with dynamic-update!]
  • :no-annotations t, suppresses the search and display of file annotations

Following up on Outlook E-Mails in Org-Mode

The combination of Org-Mode and Remember-Mode helps me to organize my projects. One special task category is “WAIT”, if I have to wait for some input from somebody else or waiting for a delivery to arrive. An example is ordering a book at Amazon. As soon as I make the order, I generate a “WAIT” which would look like this

** WAIT [#C] [2014-09-16 Tu] Book on Modeling by Morgan

In this case, I ordered the book on September 9th and it has not a high priority. Once a week I check this category in a customized agenda view which sorts the WAITs according to their priority. If necessary, I take action (for example resending an E-Mail). 

One nuisance is that I use Outlook for my E-Mails and Org-Mode for my tasks.If I send an E-Mail and are waiting for an answer, or if I receive an E-Mail with information on my order, I can’t generate a direct link between the E-Mail and the WAIT-task and I loose time looking for the original E-Mail.

I googled around and found the following solution by John Hilliard here (there is org-outlook, but I did not find a good explanation, how that works). He suggests to write a macro in Outlook that looks like this

'Adds a link to the currently selected message to the clipboard
Sub AddLinkToMessageInClipboard()

   Dim objMail As Outlook.MailItem
   Dim doClipboard As New DataObject

   'One and ONLY one message muse be selected
   If Application.ActiveExplorer.Selection.Count <> 1 Then
       MsgBox ("Select one and ONLY one message.")
       Exit Sub
   End If

   Set objMail = Application.ActiveExplorer.Selection.Item(1)
   doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
   doClipboard.PutInClipboard

End Sub

The macro gets the unique id for the email message and writes an Org Mode link to that message to the clip board.

Note that in order to write a macro, you have to activate the “Developer” tab in Outook, image

which can be done by right-clicking on the tabs and choosing “Customizing the Ribbon”. After defining the macro, you can add it to the quick access toolbar (same procedure as adding the developer tab), and choose a nice icon

image 

There might be an error, when running the macro, but you John nicely describes how to get rid of that one:

“When I first ran the macro, I actually got an error saying “Compile error: User-defined type not defined.” That was a little mysterious. In order to fix that error:

Click “Tools” then “References” in the menu.

Check “Microsoft Forms 2.0 Object Library” in the list of available references. 

  • This option wasn’t available to me at first so I clicked “Browse”
  • Then I opened “c:\windows\system32\FM20.DLL”

Then I clicked “OK”

I finally added the code for opening Outlook in my .emacs file.

(defcustom org-outlook-location (w32-short-file-name “c:/Program Files/Microsoft Office 15/root/office15/OUTLOOK.exe”)
  “* Microsoft Outlook 2013 location.”
  :type ‘string
  :group ‘org-outlook)

Now, I can select a message, click on the macro symbol which copies the link, jump to Emacs (I have a script for that) and insert the link. The WAIIT-Task would look like this: image

If I click on the Message-link, Outlook opens the message.