[HN Gopher] Render mathematical expressions in Markdown On GitHub
       ___________________________________________________________________
        
       Render mathematical expressions in Markdown On GitHub
        
       Author : robin_reala
       Score  : 161 points
       Date   : 2022-05-19 19:17 UTC (3 hours ago)
        
 (HTM) web link (github.blog)
 (TXT) w3m dump (github.blog)
        
       | romeovs wrote:
       | 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 being said, I'm sure they had their reasons to do so.
       | For one, MathJax seems more well-known by quite a bit so maybe
       | it's the safer option.
       | 
       | 1: https://katex.org/
        
         | jscholes wrote:
         | > I'm sure they had their reasons
         | 
         | They do, accessibility being one of them. Rendering math in the
         | way you describe makes it difficult, or impossible, to
         | understand for all sorts of audiences, including those relying
         | on screen reading software.
        
         | joppy wrote:
         | For pages with lots of mathematics markup, it is far better (in
         | terms of download size) to send the latex markup and the katex
         | library to the browser, and render it there. I tried rendering
         | the mathematics server-side using katex on my own website a
         | while ago, and the div soup generated by katex takes up loads
         | of space.
         | 
         | Original page (compressed): 10 kB
         | 
         | Page with server-rendered Katex (compressed): 50 kB
         | 
         | Katex.js (compressed): 80 kB
         | 
         | So after two pages it's a net win to _not_ render the
         | mathematics server-side.
        
           | dllu wrote:
           | For my blog (e.g.
           | https://daniel.lawrence.lu/blog/y2021m09d08/ with tons of
           | math), I render the math serverside using MathJax and serve
           | them as SVG images (with alt text for the visually impaired).
           | They get cached too which is nice especially since many
           | symbols are duplicated. Seems fast enough for me.
        
         | qumpis wrote:
         | I'm so happy that I can just paste my definitions from latex
         | preamble into a paragraph to include all the calitographic
         | symbols and other conveniences with Mathjax. As far as I know,
         | I can't easily do it without adapting to Katex-specific syntax.
        
       | diarrhea wrote:
       | I wonder if, at all, other fonts will ever be used for MathJax
       | max display?
       | 
       | The 'default MathJax font' is also just the 'default LaTeX font'
       | (CM?). There are countless other, high-quality math fonts, for
       | example the TeX Gyre Math fonts. I'd like to see those one day, I
       | prefer them. It would be not more out of place than the current
       | version.
       | 
       | There are font pairs, too, like TeX Gyre Pagella and its TeX Gyre
       | Pagella Math accompanying font. So you have the _same_ font for
       | both, which is simply beautiful and even more readable I 'd
       | argue. I think most people have accepted that text and math fonts
       | are always distinct, when in fact they needn't be.
        
       | MaxLeiter wrote:
       | My one complaint about these new mark down features with github
       | is the lock-in. I'm trying to build a gist compatible service and
       | theres quite a bit to cover. MathJax is fine, but now I (and
       | gitlab, bitbucket, etc) will need to support it
        
       | ofou wrote:
       | Finally!
        
         | orange3xchicken wrote:
         | I know, I've been waiting so long for this! I will not miss
         | having to render and reference pngs of equations / api
         | requests.
        
           | jeremymcanally wrote:
           | You think you waited a long time? I wrote a patch to add this
           | to GitHub when I worked there in 2011-12! :) It was rejected
           | at the time by some folks for various "product" reasons, but
           | I'm glad to see it finally become a thing.
        
       | krastanov wrote:
       | Funny thing is, this feature (with MathJax) used to be available
       | in 2010ish, but got removed back then as they did not want to
       | have "unvetted" large libraries as a dependency.
        
       | ashton314 wrote:
       | Looks like it works with `.org` documents as well! I've been
       | authoring my README files in org-mode for a while now (richer
       | formatting options than Markdown) and GitHub does a great job
       | rendering the org-mode.
        
       | mulmboy wrote:
       | This is cute but it seems that expressions spanning multiple
       | lines are not rendered
       | 
       | OK:
       | 
       | $$\|\vec{x} - \vec{p}_c\| = v(t_c-t_0)$$
       | 
       | --
       | 
       | NOT OK:
       | 
       | $$
       | 
       | \|\vec{x} - \vec{p}_c\|
       | 
       | = v(t_c-t_0)
       | 
       | $$
       | 
       | This makes larger latex expressions pretty impractical e.g.
       | https://github.com/jurasofish/multilateration/blob/master/re...
        
       | whatever1 wrote:
       | Finally! Gitlab had this feature for so long
        
       | singularity2001 wrote:
       | Doesn't work on github's builtin wikis
        
       | dllu wrote:
       | 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).
        
         | thaumasiotes wrote:
         | > 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}$$
         | 
         | This example doesn't make sense. You need to escape the
         | backslashes in the end-of-row command \\\, but you don't need
         | to escape the backslashes in \begin and \end?
         | 
         | The post clearly shows that backslashes in \left, \right, \sum,
         | and \sqrt do not need to be escaped. What's different about
         | \\\?
        
           | dllu wrote:
           | No idea, but if you have only two backslashes instead of
           | four, the matrix would appear as a single row, like [a bc d].
           | 
           | That said, \\\begin renders the same as \begin.
        
             | thaumasiotes wrote:
             | Oh, this is an experimental result? You've found a bug in
             | Github's parser. You should call it a "bug", not an
             | "annoyance".
        
       | rudolfwinestock wrote:
       | Looking at some of the comments in this thread, I wonder if
       | Hacker News will ever render LaTeX.
        
       | [deleted]
        
       | bachmeier wrote:
       | Math doesn't render inside a bullet list item. I don't know how
       | to file an issue against Github itself, somewhat ironically.
        
         | metadaemon wrote:
         | I feel like being in a bullet list item restricts a lot of the
         | rendering you can do.
        
       | kaycebasques wrote:
       | Big picture it's interesting how GitHub + Markdown is basically
       | becoming a major content publishing product. Albeit for a
       | technical niche market. Of course I'm not saying this is GitHub's
       | main goal. More like a P1. Instant publishing, diagrams, and now
       | math expressions.
        
         | NmAmDa wrote:
         | Github becomes a favorite option for research and academic
         | people to work and collaborate their projects their. That is a
         | reasonable move from github to make it more suitable for them.
         | I know my group and several others are relying more and more on
         | github as git host with other products used for collaboration.
        
       | JadeNB wrote:
       | > **The Cauchy-Schwarz Inequality**
       | 
       | > $$left( \sum_{k=1}^n a_k b_k \right)^2 \leq left( \sum_{k=1}^n
       | a_k^2 \right) left( \sum_{k=1}^n b_k^2 \right)$$
       | 
       | I wonder why their syntax highlighting on this example highlights
       | `left` but not `right`? (I can't seem to reproduce it here, since
       | the HN parser tries to outsmart me.)
        
         | yuchi wrote:
         | The reason is that their blog rendering auto-identifies that
         | code block as SCSS and treats "left" as an attribute. Which is
         | strange, since I cannot find something for "left" that is not
         | defined for "right".
         | 
         | For example, I cannot find a "left" attribute here:
         | https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
        
           | yuchi wrote:
           | Some more details. They are using Highlight.js, and
           | `attribute` is what is applied to (S)CSS properties too. But
           | both `left` and `right` are valid properties. What I think is
           | that `\r` is treated as the special Carriage Return character
           | and therefore doesn't allow `right` to be identified.
        
       ___________________________________________________________________
       (page generated 2022-05-19 23:00 UTC)