KaTeX / KaTeX

Fast math typesetting for the web.

Home Page:https://katex.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I repace double backslash with '\space'?

apple01150525 opened this issue · comments

Describe the bug:
Hi, I was migrating MathJax to KaTex, but I found that they handle whitespace differently. For example,
$\\frac{1}{6}(\\ \\ \\ \\ )$, It was rendering like this

image

How can I repace double backslash with '\space'? Or is there any way to fix this problem?

Looking forward to your reply.

(La)TeX code:
The code of (La)TeX you tried to render:

$\\frac{1}{6}(\\ \\ \\ \\ )$

Expected behavior:
image

Environment (please complete the following information):

  • KaTeX Version: 0.16.8
  • Device:Desktop
  • OS: Mac
  • Browser: Chrome
  • Version: 115.0.5790.114

Presumably you've got double backslashes because you're feeding KaTeX via a javascript string, correct? It's not really clear why your "double backslash space" is not giving you what you expect here. perhaps you could use a regex to handle the replacement properly, before passing the string to KaTeX?

Or why not avoid the issue altogether and just make use of \hspace like this: \frac{1}{6}(\hspace{0.6cm}). This gives us:

image

Presumably you've got double backslashes because you're feeding KaTeX via a javascript string, correct? It's not really clear why your "double backslash space" is not giving you what you expect here. perhaps you could use a regex to handle the replacement properly, before passing the string to KaTeX?

Or why not avoid the issue altogether and just make use of \hspace like this: \frac{1}{6}(\hspace{0.6cm}). This gives us:

image

Thanks for your advice, I used a string to render a formula and I solved this problem with regex before passing. Due to historical reasons, we have a lot of data like this, and the \ in mathjax means a space but in katex it just renders a \.