Skip to content

five_preferences: downloadable notebook cannot run in Colab — usetex=True requires a system LaTeX the runtime does not have #377

Description

@mmcky

The wave-C2 migration (#375, publish-2026aug18) fixed the reason the downloadable five_preferences.ipynb could not run — the loadmat('dataBHS.mat') read against a file the site never served. A human Colab run on 2026-08-18 (the in-browser check requested on QuantEcon/data-lectures#84) confirms the notebook now gets past setup and into execution, and then surfaces a second, older blocker that is specific to Colab:

RuntimeError: Failed to process string with tex because latex could not be found
<Figure size 1600x700 with 2 Axes>

Cause. The notebook's rc-params cell sets plt.rc('text', usetex=True), which makes matplotlib shell out to a system latex binary for every rendered text string. Colab's runtime ships no LaTeX distribution, so the first figure that renders text — the entropy contour pair, figsize=(16, 7), matching the 1600x700 with 2 Axes in the traceback — raises, roughly 50 cells before the lecture's data read. Since Colab's "Run all" stops at the first error, a Colab reader never reaches the repointed read_csv cell at all.

Why only this lecture. five_preferences.md is the only lecture in this repo that sets usetex=True (checked 2026-08-18 across lectures/*.md). The published site is unaffected — CI installs texlive — and so is any local jupyter with a TeX distribution, which is why the notebook executes end-to-end outside Colab (verified with nbclient, 66 cells, 0 errors, on the QuantEcon/data-lectures#100 validation). The failure is exactly scoped to the "open in Colab" path.

Not a migration regression: the setting predates the wave-C2 work, and a Colab run would have failed at the same cell before it. The migration just removed the blocker that used to sit in front of this one.

Options, in the order I would consider them:

  1. Guard the setting so it degrades instead of raising: plt.rc('text', usetex=bool(shutil.which('latex'))). The published site keeps its current typography (CI has texlive); Colab and other latex-less runtimes fall back to matplotlib's mathtext, which handles the lecture's $…$ labels with slightly different rendering but the same content.
  2. Drop usetex=True for mathtext everywhere. Simplest, and consistent with the rest of the repo (no other lecture uses it), but the published figures' typography changes and would want a visual once-over.
  3. Have the notebook install texlive in Colab. Not recommended — several minutes of apt on every Colab session for typography.

The byte-identical five_preferences.md in lecture-tools-techniques carries the same setting twice, so its notebook has both this blocker and the original .mat one — noted on QuantEcon/lecture-tools-techniques#11 so the two get fixed together there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions