When rendering inline math equations, the left and right content will be separated into different <p> s. Is this expected? Is there a way to output it in the same <p> (or simply not wrap the <p> )?,
When using cetz, the math equations in the content disappears. How can I make it display?
This is likely because html.frame isn’t an inline element (only text decoration elements and horizontal spacing are inline), so it interrupts paragraphs, similarly to e.g. image outside of html export. You’ll need to wrap them in a box for inline equations:
That’s because you’re wrapping the canvas in a frame, causing the canvas to be exported as SVG, and then the show rule wrapping equations in html.frame is being applied, which has no effect in SVG export (only in HTML export).
You’ll need to ensure the show rule is not applied inside a CeTZ canvas. One way to do this involves state:
#let in-canvas = state("in-cetz-canvas", false)
#show math.equation: it => context {
if in-canvas.get() { it } else { html.frame(it) }
}
#show math.equation.where(block: false): box
#let canvas(..args) = {
in-canvas.update(true)
html.frame(cetz.canvas(..args))
in-canvas.update(false)
// NOTE: this simplified version assumes you won't
// create a canvas inside a canvas.
}
Here’s a more flexible solution which ought to work in more situations (not only in a CeTZ canvas):
#show math.equation: it => context {
// only wrap in frame on html export
if target() == "html" {
// wrap frames of inline equations in a box
// so they don't interrupt the paragraph
show: if it.block { it => it } else { box }
html.frame(it)
} else {
it
}
}
Replacing the original math equation show rule in your post’s example code with the code above is enough to fix both problems.
Well, I know this way of writing, but similar encapsulation is needed for every packages. What I really want is a piece of “prelude” code that can be applied to any HTML rendering scenario and is no different in use from other environments. The #show math.equation above achieves this perfectly , but the #let canvas here doesn’t (because I can’t include every package, and I can’t prevent users from using the cetz.canvas directly).