a-cosmology-group/acg#7

View on GitHub →
#7 Rendering Mathematical Expressions

Mathematical expressions rendering is available in GitHub Issues, GitHub Discussions, pull requests, wikis, and Markdown files. https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions

Examples: When $a \ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$$

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)$$

2🚀 1
Comments (6)

Okay, Louis, but now I have something more elaborate, like this:

$$ H = \sqrt{\chi\,G\,\rho_0} \quad \mbox{with} \quad \chi = 8\pi \times \begin{cases} 1/8 & (: \mbox{OI}) \\ 1/6 & (: \mbox{Mach}) \\ 1/3 & (: \Lambda\mbox{CDM}) \\ 0.3883945571 & (: \mbox{UAC}) \end{cases} $$

That doesn’t work well, isn’t it? Why not? It’s perfect MathJax!

That’s my problem: sometimes it works, sometimes it doesn’t.

Han

1

$$ H = \sqrt{\chi,G,\rho_0} \quad \mbox{with} \quad \chi = 8\pi \times \begin{cases} 1/8 & (: \mbox{OI}) \ 1/6 & (: \mbox{Mach}) \ 1/3 & (: \Lambda\mbox{CDM}) \ 0.3883945571 & (: \mbox{UAC}) \end{cases} $$

It works!

It seems that the opening $$ must be preceded by a blank line, and the closing one followed by a blank line, as in:


$$
H = \sqrt{\chi\,G\,\rho_0} \quad \mbox{with} \quad \chi = 8\pi \times \begin{cases} 1/8 & (: \mbox{OI}) \\ 1/6 & (: \mbox{Mach}) \\ 1/3 & (: \Lambda\mbox{CDM}) \\ 0.3883945571 & (: \mbox{UAC}) \end{cases}
$$

You don’t need the rest of the html markup.

Thanks, but the ‘case’ statement doesn’t work properly: \ means new line in MathJax. Hmm, the preview shows a single backslash .. Does Markdown interfere with the math?

I see… It seems that a newline is required after the \\ here, bummer. And it does not handle accidental line spacing, as in \\[0.5em] 😞.

$$
\begin{cases} 1/8 & (: \mbox{OI}) \\
1/6 & (: \mbox{Mach}) \\ 
1/3 & (: \Lambda\mbox{CDM}) \\ 
0.3883945571 & (: \mbox{UAC}) \end{cases}
$$

$$ \begin{cases} 1/8 & (: \mbox{OI}) \ 1/6 & (: \mbox{Mach}) \ 1/3 & (: \Lambda\mbox{CDM}) \ 0.3883945571 & (: \mbox{UAC}) \end{cases} $$

👍 1

LaTeX is a later addition to the Markdown parser, it’s a bit finicky to use because they didn’t want a $4.98 amount trigger an error message as an invalid LaTeX equation.

The parser looks for spaces immediately outside of both $$ delimiters, and no space just after the $$ opening delimiter. It seems a comma is also accepted after the closing delimiter $$.

So,

... this equation $$ E = m c^2 $$ will not render properly,
and this one $$E=mc^2$$won't either,
but this one $E = mc^2$, will be rendered correctly!

If the equation is multiline, then a blank line is needed before and after the $$ delimiters (as @ftessier mentioned). The thin space \, does not seem to be implemented.

What you need to type is:

On the same line with spaces before and after the delimiters: $E = mc^2$,
(a comma after the last delimiter is correctly rendered)
and multiple lines with blank lines on both sides of the $$ delimiters:

$$H = \sqrt{\chi G \rho_0} \quad \mbox{with} \quad \chi = 8\pi \times
\begin{cases}
  1/8 & (: \mbox{OI}) \\
  1/6 & (: \mbox{Mach}) \\
  1/3 & (: \Lambda\mbox{CDM}) \\
  0.3883945571 & (: \mbox{UAC})
\end{cases}$$

which is rendered as:

On the same line with spaces before and after the delimiters: $E = mc^2$, (a comma after the last delimiter is correctly rendered) and multiple lines with blank lines on both sides of the $$ delimiters:

$$H = \sqrt{\chi G \rho_0} \quad \mbox{with} \quad \chi = 8\pi \times \begin{cases} 1/8 & (: \mbox{OI}) \ 1/6 & (: \mbox{Mach}) \ 1/3 & (: \Lambda\mbox{CDM}) \ 0.3883945571 & (: \mbox{UAC}) \end{cases}$$

👍 1❤️ 1🚀 1