hugo-theme-minima icon indicating copy to clipboard operation
hugo-theme-minima copied to clipboard

multiline math was not displayed correctly

Open FlyGinger opened this issue 2 years ago • 11 comments

hi, I want to migrate my blog to minima but I found something unexpected.

$$
\begin{aligned}
T(n) & = c_1 n + c_2 (n - 1) + c_3 (n - 1) + c_4 \sum_{j = 2}^n t_j \\
& + c_5 \sum_{j = 2}^n (t_j - 1) + c_6 \sum_{j = 2}^n (t_j - 1) + c_7 (n - 1)
\end{aligned}
$$

Above math equations were displayed in a single line, and \\ was ignored.

So would you fix this, or there is another way to type a newline?

FlyGinger avatar Jun 17 '22 01:06 FlyGinger

I found that \\\\ can make a linebreak.

It's not cool......

FlyGinger avatar Jun 17 '22 03:06 FlyGinger

I'm not very familiar with this syntax. But could you please provide steps on how to reproduce this locally?

memclutter avatar Nov 13 '22 13:11 memclutter

aligned is used to display multiline math equations, and \\ is used to make a linebreak. For example,

$$
\begin{aligned}
a \\
b
\end{aligned}
$$

This should be rendered as something like

a
b

But now it is

ab

This means that \\ does not make a linebreak correctly. I found that \\\\ can make a linebreak, so there may be extra interpreting step before math render engine (or framework that deals with math).

\\\\ works but is annoying, because I have to use \\\\ to make math display correct on my website, but at the same time it make two linebreak in other place.

FlyGinger avatar Nov 13 '22 13:11 FlyGinger

It is an issue I hadn't solved since I started using Hugo. It is likely that the markdown engine Hugo uses takes every heading \ as an escape character :(

mivinci avatar Nov 13 '22 14:11 mivinci

ok 😃 At least we have a solution \\\\.

FlyGinger avatar Nov 13 '22 14:11 FlyGinger

i found these https://github.com/xsro/xsro.github.io/blob/hugo/layouts/partials/extend_head.html#L1-L24

I have one idea, I'll try to make a pull... but first I need to update the theme for my site :smile:

memclutter avatar Nov 13 '22 20:11 memclutter

\cr might be the most compatible solution by far, also works with other math frameworks.

$$
\begin{aligned}
a \cr
b
\end{aligned}
$$

is also rendered as:

$$ \begin{aligned} a \cr b \end{aligned} $$

mivinci avatar Nov 14 '22 03:11 mivinci

About one year ago GitHub does the same thing when I type math equations. \ was always escaped until one day they fixed this problem, along with the problem of rendering \{ directly into { before Katex was able to touch the code, consequently making many equations incorrectly shown, and I now recommend using \newline and \lbrace instead. If the issue is fixed someday, tex codes using \\\\ due to the current FEATURE will not be shown as you expect, but those things would be shown properly under most circumstances.

szw0407 avatar Nov 02 '23 18:11 szw0407

i found these https://github.com/xsro/xsro.github.io/blob/hugo/layouts/partials/extend_head.html#L1-L24

I have one idea, I'll try to make a pull... but first I need to update the theme for my site :smile:

Seems interesting. However, this script could only be used when Hugo has such FEATURE, is that so?

szw0407 avatar Nov 02 '23 18:11 szw0407

It is an issue I hadn't solved since I started using Hugo. It is likely that the markdown engine Hugo uses takes every heading \ as an escape character :(

Perhaps it is caused by the backslashLineBreak being true in blackfriday. I shall check it later today.

Katex itself supports \\. In many other places such equations are shown correctly using Katex.

Ref: (both written in zh_CN)

https://hugocn.netlify.app/configuration.html#%E9%85%8D%E7%BD%AE%E6%B8%B2%E6%9F%93%E5%BC%95%E6%93%8Eblackfriday%EF%BC%89

https://byteprince.com/posts/2d4e6e67/

szw0407 avatar Nov 02 '23 18:11 szw0407

i found these https://github.com/xsro/xsro.github.io/blob/hugo/layouts/partials/extend_head.html#L1-L24 I have one idea, I'll try to make a pull... but first I need to update the theme for my site 😄

Seems interesting. However, this script could only be used when Hugo has such FEATURE, is that so?

Sadly I guess so 😪

mivinci avatar Nov 07 '23 15:11 mivinci