mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-11-16 12:05:12 -06:00
[PR #1894] [MERGED] fix(book): render pseudocode algorithms and contain their overflow #36511
Reference in New Issue
Block a user
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1894
Author: @farhan523
Created: 6/24/2026
Status: ✅ Merged
Merged: 6/24/2026
Merged by: @profvjreddi
Base:
dev← Head:fix/pseudocode-math-backend-and-overflow📝 Commits (1)
b86319bfix(book): render pseudocode algorithms and contain their overflow📊 Changes
2 files changed (+61 additions, -26 deletions)
View changed files
📝
book/quarto/_extensions/mlsysbook-ext/pseudocode/pseudocode.lua(+45 -26)📝
book/quarto/assets/styles/_base-styles.scss(+16 -0)📄 Description
Summary
Fixes two HTML-output bugs affecting every algorithm block across both volumes (first surfaced on
vol1/nn_computation).1. Algorithms render as raw LaTeX instead of typeset pseudocode
pseudocode.js's init script ran synchronously at parse time, but the book renders math with MathJax loaded via
deferand no KaTeX. So at the momentrenderElementran, no math backend existed yet and it threw:The raw
\begin{algorithm}…source was left on the page and never retried (MathJax loads moments later and typesets the rest of the page, but the algorithm init had already failed). Reproduced on the live_devsite, so this is a production bug, not a local artifact.Fix: wait for the math backend to be ready before rendering — KaTeX if present synchronously, otherwise MathJax's
startup.promise(available after the deferred MathJax script runs).2. Wide algorithms force page-level horizontal scroll
The rendered
.pseudocode-containerhad no overflow handling, so a long algorithm line (e.g. the\Require …signature) pushed the whole page sideways. Scopedoverflow-x: autoto the container so it scrolls in its own box — same failure mode and fix as the existing wide-table rule directly above it.Verification
Rendered the page and drove headless Chrome against the output:
| | Before |

| After |

MathJax confirmed working independently (847
mjx-containerelements rendered), isolating the failure to pseudocode init timing.Scope
Both files are shared across all chapters and both volumes, so this repairs every algorithm block — not just the one page.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.