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

Provide more options for MathJax & KaTeX #678

Closed
3 tasks done
pilgrimlyieu opened this issue Jul 23, 2023 · 9 comments
Closed
3 tasks done

Provide more options for MathJax & KaTeX #678

pilgrimlyieu opened this issue Jul 23, 2023 · 9 comments
Labels
Feature Request New feature or request

Comments

@pilgrimlyieu
Copy link

pilgrimlyieu commented Jul 23, 2023

Issue Checklist

Expected behavior

Add detailed options for MathJax & KaTeX. For example adds some macros.(This way seems not pretty, it's just an example. Maybe there are some prettier ways)

math:
  # Default (false) will load mathjax / katex script on demand.
  # That is it only render those page which has `mathjax: true` in front-matter.
  # If you set it to true, it will load mathjax / katex script EVERY PAGE.
  every_page: false

  mathjax:
    enable: false
    # Available values: none | ams | all
    tags: none
    macros:
      "\\R": "{\\bf R}"

  katex:
    enable: false
    # See: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex
    copy_tex: false
    macros:
      "\\R": "{\\bf R}"

Actual behavior

Currently I can only switch on or off MathJax & KaTeX. I can not modify its detailed option.

math:
  # Default (false) will load mathjax / katex script on demand.
  # That is it only render those page which has `mathjax: true` in front-matter.
  # If you set it to true, it will load mathjax / katex script EVERY PAGE.
  every_page: false

  mathjax:
    enable: false
    # Available values: none | ams | all
    tags: none

  katex:
    enable: false
    # See: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex
    copy_tex: false

For example, if I would like to change delimiters(I use \(...\) & \[...\] instead of $...$ & $$...$$) or add some custom macros, I will fail.

Steps to reproduce the behavior

Regardless of it

Other Information

Maybe these websites would help.

I've searched the Internet, read lots of issues, tried many plugins and modified some files while no one satisfied my requests.

I don't know how to achieve it since I didn't have relevant knowledge(like JavaScript) and I failed again and again when I tried.

It'll be appreciated if someone can help me. Thanks in advance

@pilgrimlyieu pilgrimlyieu added the Feature Request New feature or request label Jul 23, 2023
@welcome
Copy link

welcome bot commented Jul 23, 2023

Thanks for opening this issue, maintainers will get back to you as soon as possible!

@stevenjoezhang
Copy link
Member

Delimiters like \(...\) & \[...\] are supported by default: https://docs.mathjax.org/en/latest/input/tex/delimiters.html
You can check if there are other reasons causing the separator not to work. As for the issue with adding macros, I will investigate if there is a convenient solution, or you can edit this file yourself: https://github.com/next-theme/hexo-theme-next/blob/master/source/js/third-party/math/mathjax.js

@pilgrimlyieu
Copy link
Author

pilgrimlyieu commented Jul 25, 2023

Delimiters like \(...\) & \[...\] are supported by default: docs.mathjax.org/en/latest/input/tex/delimiters.html  You can check if there are other reasons causing the separator not to work. As for the issue with adding macros, I will investigate if there is a convenient solution, or you can edit this file yourself: master/source/js/third-party/math/mathjax.js

What about KaTeX? I mainly use KaTeX. Is there a way to achieve it?

@pilgrimlyieu
Copy link
Author

pilgrimlyieu commented Jul 25, 2023

Delimiters like \(...\) & \[...\] are supported by default: docs.mathjax.org/en/latest/input/tex/delimiters.html  You can check if there are other reasons causing the separator not to work. As for the issue with adding macros, I will investigate if there is a convenient solution, or you can edit this file yourself: master/source/js/third-party/math/mathjax.js

Full options support is important in my opinion. Hope there's a way to do it.

Additionally, I think it's inconvenient to write KaTeX & MathJax configs with YAML(specifically dictionary) and it's cumbersome to put every option into one config file.

Specifically speaking, I mean that we can modify KaTeX & MathJax settings in other config file, or JavaScript file.

@pilgrimlyieu
Copy link
Author

pilgrimlyieu commented Aug 2, 2023

Delimiters like \(...\) & \[...\] are supported by default: docs.mathjax.org/en/latest/input/tex/delimiters.html  You can check if there are other reasons causing the separator not to work. As for the issue with adding macros, I will investigate if there is a convenient solution, or you can edit this file yourself: master/source/js/third-party/math/mathjax.js

Hey, is it(Custom Configuration) possible for KaTeX? I'm still searching for solution but there's no new messages from this thread. Thanks!

@pilgrimlyieu
Copy link
Author

Delimiters like \(...\) & \[...\] are supported by default: docs.mathjax.org/en/latest/input/tex/delimiters.html  You can check if there are other reasons causing the separator not to work. As for the issue with adding macros, I will investigate if there is a convenient solution, or you can edit this file yourself: master/source/js/third-party/math/mathjax.js

I've tried to use MathJax under the guide of the doc. However I should use \\\( ... \\\) as InlineMath delimeter instead of simple \( ... \). Besides, the TeX commands in \\\( ... \\\) cann't be rendered properly unless I double the backslash of every command like \\\( \\mathrm{e} \\\). This case would not be replicated if I use $ ... $ as InlineMath delimeters. Is it a bug?

Self Complaint

I turned to brackets delimeters from dollar delimeters because of many reliable and credible reasons, then I met so many issues(not only this one).

@pilgrimlyieu
Copy link
Author

pilgrimlyieu commented Aug 5, 2023

Well, I kept KaTeX and found a solution to add macros. I followed the doc and installed hexo-markdown-it and @renbaoshuo/markdown-it-katex. Then I opened index.js and added & modified the following code.

*const custom_options = {
*    strict: "ignore",
*    macros: {
*    "\\d": "\\mathrm{d}"
*    }
*}
...
*      return katex.renderToString(latex, { ...options, displayMode, ...custom_options });
...

Now I can custom most of settings of KaTeX except delimeters, which means I, exhausted physically and mentally, should make a compromise and adapt to dollar delimeters.

And I found copy-tex cann't take effect. So I downloaded copy-tex.min.js and moved it to source\js\third-party\math and added a line to layout\_third-party\math\katex.njk

<script src="/js/third-party/math/copy-tex.min.js"></script>

Then it worked.

Final question
How can I enable mhchem? I did the same to mhchem.min.js but it didn't work.

@pilgrimlyieu
Copy link
Author

pilgrimlyieu commented Aug 5, 2023

Final question
How can I enable mhchem? I did the same to mhchem.min.js but it didn't work.

Find solution from

In detail, add the starred line to index.js.

 const katex = require('katex');
*require('katex/contrib/mhchem');
 const inline = require('./lib/inline');
 const block = require('./lib/block');

@sghuang19
Copy link
Member

Hi @pilgrimlyieu, seems like you've found a solution, congrats!

Just a quick note that there are too many specifications and packages of LaTeX that we couldn't possibly bring them all in. Math support beyond MathJax and KaTeX will not be something we actively work on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants