reuixiy / hugo-theme-meme

😝 You can’t spell awesome without MemE!
http://reuixiy.github.io/hugo-theme-meme
MIT License
1.03k stars 279 forks source link

KateX matrix issue #294

Open colorizer opened 3 years ago

colorizer commented 3 years ago

KateX needs me to escape the \\ in the end of each matrix row. Can there be a workaround that doesn't need me to escape the backslash? It works in mmark (currently using default goldmark) but mmark is having issues with _ and it is already being deprecated by hugo.

The following code works.

$$
\displaystyle{K= \begin{bmatrix}{k_1}_x & {k_1}_y & {k_1}_z \\\\{k_2}_x & {k_2}_y & {k_2}_z \\\\{k_3}_x & {k_3}_y & {k_3}_z \\\\{k_4}_x & {k_4}_y & {k_4}_z \\\\ \end{bmatrix} }
$$

The following doesn't.

$$
\displaystyle{K= \begin{bmatrix}{k_1}_x & {k_1}_y & {k_1}_z \\{k_2}_x & {k_2}_y & {k_2}_z \\{k_3}_x & {k_3}_y & {k_3}_z \\{k_4}_x & {k_4}_y & {k_4}_z \\ \end{bmatrix} }
$$

Thanks!

colorizer commented 3 years ago

The same issue persists for mathjax. It must be a markdown issue.

reuixiy commented 3 years ago

Yeah that's a markdown renderer's issue, or to be precise, a syntax conflict problem between TeX and Markdown,

Characters TeX Markdown
_ Subscript Emphasis
\ Command identifier (?) Escapes

A simple workaround for this is wrapping the related TeX blocks with HTML <div> or <span>(for inline equations) tag, which prevents markdown renderer and no need to add extra escapes in our TeX equations, i.e.:

<div>
$$
  \equation \\
  \equation
$$
</div>

inline equations <span>$x_{1_2}$</span>
colorizer commented 3 years ago

Thanks. That works neatly!

colorizer commented 3 years ago

It seems that only <div> works. <span> doesn't have any effect. For example, <span>$\displaystyle{j\in \left\{ 2, 3, 4 \right\} }$</span> doesn't work but using the same with div works.

reuixiy commented 3 years ago

I can't reproduce that, because the example you paste seems got a TeX syntax error while I'm testing.

FYI, to test if <div> or <span> works, just view-source the rendered HTML code, if the TeX equations within these two tags is same as the raw text in Markdown, then it works; if not, then it doesn't work.

colorizer commented 3 years ago

It seems that <span> doesn't work in my case.

image

I have been using Hugo 0.75.1 as it was the one available in my distro. May be, I should try to update it somehow. Also, I don't know why you are getting an error with tex as it renders fine for me when \ is escaped as in

$\displaystyle{j\in \left\\{ 2, 3, 4 \right\\} }$

image Try running it without the \displaystyle{} may be? Thanks for telling me how <div> and <span> works. I'll let you know if the update solves the issue :)

reuixiy commented 3 years ago

Sorry, my mistake, I didn't notice that...

\{ and \} are highlighted on my editor too. I found these on CommonMark Spec:

Perhaps <div> works because it's a html-blocks according to the spec definition, since <div> doesn't work either if we put it "inline".

colorizer commented 3 years ago

Hi, can shortcode similar to this theme be implemented? It seems that escaping is not required here, even for inline math.

https://github.com/dsrkafuu/hugo-theme-fuji

DEROOCE commented 3 years ago

I also encountered this issue. I try to type {} in mathjax, but either $\{ \}$ or <span>$\{ \}$</span> work. this case also happened in block math: <div>$$\{ \}$$</div>, it just didn't render the right {} brackets . For instance, I write some code like this:

<span>$\boldsymbol{\theta}=\{\boldsymbol{W}\_{\boldsymbol{e}}, \boldsymbol{W}\_{\boldsymbol{m}}, \boldsymbol{b}\_{\boldsymbol{m}}, \boldsymbol{W}, \boldsymbol{b}, \boldsymbol{v}\}$</span>

and return like this: image without any brackets.