Live data from Hacker News

Render mathematical expressions in Markdown On GitHub

github.blog

51–60 of 114 posts

Re: Render mathematical expressions in Markdown On GitHub

#51
post #45
post #8

Nice! A welcome addition! Too bad they're not using KaTeX [0] instead. It renders the maths server-side, so there's no runtime needed. An additional bonus is that the resulting math is copy-pasteable, which in the case of disply math might not be that useful (since most equations are to complex to be meaningfully copy-pasted with unicode), but it helps from inline math dissappearing when copy pasting texts. But, that…

I used to think KaTeX was far superior to MathJax but now I'm not so sure. I made https://mk12.github.io/web-math-demo/ to compare them and other things. They're definitely superior to browser MathML rendering today, which is nonexistent in Chrome (though see https://mathml.igalia.com/ ), quite bad in Safari, and OK in Firefox. It's true pre-rendering KaTeX produces a lot of markup, but it compresses very well so I d…

There's currently around 100 LaTeX functions listed as "Not supported" in the Katex docs at https://katex.org/docs/support_table.html I've been trying hard for a while with my site (https://cocalc.com) to use only katex, but that's definitely never going to happen. Users frequently hit missing functionality, e.g., they have lots of notebooks that use "\mbox", so it's critical to support full mathjax. I currently do this by attempting to use katex, then falling back to mathjax if it fails. That said, as you point out, mathjax has massively improved over the last few years with mathjax3! Thanks for pointing out the quality issues, which I hadn't thought about.

Re: Render mathematical expressions in Markdown On GitHub

#52
post #3

Finally a long-awaited feature. Works nicely in dark mode too. However, it simply uses MathJax. Also there are some minor annoyances. For example you need to escape the backslashes, so it takes 4 backslashes to make a newline in your matrix. $$\begin{bmatrix} a & b \\\\ c & d\end{bmatrix}$$ I found that the inline math doesn't quite match the font size of the surrounding text too (it's smaller).

In my opinion LaTeX is a poor fit for markdown, although it is the logical—and probably the only—choice. Markdown documents are supposed to be easy to read and quick to type. LaTeX is neither. When I include a matrix in my markdown document I want to type it something like: ## Example Matrix $$$ [a, b; c, d] $$$ Although I realize that we are probably stuck with LaTeX for the foreseeable future as the only way to typ…

I agree. I thought the whole point of markdown was to be simple and readable. At this point, why not just use full latex instead.

Re: Render mathematical expressions in Markdown On GitHub

#54
post #46

Earlier quoted context omitted.

You're being modest. This is easily the most performant option... although it means losing interactivity (right clicking equations on GitHub allows copy to clipboard, A11y features, etc). Running the JS client side, like GitHub, means blocking the thread. You're either going to be 1. delaying other JS from running, or 2. rendering late, shifting the layout – which is what GitHub has chosen: https://imgur.com/a/y47haf…

> Figure out viewbox and inline height/width values on the HTML so no layout jank (aka "Cumulative Layout Shift"/CLS) occurs. Unsure if this is possible for inline math. That's a great idea, I should do that. Right now I apply the height and offsets from the SVG file (via vertical-align and height) so that it flows nicely but I should add width too. It is trivially doable since the SVG does contain the width. e.g.

[deleted]

Re: Render mathematical expressions in Markdown On GitHub

#55
All these TeX-like math syntaxes seem to miss the point of markdown -- that it's as legible as possible in plain text form. I know they're very limited in how much math you can express in plain text, but using backslashes seems to be an admission of defeat.

I'd expect a syntax more like OpenOffice math.

https://wiki.openoffice.org/wiki/Documentation/OOoAuthors_Us...

Re: Render mathematical expressions in Markdown On GitHub

#56
post #8

Nice! A welcome addition! Too bad they're not using KaTeX [0] instead. It renders the maths server-side, so there's no runtime needed. An additional bonus is that the resulting math is copy-pasteable, which in the case of disply math might not be that useful (since most equations are to complex to be meaningfully copy-pasted with unicode), but it helps from inline math dissappearing when copy pasting texts. But, that…

If I was building this feature, I'd also pick client side rendering, simply because at GitHub's scale, rendering on the server side will require a bunch of servers, which will need to be managed and looked after.

By offloading the rendering to the client, you make use of the spare capacity that exists on most client machines today, with no noticable slowdown for the user (it may even end up doing the "first paint" faster in the browser if GitHub are careful about their implementation).

Even with my SaaS product, we try and do as much work on the client as possible to reduce our server requirements. If you're sensible about it, users don't even notice.

Re: Render mathematical expressions in Markdown On GitHub

#57
post #56
post #8

Nice! A welcome addition! Too bad they're not using KaTeX [0] instead. It renders the maths server-side, so there's no runtime needed. An additional bonus is that the resulting math is copy-pasteable, which in the case of disply math might not be that useful (since most equations are to complex to be meaningfully copy-pasted with unicode), but it helps from inline math dissappearing when copy pasting texts. But, that…

If I was building this feature, I'd also pick client side rendering, simply because at GitHub's scale, rendering on the server side will require a bunch of servers, which will need to be managed and looked after. By offloading the rendering to the client, you make use of the spare capacity that exists on most client machines today, with no noticable slowdown for the user (it may even end up doing the "first paint" fa…

Historically client-side rendering has been a big headache. Not sure if it's improved recently, but avid math bloggers and blog readers will remember the problems of the past decade.

Re: Render mathematical expressions in Markdown On GitHub

#58
post #3

Finally a long-awaited feature. Works nicely in dark mode too. However, it simply uses MathJax. Also there are some minor annoyances. For example you need to escape the backslashes, so it takes 4 backslashes to make a newline in your matrix. $$\begin{bmatrix} a & b \\\\ c & d\end{bmatrix}$$ I found that the inline math doesn't quite match the font size of the surrounding text too (it's smaller).

In my opinion LaTeX is a poor fit for markdown, although it is the logical—and probably the only—choice. Markdown documents are supposed to be easy to read and quick to type. LaTeX is neither. When I include a matrix in my markdown document I want to type it something like: ## Example Matrix $$$ [a, b; c, d] $$$ Although I realize that we are probably stuck with LaTeX for the foreseeable future as the only way to typ…

I think you're right on all counts, especially on being stuck with LaTeX.

What's your language? Any plans to build some sort of translator or other mechanism to allow high-quality rendering based on it?

Re: Render mathematical expressions in Markdown On GitHub

#59
post #56
post #8

Nice! A welcome addition! Too bad they're not using KaTeX [0] instead. It renders the maths server-side, so there's no runtime needed. An additional bonus is that the resulting math is copy-pasteable, which in the case of disply math might not be that useful (since most equations are to complex to be meaningfully copy-pasted with unicode), but it helps from inline math dissappearing when copy pasting texts. But, that…

If I was building this feature, I'd also pick client side rendering, simply because at GitHub's scale, rendering on the server side will require a bunch of servers, which will need to be managed and looked after. By offloading the rendering to the client, you make use of the spare capacity that exists on most client machines today, with no noticable slowdown for the user (it may even end up doing the "first paint" fa…

The tradeoff is exactly noticeable slowdown: https://imgur.com/a/y47haf9. Browser JS engines are single threaded, so MathJax has to wait its turn behind more important scripts, and it gets worse with slower devices and networks. It's a contest of download vs execution time, which a 2KB pre-rendered image will always win.

You're right on the money with the server costs though.

Re: Render mathematical expressions in Markdown On GitHub

#60
post #45
post #8

Nice! A welcome addition! Too bad they're not using KaTeX [0] instead. It renders the maths server-side, so there's no runtime needed. An additional bonus is that the resulting math is copy-pasteable, which in the case of disply math might not be that useful (since most equations are to complex to be meaningfully copy-pasted with unicode), but it helps from inline math dissappearing when copy pasting texts. But, that…

I used to think KaTeX was far superior to MathJax but now I'm not so sure. I made https://mk12.github.io/web-math-demo/ to compare them and other things. They're definitely superior to browser MathML rendering today, which is nonexistent in Chrome (though see https://mathml.igalia.com/ ), quite bad in Safari, and OK in Firefox. It's true pre-rendering KaTeX produces a lot of markup, but it compresses very well so I d…

> https://github.com/KaTeX/KaTeX/issues/3400 has gone unfixed for a long time.

I don't think I'd qualify an issue from the end of last year as "unfixed for a long time".

Post reply on HN