five_preferences: enable usetex only where a latex binary exists - #378
Merged
Conversation
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 <noreply@anthropic.com>
✅ Deploy Preview for lustrous-melomakarona-3ee73e ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents matplotlib from erroring in LaTeX-less runtimes (e.g., Google Colab) by enabling usetex=True only when a latex binary is available, while preserving the existing TeX-rendered typography on the published site where TeX is installed.
Changes:
- Import
shutilinfive_preferencesto enable runtime detection of thelatexexecutable. - Replace unconditional
plt.rc('text', usetex=True)with a guardedplt.rc('text', usetex=bool(shutil.which('latex'))). - Add an explanatory comment describing the Colab fallback behavior.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
40 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Option 1 from the issue: guard the rc setting with
shutil.which('latex')so the published site keeps its current typography (CI installs texlive and renders exactly as before) while Colab and other latex-less runtimes fall back to matplotlib's mathtext instead of raisingRuntimeError: Failed to process string with texat the first rendered figure. This was the last blocker on the "open in Colab" path for the downloadablefive_preferences.ipynb— the 2026-08-18 human Colab run got past the repointed data read and died here.This lecture is the only
usetex=Trueuser in the repo (checked 2026-08-18 acrosslectures/*.md). The byte-identical copy in lecture-tools-techniques carries the same setting twice and gets the same guard together with its.matrepoint — see QuantEcon/lecture-tools-techniques#11.After this publishes, a clean human Colab run of the downloadable notebook closes the last box on QuantEcon/data-lectures#84.
Closes #377
🤖 Generated with Claude Code