Expand description
Math messages: a formula rendered to a PNG by the mxblocks-math
program (packages/mxblocks-math/ in this repository) and sent as an m.image.
The renderer’s contract: mxblocks-math render [--inline] --out PATH.png -
with the LaTeX on stdin, exit 0 and one JSON line on stdout
({"mimetype":"image/png","w":W,"h":H,"size":BYTES}, w/h the display
size of a 2x PNG); non-zero with the TeX error on stderr. Any program
that keeps it works (Renderer::new takes its path).
The event (math_content): msgtype: m.image with the upload’s url
and info, filename: math.png, body the raw LaTeX (readable on
clients that render nothing), formatted_body MSC2191 markup
(maths_html: <div data-mx-maths="…"><code>…</code></div>, a
<span> inline, which Element’s LaTeX labs flag renders). The sender
adds the mxblocks payload with the math block (with_caption). A
caption goes first in body and formatted_body (a blank line, a
<p>), and on the math block as caption.
§mxblocks-tex
Math messages for mxblocks: render a formula with the
mxblocks-math program (packages/mxblocks-math/) and build the m.image event that carries
it, with MSC2191 markup (data-mx-maths) for clients that render LaTeX and
the raw TeX as the plain body.
The renderer contract: mxblocks-math render [--inline] --out PATH.png -,
TeX on stdin; exit 0 with one JSON line on stdout
({"mimetype":"image/png","w":W,"h":H,"size":BYTES}, w/h the display
size of a 2x PNG), or non-zero with the TeX error on stderr.
let r = mxblocks_tex::Renderer::new("mxblocks-math").render(r"e^{i\pi} + 1 = 0", true).await?;
// Upload r.png with your Matrix client, then pass its returned mxc URI.
let mxc = "mxc://example.org/rendered";
let content = mxblocks_tex::math_content(r"e^{i\pi} + 1 = 0", true, "", &r, &mxc, None);
assert_eq!(content["msgtype"], "m.image");Apache-2.0.
Structs§
Constants§
- DEFAULT_
MAX_ PNG - The default largest PNG accepted, in bytes.
- DEFAULT_
RENDERER - The default renderer (on
PATH). - DEFAULT_
TIMEOUT - The default time the renderer may take.
Functions§
- html_
escape - HTML-escaped
s(quotes too). - math_
content - The
m.imagecontent for a rendered formula uploaded tomxc, without the mxblocks payload (writewith_caption’s under the content key).caption: text to go with the formula, if any;reply_to: an event to reply to. - maths_
html - MSC2191 markup for
tex: adiv(display) orspan(inline) withdata-mx-mathsand the source in<code>for clients without it. - pick_
renderer - The first non-blank of
choices(an env var, a config value, …), trimmed, elsedefault. - with_
caption - The payload with the caption put on its math block (
caption, kept only when it is one line of at mostMAX_MATH_LINEcharacters, as the spec requires; a longer caption stays in the body only).