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

\[ and \( as delimiters #22

Open
ianqsong opened this issue Jul 29, 2024 · 3 comments
Open

\[ and \( as delimiters #22

ianqsong opened this issue Jul 29, 2024 · 3 comments
Labels
feature-request Request for new features or functionality

Comments

@ianqsong
Copy link

This plug-in seems only support dollar signs as delimiters, but \[ and \( are also widely used (e.g. math formula in response from chatgpt). I was wondering if these would be supported here.

@hopkins385
Copy link

True. Can we add configurable delimiters?

@TuringJest
Copy link

+1

@ShaunDychko
Copy link

ShaunDychko commented Dec 4, 2024

As a workaround it's possible to preprocess the markdown text to replace \( style delimiters with $-style delimiters.
The KaTeX project provides the file contrib/auto-render/splitAtDelimiters.js which can be used in a custom script normalizeDelimiters.js:

import splitAtDelimiters from "./splitAtDelimiters";
const normalizeDelimiters = (markdownText) => {
  const data = splitAtDelimiters(markdownText, [
    {left: "\\[", right: "\\]", display: true},
    {left: "\\(", right: "\\)", display: false},
  ]);
  let result = "";
  data.forEach((segment) => {
    if (segment.type === "text") {
      result += segment.data;
    }
    else if (segment.type === "math") {
      result += segment.display ? `$$${segment.data}$$` : `$${segment.data}$`;
    }
  })
  return result;
}

export default normalizeDelimiters;

@vscode/markdown-it-katex should probably consider replacing the custom parsing done in src/index.ts by leveraging contrib/auto-render/splitAtDelimiters.js from the KaTeX project.

@mjbvz mjbvz added the feature-request Request for new features or functionality label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants