Skip to content

feat: link contents to .ipynb and expand LaTeX macros before conversion - #12

Merged
mmmarinho merged 1 commit into
mainfrom
feat/ipynb-links-and-macro-expansion
Aug 19, 2026
Merged

feat: link contents to .ipynb and expand LaTeX macros before conversion#12
mmmarinho merged 1 commit into
mainfrom
feat/ipynb-links-and-macro-expansion

Conversation

@mmmarinho

Copy link
Copy Markdown
Contributor

Summary

Three related changes to how the downloadable .ipynb files are produced and linked.

This PR was created by an AI agent (OpenHands) on behalf of the repository owner.

1. "Contents" links now point to the .ipynb, not the .md

In basic_lessons/README.md, the Contents and Exercise Answers tables linked to
lesson*_tutorial.md / lesson*_exercise_answers.md. Readers were taken to the raw
Markdown source instead of the executable notebook. All 11 links now point at the
generated .ipynb files (matching what myst.yml's TOC already uses).

2. New convert_to_ipynb.py: .md → intermediate .md.ipynb with macros expanded

The lessons use custom LaTeX macros (\myvec, \mymatrix, \quat, \dual, defined in
myst.yml under project.math). MyST expands them at build time via KaTeX, but most
standalone .ipynb renderers (JupyterLab, VS Code, nbviewer, …) do not know these
macros and would show them literally. The new script implements a two-step pipeline:

basic_lessons/*.md  ->  <stem>_expanded.md  (macros expanded)  ->  basic_lessons/*.ipynb
  • Reads the macro definitions from myst.yml and expands them into a transient
    <stem>_expanded.md, then runs jupytext on that file. The resulting .ipynb
    contains only standard LaTeX and renders anywhere; you keep writing the original
    .md with the convenient macros.
  • Expansion mirrors KaTeX/TeX macro semantics so it exactly matches what the site
    renders: braced arguments (including nested braces like \mymatrix{H^{-1}}), single
    space-separated tokens (e.g. \myvec H_{0'}^{0}), and no-argument macros (\dual).
  • {code-cell} bodies are left untouched, so Python source/comments are never corrupted.
  • The intermediate file is a build artifact: deleted after conversion (use --keep to
    inspect it); not tracked and not in the TOC.

Verified: all 11 generated notebooks contain 0 macro tokens; all 295 math blocks
render cleanly in KaTeX without any macro definitions (the way a generic renderer
would see them); code cells are byte-identical to a plain jupytext conversion; and a
local myst build completes with 0 warnings (17 pages built).

3. AGENTS.md updated

Documents the two-step pipeline, the reason for it, the new local/CI build commands,
the .ipynb contents-link convention, the macro/code-cell caveat, and the new
*_expanded.md build artifact.

CI

The "Generate downloadable notebooks" step in .github/workflows/notebook_to_html.yml
now runs python convert_to_ipynb.py (with pyyaml added to its deps) instead of the
old inline jupytext loop.

- Point the "Contents" and "Exercise Answers" tables in basic_lessons/README.md
  at the generated .ipynb files instead of the .md sources, so readers land on
  the executable notebooks.
- Add convert_to_ipynb.py: a two-step .md -> intermediate.md -> .ipynb pipeline
  that first expands the project.math LaTeX macros (myvec/mymatrix/quat/dual)
  into an intermediate .md, then runs jupytext on that file. Most .ipynb
  renderers cannot draw custom macros, so the generated notebooks now contain
  only standard LaTeX and render anywhere. The intermediate file is a transient
  build artifact (deleted after conversion; --keep retains it).
  Expansion mirrors KaTeX/TeX macro semantics (braced args incl. nested
  braces, single space-separated tokens, no-arg macros) and leaves
  {code-cell} bodies untouched so Python source is never corrupted.
- Wire the script into the CI "Generate downloadable notebooks" step.
- Document the new pipeline in AGENTS.md.

Co-authored-by: openhands <openhands@all-hands.dev>

@mmmarinho mmmarinho left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mmmarinho
mmmarinho marked this pull request as ready for review August 19, 2026 05:06
@mmmarinho
mmmarinho merged commit 99a4d60 into main Aug 19, 2026
4 checks passed
@mmmarinho
mmmarinho deleted the feat/ipynb-links-and-macro-expansion branch August 19, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants