-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Math is not rendered in Library Card previews #1508
Comments
@ormsbee I've been thinking along similar lines, but I would prefer we start with a much simpler conversion from mathjax syntax to plain text. Then we don't need to add support for rendering HTML into the cards. For example, preview snippet: Rendered in the card as plain text: 𝑋 ∼ 𝑓(𝑥) = (1/2𝑏)𝑒^(𝑖𝜋) This can [hopefully?] be implemented with a series of simple |
Also, keep in mind that the snippets are truncated along word boundaries and in some cases that may result in invalid LaTeX code in the description. That's why I think doing the conversion to plain text before even indexing it is great - it's simple, robust, and increases the information density of the description. |
I realized that rendering the HTML would make it more vulnerable to injection attacks, but I had thought that it was okay because we strip tags before generating the searchable description–so this would be adding MathML to what was essentially plain text at that point. I didn't realize that the snippets would get truncated on word boundaries like that and break formatting. I had hoped that we could output all the MathML and show a limited window into it. 😞 The one thing that gives me pause about the approach you're proposing is that it seems like it's getting very close to re-inventing AsciiMath.
So depending on how complex the |
Absolutely. No need to reinvent the wheel. Though you can get much nicer output by using Unicode math characters rather than just ASCII. There's also https://www.unicodeit.net/ / https://github.com/svenkreiss/unicodeit which is a python library to do exactly this, though it doesn't seem to support |
Problems and HTML blocks can both take advantage of MathJax to render math. This works in the preview sidebar, but the raw markup is presented in the preview description on the card:
This makes the preview much less useful.
Suggested Approach: MathML conversion
MathJax is slow to load, and has long been a performance pain point in the courseware. While it has some very nice features, we don't need that much in the preview cards. Meanwhile, MathML has now become broadly supported by modern browsers.
Markup for MathJax in platform is supposed to use the following guidelines:
\( equation \)
or[mathjaxinline] equation [/mathjaxinline]
notation.\[ equation \]
or[mathjax] equation [/mathjax]
notation.The input text format for equation can be LaTeX or AsciiMath. Python libraries exist to convert from those formats to MathML:
Using that, we should be able to convert the content to MathML when search indexing happens for a document in edx-platform. So something like:
... but generalized to handle the different formats and tag delimiters.
Acceptance criteria:
[mathjaxinline]{unparseable}[/mathjaxinline]
would return as{unparseable}
. We never want to break search indexing, and showing the delimiters in the preview is unhelpful.It is likely that this won't support every edge case that MathJax handles, but it should hopefully give us the majority of the benefit with minimal overhead. We can also use information gathered from this in order to see where server-side handling of these things is incomplete, to inform any future steps we might take around doing backend conversion for rendering equations in courseware.
The text was updated successfully, but these errors were encountered: