Embedding SVGs in MathML
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 56.1k
- Forks
- 1.7k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Description
Description
I am adding some HTML support to curryst: a package that produces diagrams that are useful both in and outside of math mode. I'd like to target the SVG format, rather than pure MathML, as since these proof trees are diagrams, it makes sense for them to be downloadable and portable at the cost of losing the ability to copy+paste. (See also https://github.com/lynn/typst-syntree/pull/23).
However, SVGs that are directly embedded in MathML do not render. They must be wrapped in a <semantics> and an <annotation-xml> block in somewhat of a kludgy fashion, "annotating" a non-existent MathML block. This is a little gross but idiomatic.
<math display="block">
<mi mathvariant="normal">Π</mi>
<mspace width="1em"></mspace>
<mo lspace="0em" rspace="0em">=</mo>
<mspace width="1em"></mspace>
<semantics>
<!-- this section intentionally left blank -->
<annotation-xml encoding="image/svg+xml">
<svg> ... </svg>
</annotation-xml>
</semantics>
</math>
Unfortunately, I have hit two issues in my attempts to add this support.
- There is no way (to my knowledge) to introspect upon whether some code is within math mode or within markup mode, without the use of
show math.equationand gratuitous global state (a non-starter for just adding HTML support). I'd like to be able to do something like what can be currently done withcontext target() == "html". - Typst's
html.elemdoes not support outputting reserved XML (?) names.
error: name is reserved and not valid for a custom element
┌─ curryst.typ:498:16
│
498 │ html.elem("annotation-xml", attrs: (encoding: "image/svg+xml"), html.frame(rendered-tree))
│ ^^^^^^^^^^^^^^^^
The second issue might be a genuine issue, but the first issue I'm hitting smacks of an XY problem -- I think what I'd rather just have happen, is for Typst to wrap any html.frame in <semantics><annotation-xml encoding="image/svg+xml">...</annotation-xml></semantics> when in math mode. So I'd like to open a feature request for this. But also... if there is a better way to approach this problem, I'd love to hear it.
Use Case
(see above)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the html.elem and context target() entry points, then compare how show math.equation exposes math-mode state. Determine whether HTML frames in math mode should receive the proposed semantics and annotation-xml wrapper, and how reserved XML names should be handled. Done means the SVG MathML use case works without global state and the behavior is covered by the relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100