reopening #27605 (Math blocks can't be directly preceded or followed by alphanumeric character) #13790

Closed
opened 2025-11-02 10:53:19 -06:00 by GiteaMirror · 14 comments
Owner

Originally created by @nschloe on GitHub (Dec 5, 2024).

Description

Unless I'm missing something, the issue https://github.com/go-gitea/gitea/issues/27605 has reappeared despite its fix in https://github.com/go-gitea/gitea/pull/30175.

MWE:

a$x$ -$x$ 1$x$

Screenshot:

screenshot_2024-12-05-152708

$a$1

$a$-

$a$x

screenshot_2024-12-05-152735

This also concerns the \(...\) and \[...\] syntax.

Gitea Version

1.23.0+dev-753-gc5422fae9a

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

demo.gitea.com

Database

None

Originally created by @nschloe on GitHub (Dec 5, 2024). ### Description Unless I'm missing something, the issue https://github.com/go-gitea/gitea/issues/27605 has reappeared despite its fix in https://github.com/go-gitea/gitea/pull/30175. MWE: ``` a$x$ -$x$ 1$x$ ``` Screenshot: ![screenshot_2024-12-05-152708](https://github.com/user-attachments/assets/c294ca62-3cdd-4178-aa3e-22c44db41b2d) ``` $a$1 $a$- $a$x ``` ![screenshot_2024-12-05-152735](https://github.com/user-attachments/assets/94c6fcac-55ac-4d53-99e1-4cf05f0e2f97) This also concerns the `\(...\)` and `\[...\]` syntax. ### Gitea Version 1.23.0+dev-753-gc5422fae9a ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? demo.gitea.com ### Database None
GiteaMirror added the issue/needs-feedback label 2025-11-02 10:53:19 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Dec 5, 2024):

a$x$ -$x$ 1$x$

What's the problem? If you'd like to render it, please add some spaces.

Otherwise, it's impossible to distinguish from This is $1 and that is 20 US$, we shouldn't render everything between $, say here it is 1 and that is 20US.

@wxiaoguang commented on GitHub (Dec 5, 2024): > `a$x$ -$x$ 1$x$` What's the problem? If you'd like to render it, please add some spaces. Otherwise, it's impossible to distinguish from `This is $1 and that is 20 US$`, we shouldn't render everything between `$`, say here it is `1 and that is 20US`.
Author
Owner

@wxiaoguang commented on GitHub (Dec 5, 2024):

Unless I'm missing something, the issue #27605 has reappeared despite its fix in #30175.

The issue doesn't "reappear", because there are enough tests in #30175, a$x$ isn't rendered as "math".

image

@wxiaoguang commented on GitHub (Dec 5, 2024): > Unless I'm missing something, the issue #27605 has reappeared despite its fix in #30175. The issue doesn't "reappear", because there are enough tests in #30175, `a$x$` isn't rendered as "math". <details> ![image](https://github.com/user-attachments/assets/ff362aad-feaa-481d-a6a2-a31beb305079) </details>
Author
Owner

@wxiaoguang commented on GitHub (Dec 5, 2024):

By the way, maybe you might be interested in my recent refactoring PRs like #32728

image

@wxiaoguang commented on GitHub (Dec 5, 2024): By the way, maybe you might be interested in my recent refactoring PRs like #32728 <details> ![image](https://github.com/user-attachments/assets/549fc74c-4013-46b2-b106-600415daa894) </details>
Author
Owner

@wxiaoguang commented on GitHub (Dec 5, 2024):

Hmm, I see the misconception now. Actually #30175's title doesn't really match its test cases.

So, if a$x$ -$x$ 1$x$ is a must to support, we need to clarify its usage first and design the cases to avoid interfering other daily sentences like US$1 and 20US$

  • the question is: why not write $ax$ $-x$ $1x$?

The original discussion is here: https://github.com/go-gitea/gitea/pull/30175#discussion_r1545590510

And this: https://github.com/go-gitea/gitea/pull/30175#issuecomment-2030182178

I looked at some websites and math research papers and it seems that the math expressions are never directly preceeded by a character, they are either a whole mathematical block or have a space in between like a $x$.

@wxiaoguang commented on GitHub (Dec 5, 2024): Hmm, I see the misconception now. Actually #30175's title doesn't really match its test cases. So, if `a$x$ -$x$ 1$x$` is a must to support, we need to clarify its usage first and design the cases to avoid interfering other daily sentences like `US$1 and 20US$` - the question is: why not write `$ax$ $-x$ $1x$`? ---- The original discussion is here: https://github.com/go-gitea/gitea/pull/30175#discussion_r1545590510 And this: https://github.com/go-gitea/gitea/pull/30175#issuecomment-2030182178 > I looked at some websites and math research papers and it seems that the math expressions are never directly preceeded by a character, they are either a whole mathematical block or have a space in between like `a $x$`.
Author
Owner

@nschloe commented on GitHub (Dec 13, 2024):

the question is: why not write $ax$ $-x$ $1x$?

There are various cases where you don't want spaces before or after math, for example:

  • $n$-dimensional
  • The answer is $x$. (any punctuation mark)
  • ($a$ replaced by $b$) (any bracket, before and after)
  • the $i$th iterate

There are more examples. None of this works in Gitea now; this also concerns the the $$...$$-, \(...\)-, and \[...\] syntaxes.

Opinion

Dealing with $-math is hard, so hard even that Donald Knuth himself suggested adding it to TeX was a mistake, later remedied by adding \(...\) to LaTeX. In Markdown, as opposed to TeX and as @wxiaoguang mentiones above, it gets even more tricky since the single $ already has a meaning that must be preserved.

Both GitLab and GitHub added a syntax that ties in beautifully with Markdown, namely

$`a + b = c`$ for inline math and 

```math
a + b = c
```

for display math.

None of the problems mentioned in this and other reports exist here because it makes use of the backticks, a well-established syntax in Markdown.

I've suggested adopting this syntax in Gitea as well.

@nschloe commented on GitHub (Dec 13, 2024): > the question is: why not write `$ax$ $-x$ $1x$`? There are various cases where you don't want spaces before or after math, for example: - `$n$-dimensional` - `The answer is $x$.` (any punctuation mark) - `($a$ replaced by $b$)` (any bracket, before and after) - `the $i$th iterate` There are more examples. None of this works in Gitea now; this also concerns the the `$$...$$`-, `\(...\)`-, and `\[...\]` syntaxes. ##### Opinion Dealing with `$`-math is _hard_, so hard even that [Donald Knuth himself suggested](https://tex.stackexchange.com/questions/510/are-and-preferable-to-dollar-signs-for-math-mode#comment61028_510) adding it to TeX was a mistake, later remedied by adding `\(...\)` to LaTeX. In Markdown, as opposed to TeX and as @wxiaoguang mentiones above, it gets even _more_ tricky since the single `$` already has a meaning that must be preserved. Both GitLab and GitHub added a syntax that ties in beautifully with Markdown, namely ```` $`a + b = c`$ for inline math and ```math a + b = c ``` for display math. ```` None of the problems mentioned in this and other reports exist here because it makes use of the backticks, a well-established syntax in Markdown. [I've suggested](https://github.com/go-gitea/gitea/issues/27602) adopting this syntax in Gitea as well.
Author
Owner

@wxiaoguang commented on GitHub (Dec 13, 2024):

So if we support $` for inline math, then this issue (and maybe some related legacy issues) could be fully resolved?

@wxiaoguang commented on GitHub (Dec 13, 2024): So if we support ``` $` ``` for inline math, then this issue (and maybe some related legacy issues) could be fully resolved?
Author
Owner

@nschloe commented on GitHub (Dec 13, 2024):

At least you could point anyone running into a $-syntax bug to the working $`...`$ syntax. I myself would only use the latter anyway, and recommend everyone would do the same. (Same for $$ vs ```math.)

Edit: Highlighting why the \[...\] is problematic as well: https://github.com/go-gitea/gitea/issues/27645

@nschloe commented on GitHub (Dec 13, 2024): At least you could point anyone running into a `$`-syntax bug to the working ``$`...`$`` syntax. I myself would only use the latter anyway, and recommend everyone would do the same. (Same for `$$` vs `` ```math``.) _Edit:_ Highlighting why the `\[...\]` is problematic as well: https://github.com/go-gitea/gitea/issues/27645
Author
Owner

@wxiaoguang commented on GitHub (Dec 13, 2024):

Edit: Highlighting why the \[...\] is problematic as well: #27645

Yes, I also found that \[...\] is problematic, it's not right to introduce it. But I guess we couldn't remove it since it would be a breaking change.

After " Refactor markdown math render #32831 ", the $`x`$ will be supported, then other issues could be closed IMO (encourage users to use the new syntax)

@wxiaoguang commented on GitHub (Dec 13, 2024): > _Edit:_ Highlighting why the `\[...\]` is problematic as well: #27645 Yes, I also found that `\[...\]` is problematic, it's not right to introduce it. But I guess we couldn't remove it since it would be a breaking change. After " Refactor markdown math render #32831 ", the ``` $`x`$ ``` will be supported, then other issues could be closed IMO (encourage users to use the new syntax)
Author
Owner

@nschloe commented on GitHub (Dec 13, 2024):

But I guess we couldn't remove it since it would be a breaking change.

Indeed, unfortunately so.

After " Refactor markdown math render https://github.com/go-gitea/gitea/pull/32831 ", the x will be supported, then other issues could be closed IMO (encourage users to use the new syntax)

Note that we'd also need ```math code blocks to get feature parity with GitHub/GitLab.

@nschloe commented on GitHub (Dec 13, 2024): > But I guess we couldn't remove it since it would be a breaking change. Indeed, unfortunately so. > After " Refactor markdown math render https://github.com/go-gitea/gitea/pull/32831 ", the $`x`$ will be supported, then other issues could be closed IMO (encourage users to use the new syntax) Note that we'd also need `` ```math`` code blocks to get feature parity with GitHub/GitLab.
Author
Owner

@wxiaoguang commented on GitHub (Dec 13, 2024):

Note that we'd also need ```math code blocks to get feature parity with GitHub/GitLab.

It is already supported, right? https://demo.gitea.com/wxiaoguang/test-repo/issues/1#issuecomment-3436

image

@wxiaoguang commented on GitHub (Dec 13, 2024): > Note that we'd also need `` ```math `` code blocks to get feature parity with GitHub/GitLab. It is already supported, right? https://demo.gitea.com/wxiaoguang/test-repo/issues/1#issuecomment-3436 ![image](https://github.com/user-attachments/assets/978135b2-1d66-4bc0-926e-2bdeb0e504ae)
Author
Owner

@nschloe commented on GitHub (Dec 13, 2024):

Right! Hadn't realized that.

@nschloe commented on GitHub (Dec 13, 2024): Right! Hadn't realized that.
Author
Owner

@wxiaoguang commented on GitHub (Dec 14, 2024):

Done in 1.23, let's use $`...`$

@wxiaoguang commented on GitHub (Dec 14, 2024): Done in 1.23, let's use ``` $`...`$ ```
Author
Owner

@nschloe commented on GitHub (Dec 16, 2024):

This isn't working yet in 1.23.0+dev-789-g18061af490 (on demo.gitea.com).

@nschloe commented on GitHub (Dec 16, 2024): This isn't working yet in 1.23.0+dev-789-g18061af490 (on demo.gitea.com).
Author
Owner

@wxiaoguang commented on GitHub (Dec 16, 2024):

This isn't working yet in 1.23.0+dev-789-g18061af490 (on demo.gitea.com).

Demo site is at 18061af490 (5 days ago), it doesn't include #32831

You can get the latest main-nightly (from dl.gitea.com or dockerhub)

@wxiaoguang commented on GitHub (Dec 16, 2024): > This isn't working yet in 1.23.0+dev-789-g18061af490 (on demo.gitea.com). Demo site is at 18061af490 (5 days ago), it doesn't include #32831 You can get the latest main-nightly (from dl.gitea.com or dockerhub)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13790