Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inline math interpreted as attributes #2645

Merged
merged 1 commit into from
Nov 1, 2020
Merged

fix: inline math interpreted as attributes #2645

merged 1 commit into from
Nov 1, 2020

Conversation

edomora97
Copy link
Contributor

When using inline math ($e^{-x^2}$) the curly braces are interpreted as attributes by markdown-it-attrs. Since most of the times they are not valid attributes they simply get removed.

This patch escapes the curly braces (the default attribute delimiter), fixing the KaTeX rendering errors.

The problem occurs only when the inline math ends with a curly brace block (see examples below). For this reason the third example below works also in the current version.
An alternative fix may have been to force the math block not to end with the curly braces, for example by adding some spacing (e.g. \,). I preferred not adding some spurious spaces, the escaping strategy should be pretty invisible.

One could think it should be enough to escape the last { and }, in practice it's not enough: $e^{e^{x}+1}$ would become $e^{e^{{x}+1}}$, which is valid but clearly not equivalent. (note that this example is not broken in the current version since the last curly block contains another curly block, which apparently it's fine).

It would be nice to simply skip that rule for katex_inline block types but as far as I know markdown-it-attrs doesn't have such an option.


Example

$e^{-x^2}$

$P_{static} = I_{DD}V_{DD}$

$V_{DD}=5V$

Previously

image

ParseError: KaTeX parse error: Expected group after '^' at position 2: e^̲
ParseError: KaTeX parse error: Expected group after '_' at position 21: …atic} = I_{DD}V_̲

Now

image


Fixes #1581

When using inline math ($e^{-x^2}$) the curly braces are interpreted as
attributes by markdown-it-attrs. Since most of the times they are not
valid attributes they simply get removed.

This patch escapes the curly braces (the default attribute delimiter),
fixing the KaTeX rendering errors.

It would be nice to simply skip that rule for `katex_inline` block types
but as far as I know markdown-it-attrs doesn't have such an option.

Fixes #1581
@NGPixel NGPixel merged commit a37a73d into requarks:dev Nov 1, 2020
@ivlydp
Copy link

ivlydp commented Mar 17, 2021

It seems still have this problem in version 2.9.191
for rendering inline function such as $H_{ADAS2Eye}$
KaTeX parse error: Expected group after '_' at position 2: H_̲ ,
however in edit/preview mode it is right.
please help check it.

leduythuccs added a commit to VNOI-Admin/wiki that referenced this pull request Dec 24, 2023
leduythuccs added a commit to VNOI-Admin/wiki that referenced this pull request Dec 24, 2023
* Revert "fix: inline math interpreted as attributes (requarks#2645)"

This reverts commit a37a73d.

* Don't enable markdown-it-attrs by default
jionggyu pushed a commit to jionggyu/wiki-2.5.302-patch that referenced this pull request Jul 9, 2024
When using inline math ($e^{-x^2}$) the curly braces are interpreted as
attributes by markdown-it-attrs. Since most of the times they are not
valid attributes they simply get removed.

This patch escapes the curly braces (the default attribute delimiter),
fixing the KaTeX rendering errors.

It would be nice to simply skip that rule for `katex_inline` block types
but as far as I know markdown-it-attrs doesn't have such an option.

Fixes requarks#1581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Katex subscript rendering issue
3 participants