Skip to content

Katex error on some case #646

Closed

Description

@gxsshallot

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.

Activity

  1. gxsshallot commented on Oct 16, 2018

    @gxsshallot
    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;
        },
      },
    },
    
  2. upupming commented on Oct 25, 2018

    @upupming
    Contributor

    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.

  3. gxsshallot commented on Oct 25, 2018

    @gxsshallot
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions