Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aligned 环境中无法换行 #445

Closed
linsui opened this issue May 15, 2019 · 17 comments
Closed

aligned 环境中无法换行 #445

linsui opened this issue May 15, 2019 · 17 comments

Comments

@linsui
Copy link
Contributor

linsui commented May 15, 2019

aligned 环境中使用 \\ 无法换行,但环境外可以换行

批注 2019-05-15 205211

@yzhang-gh
Copy link
Owner

应该要升级一下 KaTeX 版本

@yzhang-gh
Copy link
Owner

升级了也不行,但是看到这个警告

LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]

@upupming
Copy link
Contributor

image
image
旧版本的没有问题呀,是新引入的 BUG 吗?

@linsui
Copy link
Contributor Author

linsui commented May 16, 2019

是新引入的 BUG。问题大概出在这吧
批注 2019-05-16 105845

@upupming
Copy link
Contributor

@yzhang-gh 那边不是显示是 js 的错误吗,你这个是直接看的 html 结果吗?

@linsui
Copy link
Contributor Author

linsui commented May 16, 2019

我对 TS 不了解 😂 ,只是说明一下 BUG 是新引入的。我猜和 #426 有关系 🤔

@yzhang-gh
Copy link
Owner

yzhang-gh commented May 16, 2019

我把 #426 引入的 macros 禁用掉就好了,感觉可能是 KaTeX 的问题,需要用原版的 KaTeX 测试一下


应该就是这么设计的

image


问题变成了如果传的参数是 macros: {},KaTeX 应该忽略 macros,和不传的时候行为应该一样

@yzhang-gh yzhang-gh added the Upstream Pertaining to an upstream component, or blocked by an upstream issue. label May 16, 2019
@linsui
Copy link
Contributor Author

linsui commented May 17, 2019

@yzhang-gh 我没理解你的意思 😕
官方文档描述的行为正好相反,strict=error 时在环境内可以换行,环境外无法换行。
示例
批注 2019-05-17 121800

@yzhang-gh
Copy link
Owner

我前面的意思是说

katex.render("aa\\bb\begin{aligned}aa\\bb\end{aligned}", element, {
  displayMode: true
});

正常,但是

katex.render("aa\\bb\begin{aligned}aa\\bb\end{aligned}", element, {
  displayMode: true,
  macros: {}
});

就不正常,不符合一般的期待


之前我以为后者是符合 KaTeX 的设计的,但是现在看来并不是

@linsui
Copy link
Contributor Author

linsui commented May 17, 2019

这个是正常的,不知道有没有关系 😕

<!DOCTYPE html>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-yFRtMMDnQtDRO8rLpMIKrtPCD5jdktao2TV19YiZYWMDkUR5GQZR/NOVTdquEx1j" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-9Nhn55MVVN0/4OFx7EE5kpFBPsEMZxKTCnA+4fqDmg12eCTqGi6+BB2LjY8brQxJ" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"
    onload="renderMathInElement(document.body, {
            displayMode: true,
            macros: {}
        });"></script>

<body>
    $$
    aa\\bb\\
    \begin{aligned}
        a\\b
    \end{aligned}
    $$
</body>

@yzhang-gh
Copy link
Owner

如果这样是正常的话那应该就不是 KaTeX 的问题了

剩下就只怀疑 markdown-it-katex 的部分

@yzhang-gh yzhang-gh removed the Upstream Pertaining to an upstream component, or blocked by an upstream issue. label May 17, 2019
@upupming
Copy link
Contributor

Some random test, the following code:

const mdkt = require('@neilsustc/markdown-it-katex')
const mdit = require('markdown-it')

let mdString = String.raw`
# Test
$$
aa\\bb\\
\begin{aligned}
    a\\b
\end{aligned}
$$
`

let html = mdit({
  html: true
}).use(mdkt, {
  throwOnError: false,
  macros: {}
}).render(mdString)

console.log(html)

Get html:

<h1>Test</h1>
<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>a</mi><mi>a</mi><mspace linebreak="newline"></mspace><mi>b</mi><mi>b</mi><mspace linebreak="newline"></mspace><mtable rowspacing="0.24999999999999992em" columnalign="right" columnspacing=""><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mi>a</mi></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mi>b</mi></mstyle></mtd></mtr></mtable></mrow><annotation encoding="application/x-tex">aa\\bb\\
\begin{aligned}
    a\\b
\end{aligned}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">a</span><span class="mord mathdefault">a</span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathdefault">b</span><span class="mord mathdefault">b</span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:3.0000000000000004em;vertical-align:-1.2500000000000002em;"></span><span class="mord"><span class="mtable"><span class="col-align-r"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.7500000000000002em;"><span style="top:-3.91em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault">a</span></span></span><span style="top:-2.41em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault">b</span></span></span></span><span class="vlist-s"></span></span><sp
an class="vlist-r"><span class="vlist" style="height:1.2500000000000002em;"><span></span></span></span></span></span></span></span></span></span></span></span></p>

which will be rendered as following:
image
So there is no problem with markdown-it-katex at all.

@upupming
Copy link
Contributor

I have fixed, a PR will come soon.

upupming added a commit to upupming/vscode-markdown that referenced this issue May 19, 2019
@yzhang-gh
Copy link
Owner

Please try out the latest dev build.

@linsui
Copy link
Contributor Author

linsui commented May 19, 2019

这里没问题 👍

@upupming
Copy link
Contributor

Problem still exists if the user defines a macros:

  "markdown.extension.katex.macros": {
    "\\ssss": "\\frac{1}{22}"
  },
# Test

$$
aa\\bb\\
\begin{aligned}
    a\\b
\end{aligned}
\\
\ssss
$$

image

@yzhang-gh
Copy link
Owner

多谢 @upupming,合并 PR 之后应该是真正解决了

@linsui linsui closed this as completed May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants