Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I represent $\mathbb{character}$ in Github markdown?

I uploaded a Markdown file to GitHub, but the inline math formulas are not displaying correctly. For example, $v=\begin{bmatrix}1 & 3\end{bmatrix}^T$ does not render as expected.

enter image description here

After some trial and error, I discovered that using $`v=\begin{bmatrix}1 & 3\end{bmatrix}^T`$ works correctly, although I'm unsure why.

enter image description here

Now, I have another issue I haven't resolved: the font for the math formulas. I want to display $\mathbb{R}$, but whether it's in an inline formula or a block formula, it does not render correctly and just looks like $R$ (the default font).

Expectation: enter image description here

Reality: enter image description here

Any insights on how to fix the font rendering issue for $\mathbb{R}$ in GitHub Markdown would be greatly appreciated. Thanks!

like image 458
Warren Chen Avatar asked Dec 01 '25 18:12

Warren Chen


1 Answers

GitHub is now translating the LaTeX input into MathML rather than using MathJax in the browser (it may use MathJax behind the scenes to do that translation, but I'm not sure). That means the math is being rendered by the browser's native MathML implementation. Chrome implements MathML-Core, which is a limited version of MathML. In particular, it only allows the mathvariant attribute on <mi> elements, and then only to set mathvariant="normal" when it would otherwise have been italic for content that is a single letter. Safari does handle mathvariant, but it appears that Chrome removes the attribute entirely. MathML-Core expects you to use the Unicode characters in the Mathematical Alphanumerics and Letter-like Symbols blocks directly, so you would have to use U+211D for the double-struck capital R. Because GitHub Markdown isn't making that translation for you, you would have to use the U+211D character explicitly: ℝ. That's a pain, and it is an unfortunate result of their deciding to go with native MathML rendering rather than MathJax.

As for the $`...`$ delimiters, that is one of the mechanisms they have used to avoid Markdown processing the contents of the mathematics, where things like underscores and backslashes should be left verbatim instead of having their usual Markdown meanings. They had originally tried to modify the math to quote the special characters, but botched it rather badly, and this was their way of rectifying that. See their blog post about writing mathematics in GitHub, which is no longer accurate in saying they are using MathJax for rendering, but gives you the right delimiters to use for in-line and displayed math.

like image 172
Davide Cervone Avatar answered Dec 04 '25 09:12

Davide Cervone