How I Wrote my Thesis 2019-01-10

Next week I will defend my thesis, “Contributions to Declarative Implementation of Static Program Analysis”. A PDF of the thesis can be downloaded here. In this post I will describe the writing process and the tools I used to write my thesis.

What is it about?

My research contributions are all related to the development of static program analysis with reference attribute grammars. Among the main contributions are new algorithms for concurrent evaluation of circular reference attributes.

With reference attribute grammars it is possible to construct highly extensible compilers. I have been working for the past five years on a Java compiler named ExtendJ, and several of my research contributions have been implemented as extensions to ExtendJ.

How long did it take?

I spent about half of last year working on my thesis. However, I probably only spent about three months of effective writing time on the thesis. The rest of my time was spent on various related tasks like searching and reading related work, reviewing drafts, drawing graphs, administrative tasks, and procrastination. Writing ramped up toward the end of the writing period. The last couple of weeks leading up to the end, I slept poorly and did nearly no other activities than just writing and reading through my drafts multiple times.

My thesis is a collection of previously published papers. The thesis starts with an introductory chapter which gives a background to several topics discussed in the thesis as well as describing my research contributions. The rest of the thesis consists of the included papers and finally a short popular science summary in Swedish. The majority of my writing work went into the introductory chapter. Although I did not edit the text of the included papers I had to adjust tables, figures, and paragraph layout to make them fit in the book format of the thesis. For one of the papers I replaces four raster images with TikZ graphics.

LaTeX Makefile and automation

I wrote my thesis in LaTeX on Ubuntu. I used Chris Monson’s amazing Latex Makefile to compile my LaTeX code. This makefile was indispensable because it filters out all irrelevant output from LaTeX and only shows warnings and errors in the console, for example:

I had to make a small edit in the makefile so that it could work with Biber, but otherwise it worked very smoothly. To further make my LaTeX editing as smooth as possible I used entr to automatically recompile when I saved the LaTeX code.

The default document viewer on Ubuntu (Evince) automatically reloads a PDF if the file is changed on disk. When I made any change to the LaTeX code and saved the file, entr would automatically run the makefile and after a short delay the document viewer reloaded the PDF so that I could see the effect of my changes. I had the document viewer on one display and my LaTeX code on the other. My setup worked similarly to Overleaf, except that I edited the code in Vim and had full control of my own files and didn’t rely on a network connection.

TikZ and Forest

I spent a considerable amount of time designing figures and diagrams for the thesis. I wanted to mainly use TikZ to draw my diagrams. TikZ is a LaTeX package which can be used to draw figures directly in a TeX document as vector graphics. There are several advantages of using TikZ which motivated me to use it for the figures:

  • TikZ figures are scalable to any size without pixelation.
  • TikZ figures typically use relative positioning for specifying the locations of objects. When something changes size, the rest of the figure will be adjusted to maintain the relative distances. This is very useful when editing the text in the blocks in a flowchart, for example.
  • Text in TikZ figures is written with normal TeX code. This both makes the fonts in figures automatically consistent with the rest of the document and also allows the use of mathematical equations or any other kind of TeX formatting.

The major disadvantage of using TikZ is that figures are designed within the TeX language using an embedded DSL for describing diagrams. It can take a very long time to make a nice figure with TikZ. For example, it took three days for me to replace four raster images in one of the included papers by TikZ figures.

Illustrating trees is especially onerous in TikZ. However, I found the supremely useful Forest package which adds a DSL on top of TikZ for describing trees. With the Forest package it was very easy to draw nice trees for my thesis. The code for the trees was fairly minimal in most cases. For example, here is a small tree in Forest code:


Here is the resulting figure from the above code:

The trees generated by Forest are TikZ objects and can be integrated into regular TikZ drawings with little effort. I used this when drawing arrows between nodes in a tree, among other things.

If you want to look at the TikZ code for the figures, the TeX code for my thesis is on my GitHub page. Some figures in the included papers are EPS or SVG instead of TikZ.


I am very happy to finally have finished my thesis. For the past half year or so I have largely neglected friends and family to focus on the thesis. I also constantly had a bad conscience about not progressing fast enough with the writing.

At the start of my PhD studies I felt like I would not have enough research results to write a full thesis. Doing good research is hard, and there is much more to it than just coming up with a new idea and implementing it. Implementing a new algorithm is the easy part, the hard part is to describe and evaluate it so that it becomes useful for other researchers.

Although I feel that there are some parts of my thesis which could have been improved, especially in the earlier papers, I am very pleased with it as is. I am especially pleased with the background sections about attribute grammars.

Categories: Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.