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

Katex error on some case #646

Closed
gxsshallot opened this issue Oct 15, 2018 · 3 comments · Fixed by #1390
Closed

Katex error on some case #646

gxsshallot opened this issue Oct 15, 2018 · 3 comments · Fixed by #1390

Comments

@gxsshallot
Copy link

gxsshallot commented Oct 15, 2018

My index.html (created by docsify-cli v4.2.1 and only change body part):

<body>
  <div id="app">加载中</div>
  <script>
    window.$docsify = {
      name: '',
      repo: '',
      markdown: {
        gfm: true,
        tables: true,
      },
      plugins: [
        function (hook) {
          hook.beforeEach(function (content) {
            console.log(content);
            return content
              .replace(/\$([\s\S]*?)\$/g, function (m, code) {
                return katex.renderToString(code, {
                  displayMode: false,
                });
              });
          });
        }
      ]
    }
  </script>
  <script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.js" integrity="sha384-483A6DwYfKeDa0Q52fJmxFXkcPCFfnXMoXblOkJ4JcA8zATN6Tm78UNL72AKk+0O" crossorigin="anonymous"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.css" integrity="sha384-D+9gmBxUQogRLqvARvNLmA9hS2x//eK1FhVb9PiU86gmcrBrJAQT8okdJ4LMp2uv" crossorigin="anonymous">
</body>

Markdown file:

$\{x_n\}$,$\lim\limits_{n \rightarrow \infty} x_n = a$

And it displays incorrect:

2018-10-16 12 44 22

Environment:

  • Mac OS X Mojave 10.14
  • Google Chrome v69.0.3497.100 x64
  • katex v0.10.0-rc.1
  • docsify-cli v4.2.1

I found it change x_n to x<em>n.

@gxsshallot
Copy link
Author

I got it. Because markdown parser will translate _..._ to <em>...</em>. It should be configured to disable em in options:

markdown: {
  renderer: {
    em: function (text) {
      return text;
    },
  },
},

@upupming
Copy link
Contributor

upupming commented Oct 25, 2018

Currently, you parse your math formula with KaTeX, and give the result to docsify's renderer, so the math formula will be rendered again.

Your fix is also not a good idea, because:

  1. All of you italic will be ignored. Instead, we should only disable markdown's _..._ syntax in the math formula, which cannot be implemented in the current renderer.
  2. There are other tags(*...*, which have special meaning in both KaTeX and markdown, but you means it is KaTeX syntax) you need to skip rendering with docsify's renderer.

I'm working on a plugin docsify-katex for writing KaTeX with docsify, but it doesn't very stable yet. Although all KaTeX and markdown are rendered as expected, the sidebar doesn't show as expected.

Update: The sidebar issue has been fixed.

@gxsshallot
Copy link
Author

Currently, you parse your math formula with KaTeX, and give the result to docsify's renderer, so the math formula will be rendered again.

Your fix is also not a good idea, because:

  1. All of you italic will be ignored. Instead, we should only disable markdown's _..._ syntax in the math formula, which cannot be implemented in the current renderer.
  2. There are other tags(*...*, which have special meaning in both KaTeX and markdown, but you means it is KaTeX syntax) you need to skip rendering with docsify's renderer.

I'm working on a plugin docsify-katex for writing KaTeX with docsify, but it doesn't very stable yet. Although all KaTeX and markdown are rendered as expected, the sidebar doesn't show as expected.

Thanks for reply. I will try your plugin later~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants