找回密码
 快速注册
搜索
查看: 287|回复: 6

mathjax重置编号

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-1-28 12:31 |阅读模式
  1. MathJax.InputJax.TeX.Definitions.Add({
  2.         macros: {
  3.           setCounter: "setCounter"
  4.         }
  5.       }, null, true);
  6.       MathJax.InputJax.TeX.Parse.Augment({
  7.         setCounter: function(name) {
  8.           var num =  parseInt(this.GetArgument(name));
  9.           MathJax.Extension["TeX/AMSmath"].number = num;
  10.         }
  11.       });
复制代码
codepen.io/pkra/pen/YXPQxR
不知在mathjax3里怎样写?

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-1-28 12:40
在官方文档里找到了:
docs.mathjax.org/en/latest/input/tex/extensions/tagformat.html#tex-tagformat
  1. MathJax = {
  2.   startup: {
  3.     ready() {
  4.       const Configuration = MathJax._.input.tex.Configuration.Configuration;
  5.       const CommandMap = MathJax._.input.tex.SymbolMap.CommandMap;
  6.       new CommandMap('sections', {
  7.         nextSection: 'NextSection',
  8.         setSection: 'SetSection',
  9.       }, {
  10.         NextSection(parser, name) {
  11.           MathJax.config.section++;
  12.           parser.tags.counter = parser.tags.allCounter = 0;
  13.         },
  14.         SetSection(parser, name) {
  15.           const n = parser.GetArgument(name);
  16.           MathJax.config.section = parseInt(n);
  17.         }
  18.       });
  19.       Configuration.create(
  20.         'sections', {handler: {macro: ['sections']}}
  21.       );
  22.       MathJax.startup.defaultReady();
  23.     }
  24.   }
  25. };
复制代码
这样便创建了两个指令nextSection和setSection

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-2-17 00:18
本帖最后由 hbghlyj 于 2022-2-17 08:53 编辑 You can reset equation numbering using the command.
MathJax.texReset([start])
where start is the number at which to start equation numbering.

测试:\begin{equation}1+1=2\end{equation}\begin{equation}2+2=4\end{equation}\begin{equation}3+3=6\end{equation}

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-2-17 00:56
3#的MathJax.texReset确实起作用了,但是,它是在MathJax运行之前起作用,于是所有公式的编号都被重置了,如何在文章中间重置编号呢?就像\setcounter{equation}{0}这样?应该需要给MathJax增加定义,这里这里都已经实现了setcounter,但是它们都是MathJax v2,问题是MathJax v3怎么实现setcounter

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-2-26 10:52
docs.mathjax.org/en/latest/input/tex/extensions/tagformat.html#tex-tagformat
找到了
  1. MathJax = {
  2.   startup: {
  3.     ready() {
  4.       const Configuration = MathJax._.input.tex.Configuration.Configuration;
  5.       const CommandMap = MathJax._.input.tex.SymbolMap.CommandMap;
  6.       new CommandMap('sections', {
  7.         nextSection: 'NextSection',
  8.         setSection: 'SetSection',
  9.       }, {
  10.         NextSection(parser, name) {
  11.           MathJax.config.section++;
  12.           parser.tags.counter = parser.tags.allCounter = 0;
  13.         },
  14.         SetSection(parser, name) {
  15.           const n = parser.GetArgument(name);
  16.           MathJax.config.section = parseInt(n);
  17.         }
  18.       });
  19.       Configuration.create(
  20.         'sections', {handler: {macro: ['sections']}}
  21.       );
  22.       MathJax.startup.defaultReady();
  23.     }
  24.   }
  25. };
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-3-23 00:21
本帖最后由 hbghlyj 于 2022-5-8 22:47 编辑 math.stackexchange.com好像自动把每个回答的div的开头加上\begingroup,结尾加上\endgroup,这样就能每个回答分开编号.

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-9 05:46
docs.mathjax.org/en/v2.7-latest/tex.html
The begingroup extension implements commands that provide a mechanism for localizing macro defintions so that they are not permanent. This is useful if you have a blog site, for example, and want to isolate changes that your readers make in their comments so that they don’t affect later comments.

@kuing
可以考虑给帖子的各个楼层加一个\begingroup⋯ ⋯\endgroup的wrapper,就像math.stackexchange.com那样?
For example, if you put \(\begingroup\) at the top of each reader’s comments and \(\endgroup\) at the end, then any macros they define within their response will be removed after it is processed.

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:58

Powered by Discuz!

× 快速回复 返回顶部 返回列表