Forgot password?
 Create new account
Author: hbghlyj

标记搜索词

[Copy link]

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 17:40:10
kuing 发表于 2024-9-15 09:25
好像不行呀,是我代码写错了吗?
我们应该修改 head 中的 MathJax 配置,因为 MathJax 只能在执行前读取其配置,而无法在排版完成后读取 MathJax 配置。

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 17:42:34
kuing 发表于 2024-9-15 09:38

<!--{if !empty($_GET['highlight'])}-->
<script>
MathJax = {
  startup: {
    typeset: false
  }
}
</script>
<!--{/if}-->
写在头部吗?
刚才想建议将此项 startup: {typeset: false} 合并到现有配置window.MathJax = {,这样 MathJax 配置就只需要一个 <script> 标签。

  1. window.MathJax = {
  2. <!--{if !empty($_GET['highlight'])}-->
  3.   startup: {
  4.     typeset: false
  5.   },
  6. <!--{/if}-->
  7.   ...
  8.   ...
  9. }
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 17:46:44
hbghlyj 发表于 2024-9-15 17:42
刚才想建议将此项 startup: {typeset: false} 合并到现有配置,这样 MathJax 配置就只需要一个 <script>  ...
问题是这样是否影响了其他网页的 mathjax

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 17:49:03
kuing 发表于 2024-9-15 09:46
问题是这样是否影响了其他网页的 mathjax
对于没有“highlight=”的页面,该行将不会出现在 MathJax 配置中,因为它被 if 条件处理为不包含在内

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 17:52:38
kuing 发表于 2024-9-15 09:46
问题是这样是否影响了其他网页的 mathjax
没有“highlight=”的页面将与以前完全相同

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 17:56:58
hbghlyj 发表于 2024-9-15 17:49
对于没有“highlight=”的页面,该行将不会出现在 MathJax 配置中,因为它被 if 条件处理为不包含在内 ...
我那段代码是在论坛后台的“其他头部信息”那里加的,那里的 <!--{if !empty($_GET['highlight'])}--> 好像没用……

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 18:05:15
kuing 发表于 2024-9-15 09:56
我那段代码是在论坛后台的“其他头部信息”那里加的
$_G['setting']['seohead']变量代表网站的“其他头部信息”
2564835-20230916194217718-325377522[1].png
直接修改模板效果一样

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 18:13:36
kuing 发表于 2024-9-15 09:56
我那段代码是在论坛后台的“其他头部信息”那里加的,那里的 <!--{if !empty($_GET['highlight'])}--> 好像没用……
建议将其移至 /template/default/common/header_common.htm,它将变得更容易控制。

如果将来需要更复杂的控制,也会更方便。

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 18:22:26
hbghlyj 发表于 2024-9-15 18:13
建议将其移至 /template/default/common/header_common.htm,它将变得更容易控制。

如果将来需要更复杂 ...
我看了下,\template\default\touch\common\header.htm 也引用了 $_G['setting']['seohead'] 这个变量,如果只移到 header_common.htm,那这个 touch 的 header.htm 就没了这段,是否会使得手机版页面没有 mathjax?(其实我已经记不清楚这个是不是管手机版的了……

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 18:31:48
kuing 发表于 2024-9-15 10:22
我看了下,\template\default\touch\common\header.htm 也引用了 $_G['setting']['seohead'] 这个变量, ...
如果想避免重复代码,只需将该代码放入新模板,然后包含该模板。由于 if 条件将在模板中执行,因此一切都将按预期正常工作。

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 18:31:55
hbghlyj 发表于 2024-9-15 18:26
我们可以将其复制到引用变量 $_G['setting']['seohead'] 的任何位置,这样一切都会按预期正常工作 ...
那将来有改动岂不相当麻烦?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 18:38:19
kuing 发表于 2024-9-15 10:31
那将来有改动岂不相当麻烦?
我有一个想法:将那段 MathJax 配置代码移动到模板 mathjax.htm 中,然后包含该模板。
由于 if 条件将在模板中执行,因此一切都将按预期正常工作。
这样做有两个好处:一是代码模块化,方便后期修改;二是以后我们可以把模板发布到 Discuz 模板共享网

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 18:46:18
hbghlyj 发表于 2024-9-15 18:38
我有一个想法:将那段 MathJax 配置代码移动到模板 mathjax.htm 中,然后包含该模板。
由于 if 条件将在模 ...
具体如何操作?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 18:51:47
kuing 发表于 2024-9-15 10:46
具体如何操作?

模板嵌套

  • 将被嵌套模板内容解析为PHP语句并合并入本模板中的写法
    • common/header 对应某个模板套系中的common目录的header.htm模板文件
<!--{subtemplate common/header}-->
  • 程序运行时include嵌套模板内容
<!--{template common/header}-->

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 18:56:49
kuing 发表于 2024-9-15 10:46
具体如何操作?
我想我们应该用以下代码替换所有的 $_ G['setting']['seohead']
<!--{template common/mathjax}-->

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 19:10:22
以上讨论都是关于帖子查看页面的。
搜索结果页面上的关键字似乎不会干扰 mathjax 上下文菜单。我们需要修改它吗?
Screenshot 2024-09-15 190928.png

Comment

这个先不管拉  Posted at 2024-9-15 20:26

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 20:37:46
hbghlyj 发表于 2024-9-15 18:56
我想我们应该用以下代码替换所有的 $_ G['setting']['seohead']
<!--{template common/mathjax}--> ...
“其他头部信息”里除了 mathjax 还有其他东西,所以 $_G['setting']['seohead'] 还是应该保留。

你的意思,是不是现在要将 mathjax 的部分写在一个 mathjax.htm 里,然后放入 /template/default/common/ 里面,再在需要的地方加 <!--{template common/mathjax}-->?
(我感觉其实就两个地方需要,就是你说的那个和我说的 touch 那个)

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 21:01:51
kuing 发表于 2024-9-15 20:37
...
你的意思,是不是现在要将 mathjax 的部分写在一个 mathjax.htm 里,然后放入 /template/default/common/ 里面,再在需要的地方加 <!--{template common/mathjax}-->?
...

刚才试了一下,结果就报错了,搞模板是真不会😔
Discuz! System Error
Time: 2024-09-15 21:00:06 +0800 IP: 218.19.138.21 BackTraceID: d2e69c87aee5e25649f8e154938d0b99

Undefined constant "d"
PHP Debug

No.        File        Line        Code
1        forum.php        71        require(%s)
2        source/module/forum/forum_viewthread.php        1030        include(%s)
3        data/template/1_diy_forum_viewthread.tpl.php        10        include(%s)
4        data/template/1_1_common_header_forum_viewthread.tpl.php        15        include()
5        data/template/1_1_common_mathjax.tpl.php        18        break()

Comment

似乎在模板第 18 行未定义常量“d”  Posted at 2024-9-15 21:12
模板的第 18 行是什么?  Posted at 2024-9-15 21:12

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 21:04:01
kuing 发表于 2024-9-15 13:01
刚才试了一下,结果就报错了,搞模板是真不会😔
抱歉,之前的方法太过复杂
请看一下新方法,它不涉及任何服务器端代码,只需修补 MathJax 配置就足够了:我们修改 MathJax 让它将所有 <mark> 标签视为文本

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 21:08:20
由于我们修改 MathJax 让它将所有 <mark> 标签视为文本,因此即使公式中包含 <mark> 标签,它也会对其进行排版

手机版Mobile version|Leisure Math Forum

2025-4-20 22:11 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list