Forgot password
 Register account
View 515|Reply 6

mathjax重置编号

[Copy link]

3207

Threads

7846

Posts

51

Reputation

Show all posts

hbghlyj posted 2022-1-28 12:31 |Read mode
  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.       });
Copy the Code
codepen.io/pkra/pen/YXPQxR
不知在mathjax3里怎样写?

3207

Threads

7846

Posts

51

Reputation

Show all posts

original poster hbghlyj posted 2022-1-28 12:40
在官方文档里找到了:
docs.mathjax.org/en/latest/input/tex/extensio … t.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. };
Copy the Code
这样便创建了两个指令nextSection和setSection

3207

Threads

7846

Posts

51

Reputation

Show all posts

original poster hbghlyj posted 2022-2-17 00:18
Last edited by hbghlyj 2022-2-17 08:53You 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}

3207

Threads

7846

Posts

51

Reputation

Show all posts

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

3207

Threads

7846

Posts

51

Reputation

Show all posts

original poster hbghlyj posted 2022-2-26 10:52
docs.mathjax.org/en/latest/input/tex/extensio … t.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. };
Copy the Code

3207

Threads

7846

Posts

51

Reputation

Show all posts

original poster hbghlyj posted 2022-3-23 00:21
Last edited by hbghlyj 2022-5-8 22:47math.stackexchange.com好像自动把每个回答的div的开头加上\begingroup,结尾加上\endgroup,这样就能每个回答分开编号.

3207

Threads

7846

Posts

51

Reputation

Show all posts

original poster hbghlyj posted 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.

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-12 12:57 GMT+8

Powered by Discuz!

Processed in 0.013104 seconds, 24 queries