Skip to content
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

[GH-1509] Add support for Latex rendering in markdown cells #1755

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cphyc
Copy link

@cphyc cphyc commented Nov 4, 2021

This adds support for displaying inline and displayed Latex equations using Katex in markdown cells, fixing #1509.

The conversion happens before each paragraph is converted from markdown to HTML. At the moment, any parsing error thrown by KaTeX is caught and the chunk ignored. In other words, the following $\thisisinvalid$ will render as-is, including the surrounding $.

Demonstration

Markdown editor

Screenshot from 2021-11-04 11-02-18

Automatic rendering when leaving the editor

image

@mattermod
Copy link
Contributor

Hello @cphyc,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

Per the Mattermost Contribution Guide, we need to add you to the list of approved contributors for the Mattermost project.

Please help complete the Mattermost contribution license agreement?
Once you have signed the CLA, please comment with /check-cla and confirm that the CLA check is green.

This is a standard procedure for many open source projects.

Please let us know if you have any questions.

We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team.

@cphyc
Copy link
Author

cphyc commented Nov 4, 2021

/check-cla

const paragraphRenderer = renderer.paragraph
renderer.paragraph = (txt:string) => {
const newTxt = txt.replace(
/\$\$([^\$]*)\$\$/g,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewer: this only matches expressions like

$$ x = y $$  # will be matched
\( x = y \)  # won't be

A discussion to have is whether we want things like

This is a very long line that contains a display equation in the middle. $$ x= y$$, does it even make sense to do that?

At the moment this is rendered as follows
image

@cphyc cphyc force-pushed the support-latex branch 2 times, most recently from ae43b05 to a6cb259 Compare November 4, 2021 13:00
@cphyc cphyc marked this pull request as ready for review November 4, 2021 14:50
@cphyc cphyc requested a review from a team as a code owner November 4, 2021 14:50
@cphyc cphyc requested review from sbishel and chenilim and removed request for a team November 4, 2021 14:50
@sbishel sbishel requested review from jespino and removed request for sbishel and chenilim November 9, 2021 22:06
@jespino
Copy link
Contributor

jespino commented Nov 22, 2021

@cphyc We are evaluating how is the best way to handled this. sorry for the delay answering, but let me think a bit more about it and we can decide if we merge it or try to incorporate the existing code from mattermost.

@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @jfrerich @emilyacook

@jespino
Copy link
Contributor

jespino commented Dec 13, 2021

Sorry, I still have to take a look into this.

@cphyc
Copy link
Author

cphyc commented Feb 18, 2022

Any news on this front?

@cphyc
Copy link
Author

cphyc commented Oct 26, 2022

Hi, this has been almost a year. Is there any hope of getting this merged or should I close the PR?

Use built-in KaTeX error handling

Swallow HTML line break that immediately follows latex displays

This allows the equation to stay in the same paragraph (consistently with Latex behaviour)

Update package-lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants