Introduction to Sumatra – Automated tracking of scientific computations

I gave a seminar on how I use Sumatra as an “automated lab-notebook” for my computational research. These slides are tutorial to Sumatra and detail how to get started:

Setting up Emacs with Compiz

I recently spent some time to set up GNU Emacs 24.3.1 properly in my Ubuntu 12.04/14.04 environments with the Compiz windows manager. Here I describe how to

  1. start Emacs in a specified position and size, and
  2. set focus (activate) Emacs in the current workspace

for the Compiz window manager. Note that if you’re using another window manager (find out by typing wmctrl -m in a terminal), most of the tips in this post will be useless to you.

Start Emacs in a specified position and size

Personally, I strictly keep Emacs on the right side of my screen and try to adjust the width to 80 columns. Emacs size can be controlled on start-up by passing the right set of parameters. In my setup I use

emacs24 -fh

to start in full height; the windows is 80 column wide by default.

To start in a specified position, I used the CompizConfig Settings Manager. Easily installed via

sudo apt-get install compiz compizconfig-settings-manager

the manager allows to set start-up window positions for classes of applications. In Place Windows selected the tab Fixed Window Placement. When adding a new fixed position for a class, note the grab functionality to easily extract the window class name.



Activate Emacs in the current workspace

The command line tool gives you (almost) everything you need to set the focus on your Emacs window. If you only ever have a single Emacs window open, all you need is

wmctrl -x -a Emacs

However, I like to have multiple Emacs instances across my workspaces. The solution to activate the Emacs window in the current workspace was given on AskUbuntu by user55822. Here’s the script adapted to activate Emacs:

# Adapted from user55822 on AskUbuntu: 

SCREEN_W=$(xwininfo -root | sed -n 's/^  Width: \(.*\)$/\1/p')
SCREEN_H=$(xwininfo -root | sed -n 's/^  Height: \(.*\)$/\1/p')


wmctrl -xlG | awk -v W="$SCREEN_W" -v H="$SCREEN_H" \
       -v NAME="$NAME" \
       '$7==NAME && $3>=0 && $3<W && $4>=0 && $4<H {print $1}' \
       | while read WINS; do wmctrl -ia "$WINS"; done

exit 0

Finally, set keyboard shortcuts to your custom commands/script in the Keyboard settings:


Template for code highlighting with minted in LaTeX beamer

Syntax highlighting can be achieved in LaTeX via listings or more recently with minted. The latter package uses Pygments to create beautiful code highlighting and includes fantastic additional features such as line numbering.

Minted’s compatibility with the Latex beamer class, however, is restricted and some workarounds (as laid out by Tristan Ravitch in his blog post) are needed to assure full functionality of both the beamer class and minted.

Here’s a template I created for anyone who wants to present code with the beamer class and the minted package. Slides created in such way can then, for example, look like this:


Get the TeX source code!

Mathjax theorems – CSS for LaTeX-like environments – Custom names

EDIT: As mentionend in the comments, this solutions does not currently work in all browsers.
EDIT2: Paul Siegel has commented below and shared a solution that works again in all browsers. His implementation should be preferred. For ease of reading, I’ve posted his solution on my new blog. Many thanks to him!


In a fantastic post on his blog earlier this year, Zachary T. Harmany explained how LaTex-like environments, such as definitions, theorems and proofs, should be done with CSS.

His solution is a great way for writing mathematics on the web and I took his idea one step further, looking for a way to have custom names for theorems, which we would TeX as

\begin{theorem}[Prime numbers]
All odd numbers are prime.

To combine such functionality with Zachary’s approach, I got the right idea from BigMacAttack’s answer to a stackoverflow question about a related topic.

Here’s what I am suggesting:

.theorem {
    display: block;
    font-style: italic;
    margin-left: 4.5%; margin-right: 4.5%; margin-top: 2em;
    content: "Theorem ";
.theorem:before {
    content: inherit;
    font-weight: bold;
    font-style: normal;

With this one could write

<div class="theorem" style="content:'Theorem (Prime numbers)';"> 
All odd numbers are prime.</div>

to get

Theorem (Prime numbers) All odd numbers are prime.

For more about this, please visit Zachary’s original post !

Mathematical Annotations in PDF Part II – Introducing pdfnoter

In my last post I presented a way to make annotations to a pdf document using LaTeX and the ingenious pdf tool pdftk. While the procedure I described served its purpose,  it was quite tedious and not really practical.

But there is hope: caks, after I contacted him about my solution, went ahead and greatly simplified the procedure by scripting it. Please visit his Github page for the latest version of his pdfnoter. All you need to know is described there.

He’s also not stopping there. Ultimately, we want to have some kind of GUI, maybe even an extension to a pdf viewer, so that annotations can be, in fact, TeXed directly into your document. Currently caks is working on making the installation of the pdfnoter more convenient. Look out for further updates and posts!

If you have any comments and suggestions on the project you can also post them here. Any kind of input would be greatly appreciated!

Mathematical Annotations in PDF Documents

I’m often in the situation that while working with an interesting pdf, I want to add small notes to the document. Those annotations, for the sake of being short and precise, then almost always include math symbols. The problem is, that I rarely own the LaTeX source-code to the file; all I have is the pdf.

How to add mathematical annotations to a pdf, of which you don’t own the LaTex source-code?

While this is a question that does get asked from time to time (here and here), I had yet to find a comprehensive solution to the problem.

Here is mine:

I first create an otherwise empty pdf document, which only consists of my annotations, and then stamp this mask onto the target pdf, using the multi-stamp function of the pdf-tool pdf-tk.

A step-by-step guide to making mathematical annotations:

(1)  Download pdftk

Go to and download pdftk. Of course you will want to download the correct version for your operating system, but for this guide I will only reference Windows.

Unzip the downloaded file and I recommend following Sid Stewart’s advice and copy the contents (pdftk.exe and libiconv2.dll) of the bin-folder to


Another possible choice is to set up a working folder, where you will have your mask- and target pdf and copy the files there.

(2) Creating the mask

Next we will create an empty pdf file of at least as many pages as your target document and will put the annotations in the right places using LaTex.

Tex.stackexchange user egreg , had a wonderful suggestion of how to do this. Here is his sample code:


 \null\csname onthispage\thepage\endcsname\newpage}
 \expandafter\def\csname onthispage#1\endcsname{#2}}
\putonpage{1}{Hello world}
 \putonpage{3}{\vspace*{\fill}Hello world\par\vspace{\fill}}

As he explains, “this creates a four page document, with something on the first and third pages as decided by the commands \putonpage".

If you are not too sure of how to create your custom stamp mask from here, you can download this sample mask. (Sadly, I am not allowed to upload .tex files and had to settle for the awkward .doc file. Please open with notepad (or better notepad++) and copy&paste into the TeX Editor of your liking.)

Now create the pdf file from the source and for the sake of the tutorial name it


(Don’t worry,  if you couldn’t create a mask for whatever reason, here are a mask and a target you can use.)

(3) Stamping

Copy your mask.pdf and your target pdf to a folder of your choice. Please rename your target pdf to


for this tutorial.

Note: If you didn’t copy pdftk files to System32, they must be copied to this folder for the procedure to work!

Now all we need to do is stamping the mask onto the target using pdftk.

For this run a terminal (by clicking on the windows start button and entering cmd in the search field).

Next change to the directory where your mask.pdf and target.pdf are.

(You can do this by entering

cd  %path-to-your-directory

for example

cd C:\Windows\stampingfolder

If you need to change drives, enter the name of the drive with a colon, for example


if D is the name of your drive. Then locate your folder like above.)

Finally we enter the command that will tell pdftk to stamp the mask.pdf onto the target.pdf. Enter

pdftk target.pdf multistamp mask.pdf output stamped.pdf

This will create a pdf called stamped.pdf and it should contain everything of your target pdf with the annotations of your mask stamped upon it!