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

KateX matrix issue

Open colorizer opened this issue 4 years ago • 9 comments

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 avatar Jan 09 '21 06:01 colorizer

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

colorizer avatar Jan 09 '21 06:01 colorizer

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>

reuixiy avatar Jan 09 '21 10:01 reuixiy

Thanks. That works neatly!

colorizer avatar Jan 09 '21 13:01 colorizer

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.

colorizer avatar Jan 09 '21 13:01 colorizer

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.

reuixiy avatar Jan 09 '21 15:01 reuixiy

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 :)

colorizer avatar Jan 09 '21 17:01 colorizer

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

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

  • https://spec.commonmark.org/0.29/#backslash-escapes
  • https://spec.commonmark.org/0.29/#html-blocks

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".

reuixiy avatar Jan 10 '21 03:01 reuixiy

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

colorizer avatar Feb 16 '21 02:02 colorizer

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.

DEROOCE avatar Mar 15 '21 11:03 DEROOCE