Block Math Syntax discrepancy between editor and reading mode (LaTeX)

Please see:

Steps to reproduce

  • Create a file A.md
  • Create a file B.md and insert the following into it:
$$
P(A)
$$$$
P(A)
$$

[A](A.md)
  • Rename A.md to anything
  • The link to A.md in B.md will not have updated

If you then insert a newline character between the two sets of $$ the link renaming will work as expected.

Weirdly though this doesn’t appear to be an issue for the interactive viewer as in it will display both equations fine

Did you follow the troubleshooting guide?

Y - Was able to replicate this bug in the sandbox

Expected result

I wanted the link to A.md to be updated to the new name

Actual result

The Link to A.md in B.md was not updated

Environment

SYSTEM INFO:
	Obsidian version: v1.4.14
	Installer version: v1.4.13
	Operating system: Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 22.4.0
	Login status: logged in
	Catalyst license: none
	Insider build toggle: off
	Live preview: on
	Legacy editor: off
	Base theme: light
	Community theme: none
	Snippets enabled: 1
	Restricted mode: off
	Plugins installed: 5
	Plugins enabled: 0

Additional information

Linked file settings:

Just to add that it appears to be bugged if any text is added onto the end of the equation for example this triggers it as well:

$$
P
$$sometext

[A](A.md)

This is particularly difficult to spot / deal with because in live preview mode as there is no clue that it is formatted like this:

In addition to missing links, the outline not working, etc., PDF export is also affected.

Folks who only use Live preview, where the issue may not be seen, are surprised when the exported PDF is broken part way through (often with the yellow highlighted text appearing).

Are you sure this is case cause both hypermd and the remark parser don’t follow this. Leaving aside the hypermd parser cause that is a complicated stream parser with the baggage of the project hypermd and only focusing on the remark/reader parser.

Edit: questioning the definition because the code in app.js indicates something else/would be less complex if that was the definition. And it seems to take inspiration from both mdast-util-math and pandoc.

Or could you make that definition more formal, because I’m assuming what you mean is along the lines of the pandoc definition of

Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.

For display math, use $$ delimiters. (In this case, the delimiters may be separated from the formula by whitespace. However, there can be no blank lines between the opening and closing $$ delimiters.)

But currently the blank line rule is relaxed for the block display parser (unless it breaks outside syntax like blockqoutes) and it treats the $$ more like code fences where at least the starting amount have to be used in the end (and text can be on the same line as the end delimiters).

As for the inline display math parser, it checks the full paragraph instead of the current line for display math in certain cases.

Examples

$$$
Math
$$$

(Only displays Math)

1. Hello $$
   Math
   $$
2.

(That is a math environment parsed by the inline display parser)

$$
Math$$
$$
$Math$$
Still Math cause the first didn't close it
$$