diff --git a/proposals/1722-math.md b/proposals/1722-math.md new file mode 100644 index 00000000000..ad92e5b143f --- /dev/null +++ b/proposals/1722-math.md @@ -0,0 +1,207 @@ +# Support for displaying math(s) in messages + +Some users need to communicate using mathematical notation. Matrix should +provide a common format for sending mathematical notation so that users using +different clients can communicate with each other. + +This proposal defines a format for sending messages with mathematical +notation. Note that it does not define how to input mathematical notation; +clients are free to use different input methods, as long as they can generate +the required message format. + +See also: + +- https://github.com/vector-im/riot-web/issues/1945 + +## Proposal + +The HTML subset supported by Matrix in the `formatted_body` property of +messages with `"format": "org.matrix.custom.html"` will be extended to support +[Presentation MathML](https://www.w3.org/TR/MathML3/chapter3.html). +Presentation MathML is used rather than Content MathML because Presentation +MathML seems to be better supported. Other markup formats can be transmitted +along with the MathML using the [Annotation +framework](https://www.w3.org/TR/MathML3/chapter5.html). + +In other words, let HM be the HTML subset currently supported +by Matrix in the `formatted_body` property of messages with `"format": +"org.matrix.custom.html"`, and let MP be Presentation +MathML. We propose to extend the HTML subset supported by Matrix by allowing +clients to support +HM=HMMP. (Note +that AMP, where A is the Annotation +framework.) + +Clients should replace the mathematical notation with something more +human-readable in the `body` property of the message. However, this proposal +does not specify what form this should take. + +Example (with line breaks and indentation added to `formatted_body` for clarity): + +```javascript +{ + "content": { + "body": "This is an equation: sin(x)=a/b", + "format": "org.matrix.custom.html", + "formatted_body": "This is an equation: + + + sinx=ab + \\sin(x)=\\frac{a}{b} + + sin(x)=ab + + + ", + "msgtype": "m.text" + }, + "event_id": "$eventid:example.com", + "origin_server_ts": 1234567890 + "sender": "@alice:example.com", + "type": "m.room.message", + "room_id": "!soomeroom:example.com" +} +``` + +## Other solutions + +* LaTeX (or LATEX): LaTeX is a popular method for writing + mathematical texts, and is fairly readable. However, "LaTeX" is not a single + format; there are several popular extensions such as AMS-LaTeX that different + implementations may or may not support. There are also certain (La)TeX + commands that should probably not be supported, such as `\newcommand`, as it + could be used create an infinite loop, which may crash an implementation that + is not sufficiently careful. (La)TeX is Turing complete, which is, from a + security standpoint, not a good property for transmitting documents. + Therefore using LaTeX as the format for sending mathematical notation in + Matrix events would require specifying which (sub|super)set of LaTeX should + be supported. + + An alternative to specifying the set of supported commands may be to allow + clients to send arbitrary LaTeX, and if it contains a command that the + receiving client does not support, then the receiving client should fall back + to displaying the raw LaTeX, relying on the readability of LaTeX and/or the + fact that people who are communicating about more complicated mathematics are + likely to be able to understand the requisite LaTeX. This may give an + inconsistent user experience, but would also provide clients that are unable + to support proper display of mathematics with an easy fallback. This also + does not address security concerns, and it would be up to client authors to + ensure that their code for displaying mathematics, or the library that they + use, is not vulnerable to any potential attacks. + + If LaTeX is used, then it must be delimited in some way, most likely by + wrapping it in some element. One option would be to use a custom + Matrix-specific element such as `` (this is similar to how replies + use the `` element). Other options include using a `` with a + custom class (such as ``), or a `