hexo-theme-next
hexo-theme-next copied to clipboard
Provide more options for MathJax & KaTeX
Issue Checklist
- [X] I am using NexT version 8.0 or later.
- [X] I have already read the Troubleshooting page of Hexo and Troubleshooting page of NexT.
- [X] I have already searched for current issues, which does not help me.
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
Thanks for opening this issue, maintainers will get back to you as soon as possible!
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
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?
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.
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!
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).
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.
Final question How can I enable
mhchem
? I did the same tomhchem.min.js
but it didn't work.
Find solution from
- waylonflinn/markdown-it-katex#38
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');