[PR #1894] [MERGED] fix(book): render pseudocode algorithms and contain their overflow #36511

Closed
opened 2026-07-16 00:24:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 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)

  • b86319b fix(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 defer and no KaTeX. So at the moment renderElement ran, no math backend existed yet and it threw:

Uncaught EvalError: No math backend found. Please setup KaTeX or MathJax.

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 _dev site, 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-container had no overflow handling, so a long algorithm line (e.g. the \Require … signature) pushed the whole page sideways. Scoped overflow-x: auto to 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 |
Screenshot 2026-06-24 105451

| After |
Screenshot 2026-06-24 105441

MathJax confirmed working independently (847 mjx-container elements 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.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1894 **Author:** [@farhan523](https://github.com/farhan523) **Created:** 6/24/2026 **Status:** ✅ Merged **Merged:** 6/24/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `dev` ← **Head:** `fix/pseudocode-math-backend-and-overflow` --- ### 📝 Commits (1) - [`b86319b`](https://github.com/harvard-edge/cs249r_book/commit/b86319b0802f191b8fc518cb010fdbaab38eb621) fix(book): render pseudocode algorithms and contain their overflow ### 📊 Changes **2 files changed** (+61 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `book/quarto/_extensions/mlsysbook-ext/pseudocode/pseudocode.lua` (+45 -26) 📝 `book/quarto/assets/styles/_base-styles.scss` (+16 -0) </details> ### 📄 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 `defer`** and no KaTeX. So at the moment `renderElement` ran, no math backend existed yet and it threw: ``` Uncaught EvalError: No math backend found. Please setup KaTeX or MathJax. ``` 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 `_dev` site**, 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-container` had no overflow handling, so a long algorithm line (e.g. the `\Require …` signature) pushed the whole page sideways. Scoped `overflow-x: auto` to 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 | <img width="788" height="107" alt="Screenshot 2026-06-24 105451" src="https://github.com/user-attachments/assets/325c0982-00b4-40c0-8e29-98a0b406e614" /> | After | <img width="773" height="671" alt="Screenshot 2026-06-24 105441" src="https://github.com/user-attachments/assets/6a8d9184-84d8-4f71-a216-63d3f2620f78" /> MathJax confirmed working independently (847 `mjx-container` elements 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-07-16 00:24:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#36511