gohugoio / hugo-goldmark-extensions

Work in progress.
Apache License 2.0
19 stars 6 forks source link

Single equal symbol is parsed as a Markdown header inside a $$ ... $$ block. #17

Open carlohamalainen opened 8 months ago

carlohamalainen commented 8 months ago

Hi,

This is more of a question than an issue.

I had a problem with a math block when I migrated from Jekyll to Hugo. A minimal example:

    input := `$$
P
=
Q
$$
`

P and Q were large matrices so I put them on separate lines.

Goldmark runs the block parsers first and the = is recognised as a header, so it renders to

<h1>$$
P</h1>
<p>Q
$$</p>

I guess this is an inherent limitation because passthrough is an inline parser? So even changing its priority wouldn't help because the block parsers run before the inline parsers?

adding block parser: *parser.setextHeadingParser
adding block parser: *parser.thematicBreakPraser
adding block parser: *parser.listParser
adding block parser: *parser.listItemParser
adding block parser: *parser.codeBlockParser
adding block parser: *parser.atxHeadingParser
adding block parser: *parser.fencedCodeBlockParser
adding block parser: *parser.blockquoteParser
adding block parser: *parser.htmlBlockParser
adding block parser: *parser.paragraphParser
adding inline parser: *parser.codeSpanParser
adding inline parser: *parser.linkParser
adding inline parser: *passthrough.inlinePassthroughParser
adding inline parser: *parser.autoLinkParser
adding inline parser: *parser.rawHTMLParser
adding inline parser: *parser.emphasisParser

An easy workaround is to indent the == by 4 spaces.

jmooring commented 8 months ago

Do this instead:

$$
P
\\=
Q
$$

Lines beginning with these Markdown block level indicators are not passed through: =, -, #, and >.

$$
=
$$

$$
-
$$

$$
#
$$

$$
>
$$
jmooring commented 8 months ago

@j2kun Comments?

carlohamalainen commented 8 months ago

@jmooring thanks for the quick reply.

Do this instead:

$$
P
\\=
Q
$$

Unfortunately that introduces a newline in the equation:

image

I'm expecting:

image

jmooring commented 8 months ago

@carlohamalainen With this:

$$
P
\\=
Q
$$

I get this when using the MathJax engine:

image

And I get this when using the KaTeX engine:

image

This is a known KaTeX issue: https://github.com/KaTeX/KaTeX/issues/437

Usage of the Passthrough extension with Hugo is described here: https://gohugo.io/content-management/mathematics

j2kun commented 8 months ago

I'm at conferences through the weekend but will take a look after. My initial impression is that a good workaround is to use the aligned environment.