Messing (and suffering) with LaTeX

Early in December 2024 I presented a paper in the Brazilian Symposium on Formal Methods and while I prepared my slides, I noticed that I did not have a proper template for slides in LaTeX and I had to customize a template and a theme from my university that I had laying in my computer.

After the presentation I kept thinking about the time I had spent customizing this template and fighting with the theme instead of actually making my presentation, something that gave me the idea to create my own theme for slides, as well as templates for presentations and also for papers, both in portuguese and english, and also I took the opportunity to create a package with all my macros and useful definitions that I had created over the years. In this post I’ll talk about the adventure that was this.

In spite of the fact that the template for slides was what led me to have this idea initially, I chose to begin by converting a .tex file of useful definitions and macros into a .sty package. The main reason behind this choice was the fact that the slide template that I was going to change had some… issues that I didn’t want to deal with in that moment.

Starting with this conversion was a good idea because I learnt how a few things in LaTeX that I had already stumbled into actually worked. For example, what does the \relax command do (nothing, literally), what do the \makeatletter and \makeatother (respectively makes the @ symbol be interpreted as a letter and a special character) commands do and the difference between \usepackage and \RequirePackage (the first should only be used in .tex files and the second should only be used in .sty files). All things considered, this part was easy, all I had to do was copy the definitions from the .tex file to a .sty of same name, added some options to conditionally load some packages, added some more comments explaining everything and it was done… after I spent about an hour debugging the options, yes, but those are minor details.

With that done, I then went on to make my templates for papaers in both portuguese and english, something that also was rather easy. As I already had made dozens of papers in LateX this was only a matter of checking which packages I normally used, adding some comments explaining what each package does and filling out some fields like the author field and the title of some sections. There are so few diferences between the portuguese and english versions that I will not go into details about then.

Afterwards I intended to work on the theme for my slides, however unwillingness to fix the problems in the theme I was going to be using as a base led me to create a package with all my customizations for slides before doing this, something that didn’t take a whole lot of time as I had very few of those.

At last, it was time to tackle the issues in this theme. The theme that I had was from my university, which was a customization of a theme called ru theme, which I quite like, nearly all the space in the slide is dedicated to the content of the slide itself, the title and the current (sub)section are at the top of the slide, and the presentation title together with the name(s) of the author(s), the date and the counter for the number os slides are all at the bottom. The problem was at the top of the slide, in the box that contained the title of the slide, it was a single pixel too short to fit the slide.

My-university-theme Notice the right side of the image.

I cannot describe how much this annoyed me, but I imagine that you, dear reader, also feels annoyed by it. Oddly, I couldn’t reproduce this on the original theme when compiling it on my computer.

Original-theme Notice the right side of the image.

I then spent an entire day trying to figure out what could possibly be the issue behind this. I reaearched what was each component of the theme, I changed pratically every definition that I could, I tried removing each and every component to see if I could figure out what was causing the error, but nothing solved it. After many attempts to fix the error in the theme from my university, I went on to work on the original theme, hoping that the error was in some modification made in the theme from my university. Immediately I was faced with a warning stating that some background image was not found, upon removing the line that loaded this image that I did not have, I recompiled the slides and noticed that the problem was back.

At this point, I remebered a video from Computerphile about time zones, questioned if what I was doing was worth my time, closed VSCode and took my dog for a walk.

It took a few days for my will to work on this return, but when it did I decied that I was going to abandon this cursed theme and customize one of the standard themes from beamer. I then looked for a list of all standard beamer themes when I noticed that the Warsaw theme was nearly identical to the ru theme I was trying to customize. After thinking for a few moments, I decided that I was going to find out what on earth was wrong with this theme.

After several minutes scrounging the internet and my local installation of LaTeX, I found the souce code of the theme and, immediately afterwards, I calmly exclamed my surprise and insatisfaction with the creator of ru theme.

The reason is quite simple. Bellow is the definition of the title box in ru theme:

\begin{pgfpicture}{0.1mm}{0pt}{1.01\paperwidth}{\beamer@tempdim}
  \usebeamercolor{frametitle right}
  \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
  \pgfusepath{clip}
  \pgftext[left,base]{\pgfuseshading{beamer@frametitleshade}}
\end{pgfpicture}

And bellow is the definition of the same box in Warsaw:

\begin{pgfpicture}{0pt}{0pt}{\paperwidth}{\beamer@tempdim}
  \usebeamercolor{frametitle right}
  \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
  \pgfusepath{clip}
  \pgftext[left,base]{\pgfuseshading{beamer@frametitleshade}}
\end{pgfpicture}

Notice how the value of the first argument is different. Yes, that was the problem. Zero point one milimetres.

Now, dear reader, you may be asking yourself: “Miguel, why didn’t you try changing this value?”, and I will answer you: I did. Several times. But, you see, this value represents and offset. I foolishly tried to increase this value, because I figured 0.1mm wasn’t enough.

Anyhow, I wrongly thought that the values that the creator of the theme had set were right. Maybe they were, for whatever use the creator had in mind when he made this theme. We shall never know.

So, after this joyous experience, I had some other minor run ins with LaTeX, amidst then I finished my template for slides, I created a template for abstract for an event I’m helping to organize here and I had to convert a .tex file into a .docx, which was as fun as it sounds. None of which were interesting enough to document here.