feat: link contents to .ipynb and expand LaTeX macros before conversion - #12
Merged
Merged
Conversation
- 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>
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.
Summary
Three related changes to how the downloadable
.ipynbfiles are produced and linked.1. "Contents" links now point to the
.ipynb, not the.mdIn
basic_lessons/README.md, the Contents and Exercise Answers tables linked tolesson*_tutorial.md/lesson*_exercise_answers.md. Readers were taken to the rawMarkdown source instead of the executable notebook. All 11 links now point at the
generated
.ipynbfiles (matching whatmyst.yml's TOC already uses).2. New
convert_to_ipynb.py:.md→ intermediate.md→.ipynbwith macros expandedThe lessons use custom LaTeX macros (
\myvec,\mymatrix,\quat,\dual, defined inmyst.ymlunderproject.math). MyST expands them at build time via KaTeX, but moststandalone
.ipynbrenderers (JupyterLab, VS Code, nbviewer, …) do not know thesemacros and would show them literally. The new script implements a two-step pipeline:
myst.ymland expands them into a transient<stem>_expanded.md, then runsjupytexton that file. The resulting.ipynbcontains only standard LaTeX and renders anywhere; you keep writing the original
.mdwith the convenient macros.renders: braced arguments (including nested braces like
\mymatrix{H^{-1}}), singlespace-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.--keeptoinspect 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
jupytextconversion; and alocal
myst buildcompletes with 0 warnings (17 pages built).3.
AGENTS.mdupdatedDocuments the two-step pipeline, the reason for it, the new local/CI build commands,
the
.ipynbcontents-link convention, the macro/code-cell caveat, and the new*_expanded.mdbuild artifact.CI
The "Generate downloadable notebooks" step in
.github/workflows/notebook_to_html.ymlnow runs
python convert_to_ipynb.py(withpyyamladded to its deps) instead of theold inline
jupytextloop.