LaTeX Tips

Below I’ve recorded a few LaTeX tips which don’t often appear in a first tutorial but I still wish I’d known earlier. There are also some personal preferences which improve readability (for me personally).

Syntax imposters

Some commands produces the symbols you want when there’s a preferred variant (which may produce subtle differences). As a result, I bet that in some cases below the suggestion may be the “approved” option without being the most commonly used!

The below produce marginal differences in spacing:

On the topic of spacing, a space following a . is interpretted as the end of a sentence. That gives the incorrect spacing when we have a mid-sentence abbreviation like “Dr.” or “e.g.” (although arguably an “e.g. " should usually be an “e.g., " anyway, in which case the spacing issue won’t occur):

If you have a “tall” equation then the standard brackets will be too short:

There are various kinds of dashes that should be typeset differently, the hyphen, en-dash and em-dash:

Writing display equations (as opposed to inline equations):

Characters are cheap

For me, cramped LaTeX code is a pain to read. It doesn’t cost anything to add extra spaces or tabs, which can give the code some more room to breathe. Readability should be favoured over character count:

Of course, when referring to numbered theorems, sections etc., you should use labels, so that any reordering won’t mess up your references:

Macros

I should probably use more macros. They can both improve readability and, of course, save time:

Folder structure

Especially for bigger projects (see also below on course note recommendations), having a sensible folder/file structure can keep things more organised.

Course material maintenance

Courses can easily consist of 50 or more documents: workshop sheets, lecture notes/slides, problem sheets, their solutions, formula sheets, the booklet of course information,….

If any contain year-specific data then this forces an unnecessary and incredibly tedious waste of time scanning for such updates at the beginning of a new term. I don’t intend to promote a “set it then forget it” approach of rarely updating course material, which we should try to improve on each iteration. But realistically, a lot of material will be re-used. Is fishing through for these simple changes each year (crossing fingers that none are missed) really the best way to motivate improvements to the material? Probably not.

I’m thinking of year-specific data like:

Wouldn’t it be great if there was a simple list of all of the data that might need to change between years, and editing this made the necessary updates to all other files? It’s easy to do with LaTeX using sty files:

  1. If upgrading an old set of materials, go through each tex file to find data which will (or merely might) need updating between iterations. If starting on a new set of notes, of course just do this from the outset: replace the year-dependent data with a descriptive command, like \spring_exam_date or \lecturer_name. These should then be defined in the preamble of the tex file: \newcommand{\spring_exam_date}{30\textsuperscript{th} January 2020} or \newcommand{\lecturer_name}{Prof.\ Smartypants}. Make sure everything still compiles.

  2. Next, cut all of these \newcommands (from all tex files of your course) into a single sty file; call it variables.sty or something. I tend to put this file in a subfolder year_dependent from the root folder of the course.

  3. Your tex files need to know where to look for these commands. Add \usepackage{../../year_dependent/variables} to the preamble of each which needs access, where the number of ../ is just how many folders back you need to go to the root folder.

Voilà! Now at the start of the year, just update that small sty file and when recompiling each file you’ll get the new version (I should now look up LaTeX makefiles, to find an easy way of recompiling an entire project). This is far less tedious than scouring numerous files for outdated culprits, and it even only takes marginally longer to implement the first time (and hence pays big dividends already by the second).

Some further tips on course folder structure:

Putting all of the above together, our course will have something like the following folder structure:

course
├──booklet
├──lecture_slides
│   │   └──images
│   │       └──svgs 
│   ├──1
│   ├──2
│   └──...
├──problem_sheets
│   ├──questions
│   │  ├──1
│   │  ├──2
│   │  └──...
│   └──solutions
│      ├──1
│      ├──2
│      └──...
├──sty_static
└──year_dependent
├──workshops
│   ├──sheets
│   │  ├──1
│   │  ├──2
│   │  └──...
│   └──solutions
│      ├──1
│      ├──2
│      └──...
├──...

In the above, sty_static holds the sty files for preambles and macros (such as for maths notation). The folder year_dependent contains everything we need to edit for a new year: the variables.sty file and maybe some individual files that might need updating (like image files for QR codes to student participation activities).

In case it helps a single soul, I’ve started a very basic template implementing the above.

Simple Beamer slides

Maths talk/lecture slides are often made on Beamer. I regularly see the bottom navigation symbols displayed but have never seen them used:

Purely personal preference: I prefer slides to be clean and minimal. I’d rather the important content be drawing the attention than a busy frame. Here’s a template for some simple, adaptable slides.