mystmd icon indicating copy to clipboard operation
mystmd copied to clipboard

enhancement proposal: equation numbering for SymPy cell outputs

Open cuihantao opened this issue 1 month ago • 0 comments
trafficstars

MyST currently supports labeling and referencing equations that are authored in Markdown math blocks and it supports labeling notebook cells to embed or reference their outputs (including figures) by cell label. However, there is no first-class, documented way to label and reference equations that are generated as math outputs from code cells (e.g., SymPy pretty-printed LaTeX).

This proposal introduces a minimal, MyST-native syntax to label, number, and cross-reference such programmatically generated equation outputs, in parity with existing figure-output workflows and consistent with the cross-reference and numbering model described in the documentation Cross-references.

Proposal

Allow a labeled code cell to become an equation target purely via its label if the backend detects an equation output.

Example authoring:

#| label: eq-power-balance
from sympy import Eq, symbols
P_i, P_load = symbols('P_i P_load')
Eq(P_i, P_load)  # or any SymPy object that renders to LaTeX math

Expected behavior:

  • Auto-detect equation-like outputs (e.g., SymPy Eq or text/latex math) as the primary output.
  • Register eq-power-balance as an equation target (not a figure), numbered under numbering.equation and honoring project/page numbering settings.
  • Enable references: [Equation %s](#eq-power-balance)
  • If no math-like output is found, treat it as a labeled cell.
  • If multiple math outputs exist, use the first by default. Discourage multiple math outputs in one cell. Users should label each equation in a new cell.

Additional notes

This mirrors the simplicity of referencing labeled cell outputs while giving equations first-class semantics. This was briefly discussed on Discord. https://discord.com/channels/1083088970059096114/1126886232060870678/1420489507580416116

cuihantao avatar Oct 12 '25 17:10 cuihantao