Quick maths

2022 Week 212 min read

giscus 💎

GitHub added support for mathematical expressions in Markdown. I thought their Markdown Renderer API wouldn't be updated any time soon to include rendered math expressions in the result.

I was half-wrong. They did update the API, but it returns a custom element with the math expressions inside it. So, the following input:

$$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$

yields the following output:

<p dir="auto">
  <math-renderer
    class="js-display-math"
    style="display: block"
    data-static-url="https://github.githubassets.com/static"
    >$$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$</math-renderer
  >
</p>

This means it's up to us to define the <math-renderer> custom element and how it renders the math expression.

I didn't intend to hack a solution immediately, but one discovery urged me to try something out:

It turns out GitHub provides sourcemaps for its client code. I think I remember reading about this a while ago, but I can't remember where. Anyway, it turns out we can see the source code for their <math-renderer> element.

Source code for math-renderer-element.ts

I shamelessly "adapted" it to be used in giscus. Thus, we now support rendering mathematical expressions!

I've also updated the theme colors and added the light and dark Tritanopia themes.

Work

We had another edition of What's New in Wagtail on Wednesday and Thursday! I presented the work I've been (and will be) doing on Snippets. The recording should be up soon!

Other stuff

My friends and I played badminton on Sunday afternoon. It's the first time we played in the afternoon. That was a nice change of vibe.

I also played some video games, Borderlands 2 and Fallout: New Vegas, like last week.