markup icon indicating copy to clipboard operation
markup copied to clipboard

Markdown math rendering fails on multiple subscripts with curly brackets

Open stroitzsch opened this issue 2 years ago • 11 comments

Multiple subscripts in combination with curly brackets in LaTeX-based math expressions don't render as expected.

Single underscore with curly brackets works fine: \mathbf{x}_{i,j} = \mathbf{y} renders as $\mathbf{x}_{i,j} = \mathbf{y}$.

Multiple underscores without curly brackets work fine: x_i = y_i renders as $x_i = y_i$.

Multiple underscores with curly brackets fail: \mathbf{x}_{i,j} = \mathbf{y}_{i,j} renders as $\mathbf{x}{i,j} = \mathbf{y}{i,j}$.

stroitzsch avatar Jul 18 '22 13:07 stroitzsch

In the meantime, a workaround is to use trailing spaces after underscore symbols: \mathbf{x}_ {i,j} = \mathbf{y}_ {i,j} renders as $\mathbf{x}_ {i,j} = \mathbf{y}_ {i,j}$

stroitzsch avatar Jul 18 '22 13:07 stroitzsch

Same issue, thanks for the workaround tho!

zhongzachary avatar Aug 04 '22 19:08 zhongzachary

In some cases also without curly brackets don't work. Example: 19 =_2 010011 The workaround works fine.

giopalma avatar Aug 20 '22 09:08 giopalma

If the two subscripts are in two expressions but in the same line, render is broken as well.

Range of $\mathbf{d}_{ij}$ and $\mathbf{d}_{ij} \cdot \Delta E$

will be rendered as "Range of $\mathbf{d}{ij}$ and $\mathbf{d}{ij} \cdot \Delta E$", but the workaround also work for this case "Range of $\mathbf{d}_ {ij}$ and $\mathbf{d}_ {ij} \cdot \Delta E$"

tautomer avatar Oct 27 '22 21:10 tautomer

To give more strange examples (but thanks a lot for the workaround), if I put a single expression it works, if I copy/paste it it fails:

$V^{a}_{x}$

Gives $V^{a}_{x}$

But

$V^{a}_{x} V^{a}_{x}$

Gives $V^{a}{x} V^{a}{x}$

My bet is that github confuses it with emphasis (like in _emphasis_), explaining why adding a space solves the issue…

tobiasBora avatar Nov 21 '22 15:11 tobiasBora

Also something similar happens with stars (I guess again because it thinks it's bold, so the same work around also works):

$V^{*}$

Gives $V^{*}$ (ok)

$V^{*} V^{*}$

Gives $V^{} V^{}$ (bad!)

$V^{ * } V^{ * }$

Gives $V^{ * } V^{ * }$ (ok)

tobiasBora avatar Nov 21 '22 15:11 tobiasBora

I suspect this happens because a_b is detected as one word, so emphasis doesn't come in, but in a}_b, there is a word boundary between } and _, so it can be detected as emphasis.

So a _b c_d is working but a _b c_ d is not.

$$ a _b c_d $$

$$ a b c d $$

ImpleLee avatar Dec 01 '22 11:12 ImpleLee

For non-inline math, as an alternative, we can use

```math

to replace $$.

I have more experiments at https://github.com/ImpleLee/c4w/issues/1 .

ImpleLee avatar Dec 01 '22 11:12 ImpleLee

Inline math expression: $\sum_{i=1}^{m}$ $\sum_{i=1}^{m}$ Summation superscript rendering is bad! Another e.g., $\frac{1}{2m}\sum_{i=1}^{m}{(\hat{y} _{i} - y _{i})}^{2}$ $\frac{1}{2m}\sum_{i=1}^{m}{(\hat{y} _{i} - y _{i})}^{2}$

Block math expression: Summation superscript is okay! $$\sum_{i=1}^{m}$$ $$\sum_{i=1}^{m}$$ Another e.g., $$\frac{1}{2m}\sum_{i=1}^{m}{(\hat{y} _{i} - y _{i})}^{2}$$

Any workarounds?

prasanth-ntu avatar Mar 10 '23 21:03 prasanth-ntu

See e.g. ${\boldsymbol{x}1, ..., \boldsymbol{x}{i-1}, \boldsymbol{x}_{i+1}, ..., \boldsymbol{x}_n}$, which fails to render.

mbaudin47 avatar Jun 02 '23 21:06 mbaudin47

@prasanth-ntu I was looking for the same and found a workaround on a github gist of some repo. One of the solutions described there was the following ${\sum}_{k=0}^{K}$ = ${\sum}_{k=0}^{K}$. Although, these issues require #github's attention and hopefully should be fixed at some point 🤞

kirk86 avatar Jun 13 '23 11:06 kirk86