From 7045c7a5aa6744538b19eedd3fe9292ce2bb8e7c Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Wed, 19 Aug 2026 09:16:33 +1000 Subject: [PATCH] five_preferences: enable usetex only where a latex binary exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only usetex lecture in the repo. Colab ships no LaTeX, so the downloadable notebook raised at the first rendered figure (~50 cells before the data read the wave-C2 repoint fixed). shutil.which('latex') keeps the published site's typography — CI installs texlive — and lets latex-less runtimes fall back to mathtext. Co-Authored-By: Claude Fable 5 --- lectures/five_preferences.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lectures/five_preferences.md b/lectures/five_preferences.md index 8068c139..d565a3bd 100644 --- a/lectures/five_preferences.md +++ b/lectures/five_preferences.md @@ -54,6 +54,7 @@ We begin with some that we'll use to create some graphs. ```{code-cell} ipython3 # Package imports +import shutil import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt @@ -67,7 +68,10 @@ from numba import njit ```{code-cell} ipython3 :tags: [hide-input] -plt.rc('text', usetex=True) +# Render text with LaTeX only where a latex binary exists (the build has +# texlive); on latex-less runtimes such as Colab, fall back to mathtext +# instead of raising at the first rendered figure. +plt.rc('text', usetex=bool(shutil.which('latex'))) plt.rc('font', size=18) plt.rc('axes', labelsize=20, titlesize=24) plt.rc('xtick', labelsize=18)