Skip to content

feat: native Office Math authoring and formula rendering in the preview #490

Open

Description

@hyskr

Problem

I author research presentations in TSX using the local preview. Slides need fractions, sums with limits, roots, and matrices that remain native editable equations in the exported PPTX.

Currently I keep LaTeX in named text boxes while authoring, then replace those paragraphs with Office Math after export. The resulting formula objects survive an Office Kit load/save round trip, but their formula content is absent from the SVG preview. This leaves the authoring preview and exported artifact inconsistent.

Existing paths considered

  • Text / setShapeText: suitable for the editable LaTeX source, but ordinary text does not typeset mathematical structure.
  • Image: a rendered formula can be displayed, but does not provide a native equation object to edit downstream.
  • Raw: exposes public core APIs; I could not find a public Office Math authoring function in the installed packages or the current src/api/index.ts exports.
  • Export post-processing: I tried the standalone latex2omml.py converter from maenjh/pptx-math, inserting a14:m > m:oMath into the named text box's a:p, before a:endParaRPr.

The tested formulas were:

\sigma(z)=\frac{1}{1+e^{-z}}
L=\sum_{i=1}^{n}(y_i-\hat{y}_i)^2
A=\begin{pmatrix}a & b \\ c & d\end{pmatrix}
x=\frac{-b+\sqrt{b^2-4ac}}{2a}

On this one-slide fixture, the shape count stayed at 11, and four m:oMath nodes remained after loadPresentation → savePresentation. validatePresentation returned no issues. renderSlideToSvg retained the surrounding Chinese headings and labels but omitted the four formula bodies. These are package/XML and SVG observations; I have not verified the output's visual layout or equation editing in a desktop presentation application.

Tested versions: @office-kit/pptx 0.28.0, @office-kit/pptx-dsl 0.15.0, @office-kit/pptx-preview 0.21.0; Node.js 22.23.2 on macOS. The public API check also included the current main-branch exports.

Proposed solution

Add a core path for authoring and reading native Office Math in text paragraphs, with the preview displaying supported math structures. A bounded subset covering fractions, scripts, radicals, n-ary operators, and matrices would cover this use case.

The input could be OMML, leaving LaTeX conversion to a caller-supplied tool rather than adding a full TeX engine to the core. For example, an API shaped like this would let Raw use the same core implementation:

// Illustrative API, not an existing export.
setShapeMath(shape, { omml: '<m:oMath xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">…</m:oMath>' });

The important behavior is that the exported paragraph contains the native math object and the local preview shows its mathematical content. Unsupported structures should be identified clearly rather than appearing as an empty formula region.

Alternatives

Keeping the current LaTeX text-box source is workable for editing the source, but the author cannot review typeset formulas alongside the rest of the slide. Rendering formulas to images provides a visual preview but loses native equation editing. Post-processing preserves native math in the file, but requires a separate export path and currently leaves a gap in the Office Kit preview.

Scope and compatibility

This can be additive. I am not asking for another general text API, a full LaTeX compiler, or automatic conversion of prose into formulas. Supporting native Office Math through one core API, then using it from the DSL/preview, would be sufficient. Existing pass-through preservation should continue to work.

Confirmation

  • I have read the project's "one way to do one thing" policy and confirmed
    this proposal is not a parallel path to an existing capability.
  • I have searched existing issues (open and closed) and confirmed this is
    not a duplicate.
  • I have a real, specific use case for this — not a hypothetical "could be
    useful."
  • If I used an LLM to draft this issue, I have read and verified every
    claim, including the "existing paths" section, and am willing to defend
    the proposal in follow-up.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions