Forgot password?
 Create new account
Author: hbghlyj

标记搜索词

[Copy link]

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-18 10:37:15
kuing 发表于 2024-9-17 19:45
这一句运行的时刻,有时先于 tex-svg.js 加载完毕的时刻,所以就变成了未定义?是这样吗?
我刷新了几次,没有出现问题😳
但如果像描述的那样,可能需要将页脚 highlight 部分移到 MathJax 配置 pageReady() 函数中
  1. window.MathJax = {
  2.   startup: {
  3.     pageReady: () => {
  4.       return MathJax.startup.defaultPageReady().then(() => {
  5.         var instance = new Mark(document.body);
  6.         MathJax.typesetPromise().then(()=>instance.mark('highlight'));
  7.       });
  8.     }
  9.   },
  10. ...
Copy the Code

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-18 10:43:19
或者,撤销所有修改并使用77#中的方法,此方法不会因执行顺序而导致错误。😀

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-18 14:23:56
Last edited by kuing at 2024-9-18 14:54:00
hbghlyj 发表于 2024-9-18 10:43
或者,撤销所有修改并使用77#中的方法,此方法不会因执行顺序而导致错误。😀 ...
那是不是也可以弄成只有当链接有 highlight 时才使用 77# 的那段?我不想对平时的有任何影响。

按之前的方法,是不是将 mathjax.php 的内容改成以下?
  1. <script>
  2. window.MathJax = {
  3. <?php if(!empty($_GET['highlight'])) { ?>
  4.   startup: {
  5.     ready: function() {
  6.       const {HTMLDomStrings} = MathJax._.handlers.html.HTMLDomStrings;
  7.       HTMLDomStrings.OPTIONS.includeHtmlTags['mark'] = '';
  8.       var handleTag = HTMLDomStrings.prototype.handleTag;
  9.       HTMLDomStrings.prototype.handleTag = function (node, ignore) {
  10.         if (this.adaptor.kind(node) === 'mark') {
  11.           const text = this.adaptor.textContent(node);
  12.           this.snodes.push([node, text.length]);
  13.           this.string += text;
  14.         }
  15.         return handleTag.call(this, node, ignore);
  16.       }
  17.       MathJax.startup.defaultReady();
  18.     }
  19.   }
  20. <?php } ?>
  21.   tex: {
  22.     inlineMath: [ ['$','$'], ['`','`'], ["\\(","\\)"] ],
  23.     processEscapes: true,
  24.     tags: "ams",
  25.     macros: {
  26.       mbb: '\\mathbb',
  27.       riff: '\\implies',
  28.       liff: '\\impliedby',
  29.       abs: ['\\left\\lvert #1\\right\\rvert', 1],
  30.       rmd: '\\mathop{}\\!\\mathrm{d}',
  31.       vv: '\\overrightarrow',
  32.       sslash: '\\mathrel{/\\mkern-5mu/}',
  33.       px: '\\mathrel{/\\mkern-5mu/}',
  34.       pqd: '\\stackrel{\\smash[b]{/\\!/}}{\\raise-.3ex{=}}',
  35.       veps: '\\varepsilon',
  36.       du: '^\\circ',
  37.       bsb: '\\boldsymbol',
  38.       bm: '\\boldsymbol',
  39.       kongji: '\\varnothing',
  40.       buji: '\\complement',
  41.       S: ['S_{\\triangle #1}', 1],
  42.       led: '\\left\\{\\begin{aligned}',
  43.       endled: '\\end{aligned}\\right.',
  44.       edr: '\\left.\\begin{aligned}',
  45.       endedr: '\\end{aligned}\\right\\}',
  46.       an: '\\{a_n\\}',
  47.       bn: '\\{b_n\\}',
  48.       cn: '\\{c_n\\}',
  49.       xn: '\\{x_n\\}',
  50.       Sn: '\\{S_n\\}',
  51.       inR: '\\in\\mbb R',
  52.       inN: '\\in\\mbb N',
  53.       inZ: '\\in\\mbb Z',
  54.       inC: '\\in\\mbb C',
  55.       inQ: '\\in\\mbb Q',
  56.       Rtt: '\\text{Rt}\\triangle',
  57.       LHS: '\\text{LHS}',
  58.       RHS: '\\text{RHS}',
  59.       arccot: '\\operatorname{arccot}',
  60.       arcsinh: '\\operatorname{arcsinh}',
  61.       arccosh: '\\operatorname{arccosh}',
  62.       arctanh: '\\operatorname{arctanh}',
  63.       arccoth: '\\operatorname{arccoth}',
  64.     },
  65.     autoload: {
  66.       color: [],
  67.       colorv2: ['color']
  68.     },
  69.     packages: {'[+]': ['noerrors','mathtools','xypic']}
  70.   },
  71.   options: {
  72.     ignoreHtmlClass: 'blockcode',
  73.     menuOptions: {
  74.       settings: {
  75.         zoom: "DoubleClick"
  76.       }
  77.     },
  78.     processHtmlClass: 'tex2jax_process',
  79.     renderActions: {
  80.       assistiveMml: []
  81.     }
  82.   },
  83.   //chtml: {
  84.   //  scale: 0.9
  85.   //},
  86.   loader: {
  87.     load: ['[tex]/noerrors','[tex]/mathtools','[custom]/xypic.js'],
  88.     //paths: {custom: '//cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@3.0.1/build'}
  89.     paths: {custom: 'kk'}
  90.   },
  91.   svg: {
  92.     scale: 0.9,
  93.     fontCache: 'global'
  94.   }
  95. };
  96. </script>
  97. <!--<script src="//polyfill.io/v3/polyfill.min.js?features=es6"></script>-->
  98. <!--<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>-->
  99. <!--<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>-->
  100. <script src="mathjax3/es5/tex-svg.js"></script>
  101. <!--<script src="mathjax3/es5/tex-chtml.js"></script>-->
  102. <!--<script src="//unpkg.com/mathjax@3.2.2/es5/tex-svg.js"></script>-->
  103. <!--<script src="//unpkg.com/mathjax@3.2.2/es5/tex-chtml.js"></script>-->
  104. <!--<script src="//cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-svg.min.js"></script>-->
  105. <!--<script src="//cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-chtml.js"></script>-->
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-18 14:58:21
Last edited by kuing at 2024-9-18 16:52:00哦,模板那里还要改回
  1. <!--{if !empty($_GET['highlight'])}-->
  2. <script src="https://cdn.jsdelivr.net/npm/mark.js@8.11.1/dist/mark.min.js"></script>
  3. <script>
  4. var instance = new Mark(document.querySelectorAll(".t_f,.postmessage,.message"));
  5. instance.mark('$_GET['highlight']');
  6. </script>
  7. <!--{/if}-->
Copy the Code
顺便问一下,window.MathJax = ... 和 MathJax = ... 有什么区别?

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-18 17:28:49
kuing 发表于 2024-9-18 06:58
顺便问一下,window.MathJax = ... 和 MathJax = ... 有什么区别?
use strict模式下会有区别:例如,代码
  1. "use strict";
  2. x = 17;
Copy the Code
会抛出错误Uncaught ReferenceError: x is not defined,但将其更改为
  1. "use strict";
  2. window.x = 17;
Copy the Code
将不会出错

Comment

噢噢  Posted at 2024-9-18 17:35
84# 有没有问题?  Posted at 2024-9-18 17:36

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-18 17:39:14
好像 startup: {} 后面应该有一个逗号?在第 19 行

Comment

是是是😄  Posted at 2024-9-18 17:46
没什么其他问题的话,还是深夜测试😁  Posted at 2024-9-18 17:49

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-19 03:30:18
kuing 发表于 2024-9-18 14:23
那是不是也可以弄成只有当链接有 highlight 时才使用 77# 的那段?我不想对平时的有任何影响。

按之前的 ...
貌似已经可以了😊

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-19 15:51:44
Last edited by kuing at 2024-9-26 15:32:00整理一下,以便日后查证。
一、\template\default\forum\viewthread.htm 里 419-431 行(关于 highlight 的)改成
  1. <!--{if !empty($_GET['highlight'])}--><!-- kk edt -->
  2.     <script src="https://cdn.jsdelivr.net/npm/mark.js@8.11.1/dist/mark.min.js"></script>
  3.     <script>
  4.         var instance = new Mark(document.querySelectorAll(".t_f,.postmessage,.message"));
  5.         instance.mark('$_GET['highlight']');
  6.     </script>
  7. <!--{/if}-->
Copy the Code

二、论坛后台“其他头部信息”里将 mathjax 部分删除。
三、在 ./kk/ 下新建 mathjax.php 文件,内容为 84#(19 行需补逗号)
四、在以下两文件
\template\default\common\header_common.htm(管 PC 版)
\template\default\touch\common\header.htm(管手机版)
$_G['setting']['seohead'] 之后添加
  1. <!-- 加载 mathjax 新方式 test at 20240926 -->
  2. <!--{eval include './kk/mathjax.php';}-->
Copy the Code

(注:其实 \source\archiver\common\header.php 也用到 $_G['setting']['seohead'],这是 archiver 版的头部,所以以前 archiver 版也显示公式,但其实没必要,所以这里就不加上面那段代码了)

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-20 23:40:35
kuing 发表于 2024-9-18 19:30
貌似已经可以了
相关:github.com/mathjax/MathJax/issues/3284
这种方法有效,但不明白 MathJax 内部原理
  1. MathJax = {
  2.   startup: {
  3.     ready: function() {
  4.       const {HTMLDomStrings} = MathJax._.handlers.html.HTMLDomStrings;
  5.       HTMLDomStrings.OPTIONS.includeHtmlTags['mark'] = '';
  6.       Object.assign(HTMLDomStrings.prototype, {
  7.         _handleTag_: HTMLDomStrings.prototype.handleTag,
  8.         handleTag(node, ignore) {
  9.           if (this.adaptor.kind(node) !== 'mark') {
  10.             return this._handleTag_(node, ignore);
  11.           }
  12.           this.extendString(node, this.adaptor.textContent(node));
  13.           return this.adaptor.next(node);
  14.         }
  15.       });
  16.       MathJax.startup.defaultReady();
  17.     }
  18.   }
  19. };
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-21 00:03:56
hbghlyj 发表于 2024-9-20 23:40
相关:https://github.com/mathjax/MathJax/issues/3284
这种方法有效,但不明白 MathJax 内部原理
...
反正你们的代码我是一句也看不懂😒

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-21 23:04:50
Last edited by kuing at 2024-9-21 23:15:00咦,我发现“搜索页”和“编辑帖子页”没有加载 mathjax !
看源码能看到我的注释 <!-- 加载 mathjax 新方式 test -->
却没有后面的 mathjax 部分,是 <!--{eval include $_G['style']['tpldirectory'].'/common/mathjax.php';}--> 这句没生效吗?还是说要手写完整地址?

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-21 23:18:37
kuing 发表于 2024-9-21 15:04
却没有后面的 mathjax 部分,是 <!--{eval include $_G['style']['tpldirectory'].'/common/mathjax.php';}--> 这句没生效吗?还是说要手写完整地址?
不懂啊
换作<!--{eval include './template/default/common/mathjax.php';}-->试一下?

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-21 23:33:54
Last edited by kuing at 2024-9-22 22:43:00
hbghlyj 发表于 2024-9-21 23:18
不懂啊
换作试一下?
可以了😊

还真要写完整地址,话说,$_G['style']['tpldirectory'] 会变化的吗?

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-21 23:42:51
kuing 发表于 2024-9-21 15:33
$_G['style']['tpldirectory'] 会变化的吗?
不懂啊
<!--{echo $_G['style']['tpldirectory']}-->试一下?

Comment

我就不试了,你不是在那什么上装了嘛,你自己试一下呗  Posted at 2024-9-21 23:45

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-26 15:29:52
hbghlyj 发表于 2024-9-20 23:40
相关:github.com/mathjax/MathJax/issues/3284
这种方法有效,但不明白 MathJax 内部原理
...
我刚才试过将你的代码替换成他的代码,反而无法显示公式😳

另外我将 mathjax.php 移到 ./kk/ 下了,好找,反正后面都填完整地址。

手机版Mobile version|Leisure Math Forum

2025-4-20 22:18 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list