List

What are Ligature Fonts?

To quote the Fira Code README:

Problem

Programmers use a lot of symbols, often encoded with several characters. For the human brain, sequences like ->, <= or := are single logical tokens, even if they take two or three characters on the screen. Your eye spends a non-zero amount of energy to scan, parse and join multiple characters into a single logical one. Ideally, all programming languages should be designed with full-fledged Unicode symbols for operators, but that’s not the case yet.

Solution

Fira Code is a free monospaced font containing ligatures for common programming multi-character combinations. This is just a font rendering feature: underlying code remains ASCII-compatible. This helps to read and understand code faster. For some frequent sequences like .. or //, ligatures allow us to correct spacing.

Here are some of my favorite Fira Code ligatures for R.

Assignment operators

x <- 10 becomes

23 -> y becomes

Relational operators

x <= y becomes

x >= y becomes

x == y becomes

x != y becomes

Native pipe operator

x |> sqrt() becomes


Step 1: Install the Fira Code Font Family

Windows

a) Go to https://github.com/tonsky/FiraCode/releases/latest
b) Download the Fira_Code_vX.X.zip file
c) Extract all the zipped files to a folder on your computer
d) Open the extracted folder and open the ttf subfolder
e) Highlight all files in the tff subfolder
f) Right-click on one of these highlighted files to open the context menu
g) Select “Install” from the context menu

MacOS

  • Follow the same instructions 1(a) to 1(f) from Windows
  • Select “Open” or “Open with Font Book” from the context menu
  • Select “Install Font”

Linux

Animation showing how to install the Fira Code font family on Windows


Step 2: Change the RStudio Editor Font

a. In RStudio, open the “Tools” menu and select “Global Options…”

b. Select the “Appearance” tab and change the “Editor Font” to Fira Code.

c. Click the “OK” button.

Animation showing how to change the RStudio Editor Font to Fira Code


Step 3: Using Ligatures in RStudio

Now, certain character combinations will automatically be transformed into beautiful ligatures as you type them. The best part is that, although the ligatures may appear to be one character, they are still represented in your files as the individual characters and thus can still be edited without problem.

Animation showing the use of ligatures in RStudio


RStudio Screenshots taken using Windows version 2022.02.3+492 “Prairie Trillium”

Leave a Reply

Your email address will not be published.

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