Forgot password?
 Create new account
Author: hbghlyj

标记搜索词

[Copy link]

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-15 23:46:19
hbghlyj 发表于 2024-9-15 23:30
本地搭建discuz是将Discuz!论坛系统部署在本地计算机上,通过搭建本地服务器环境,模拟线上环境进行开发 ...
既然是这样,那你自己搭建一个在你电脑上,然后用 50# 的方式,将 53# 的 <?php echo d;?> 等等都改成 {d} 等,保存为 mathjax.php 放到 /template/default/common/ ,再用 <!--{template common/mathjax}--> 调用,看看是什么结果。

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-15 23:56:45
kuing 发表于 2024-9-15 15:46
既然是这样,那你自己搭建一个在你电脑上,然后用 50# 的方式,将 53# 的 <?php echo d;?> 等等都改成 {d ...

更方便的方法是使用 php 在线测试器
我在 onlinephp.io/ 中运行以下代码,没有错误。
  1. <script>
  2. window.MathJax = {
  3. <?php if(!empty($_GET['highlight'])) { ?>
  4.   startup: {
  5.     typeset: false
  6.   },
  7. <?php } ?>
  8.   tex: {
  9.     inlineMath: [ ['$','$'], ['`','`'], ["\\(","\\)"] ],
  10.     processEscapes: true,
  11.     tags: "ams",
  12.     macros: {
  13.       mbb: '\\mathbb',
  14.       riff: '\\implies',
  15.       liff: '\\impliedby',
  16.       abs: ['\\left\\lvert #1\\right\\rvert', 1],
  17.       rmd: '\\mathop{}\\!\\mathrm{d}',
  18.       vv: '\\overrightarrow',
  19.       sslash: '\\mathrel{/\\mkern-5mu/}',
  20.       px: '\\mathrel{/\\mkern-5mu/}',
  21.       pqd: '\\stackrel{\\smash[b]{/\\!/}}{\\raise-.3ex{=}}',
  22.       veps: '\\varepsilon',
  23.       du: '^\\circ',
  24.       bsb: '\\boldsymbol',
  25.       bm: '\\boldsymbol',
  26.       kongji: '\\varnothing',
  27.       buji: '\\complement',
  28.       S: ['S_{\\triangle #1}', 1],
  29.       led: '\\left\\{\\begin{aligned}',
  30.       endled: '\\end{aligned}\\right.',
  31.       edr: '\\left.\\begin{aligned}',
  32.       endedr: '\\end{aligned}\\right\\}',
  33.       an: '\\{a_n\\}',
  34.       bn: '\\{b_n\\}',
  35.       cn: '\\{c_n\\}',
  36.       xn: '\\{x_n\\}',
  37.       Sn: '\\{S_n\\}',
  38.       inR: '\\in\\mbb R',
  39.       inN: '\\in\\mbb N',
  40.       inZ: '\\in\\mbb Z',
  41.       inC: '\\in\\mbb C',
  42.       inQ: '\\in\\mbb Q',
  43.       Rtt: '\\text{Rt}\\triangle',
  44.       LHS: '\\text{LHS}',
  45.       RHS: '\\text{RHS}',
  46.       arccot: '\\operatorname{arccot}',
  47.       arcsinh: '\\operatorname{arcsinh}',
  48.       arccosh: '\\operatorname{arccosh}',
  49.       arctanh: '\\operatorname{arctanh}',
  50.       arccoth: '\\operatorname{arccoth}',
  51.     },
  52.     autoload: {
  53.       color: [],
  54.       colorv2: ['color']
  55.     },
  56.     packages: {'[+]': ['noerrors','mathtools','xypic']}
  57.   },
  58.   options: {
  59.     ignoreHtmlClass: 'blockcode',
  60.     menuOptions: {
  61.       settings: {
  62.         zoom: "DoubleClick"
  63.       }
  64.     },
  65.     processHtmlClass: 'tex2jax_process',
  66.     renderActions: {
  67.       assistiveMml: []
  68.     }
  69.   },
  70.   //chtml: {
  71.   //  scale: 0.9
  72.   //},
  73.   loader: {
  74.     load: ['[tex]/noerrors','[tex]/mathtools','[custom]/xypic.js'],
  75.     //paths: {custom: '//cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@3.0.1/build'}
  76.     paths: {custom: 'kk'}
  77.   },
  78.   svg: {
  79.     scale: 0.9,
  80.     fontCache: 'global'
  81.   }
  82. };
  83. </script>
  84. <!--<script src="//polyfill.io/v3/polyfill.min.js?features=es6" type="text/javascript"></script>-->
  85. <!--<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" type="text/javascript"></script>-->
  86. <!--<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" type="text/javascript"></script>-->
  87. <script src="mathjax3/es5/tex-svg.js" type="text/javascript"></script>
  88. <!--<script src="mathjax3/es5/tex-chtml.js" type="text/javascript"></script>-->
  89. <!--<script src="//unpkg.com/mathjax@3.2.2/es5/tex-svg.js" type="text/javascript"></script>-->
  90. <!--<script src="//unpkg.com/mathjax@3.2.2/es5/tex-chtml.js" type="text/javascript"></script>-->
  91. <!--<script src="//cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-svg.min.js" type="text/javascript"></script>-->
  92. <!--<script src="//cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-chtml.js" type="text/javascript"></script>-->
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-16 00:04:36
hbghlyj 发表于 2024-9-15 23:56
更方便的方法是使用 php 在线测试器
我在 onlinephp.io/ 中运行以下代码,没有错误。
...
运行代码没错是一回事,discuz 的模板调用它又是另一回事,你先试试再说吧,反正我刚才就没成功,完全是按照之前说的方法做的。

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 00:50:31
kuing 发表于 2024-9-15 16:04
反正我刚才就没成功


好的,我将安装 x3.5,请稍候

Comment

装 x3.5 要很久吗?是装在本地还是服务器?  Posted at 2024-9-16 01:41
还是没找到问题所在。我这边输出好像正确🤔  Posted at 2024-9-16 04:11
具体说说你的操作过程?  Posted at 2024-9-16 07:10

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 12:40:24

在 GitHub codespace 上安装 Discuz X3.5

爪机专用 发表于 2024-9-15 23:10
具体说说你的操作过程?
转到 github.com/hbghlyj/DiscuzX 此存储库包含一个 Discuz X3.5 docker 镜像
单击“Codespace”按钮,单击“Codespaces”,创建新的Codespace
  1. apache2ctl start
Copy the Code

返回 GitHub 页面,点击 Codespaces
点击“Open in Visual Studio code”
然后 VScode 将启动。
等待它连接到远程 Codespace
Screenshot 2024-09-16 125102.png
在浏览器中打开端口80
安装 Discuz,记得将数据库服务器设置为 localhost:3306
密码是 mariadb
Screenshot 2024-09-16 123828.png
之后,再次转到端口 80,您应该会看到您的论坛已启动!由于 docker 镜像中的端口 80 被转发到本地主机端口 80,因此在浏览器地址上显示为 127.0.0.1。 Screenshot 2024-09-16 125742.png
在 vscode 中点击“Open folder”
打开 /var/www/html 你应该可以看到远程 Codespace 上的文件。这使得编辑远程文件变得非常容易
Screenshot 2024-09-16 130210.png
在许多文件中搜索/替换字符串也很容易。这些 vscode 功能使编辑远程文件几乎与编辑本地文件一样 Screenshot 2024-09-16 131010.png

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 13:59:00
kuing 发表于 2024-9-15 16:04
discuz 的模板调用它又是另一回事 ...

我同意,Discuz 模板系统带来很多麻烦,我们必须绕过它。

只需将 <!--{template common/mathjax}--> 替换为
  1. <!--{eval include $_G['style']['tpldirectory'].'/common/mathjax.php';}-->
Copy the Code

这将直接包含 php 文件,而不是先通过 Discuz 模板对其进行解析。

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 14:23:44
@kuing 我测试过了。替换代码后
Screenshot 2024-09-16 142022.png


头部代码完全正确

Screenshot 2024-09-16 142104.png


如果 url 带有参数 highlight= ,它仍然完全正确

Screenshot 2024-09-16 142511.png

Comment

深夜再试,以免影响用户使用  Posted at 2024-9-16 14:55

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 14:29:31
kuing 发表于 2024-9-15 17:41
装 x3.5 要很久吗?是装在本地还是服务器?

所花费的时间是用于编写正确的 Docker 文件。因为我之前没有 DiscuzX docker 文件,也没有编写 Docker 文件的经验。
但毕竟,现在它可以工作了。
我已将 Docker 文件放在该 repo 上。可以像上面一样设置 DiscuzX docker,只需不到半小时,即可开始本地测试

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 14:37:45
hbghlyj 发表于 2024-9-16 05:59
只需将 <!--{template common/mathjax}--> 替换为
<!--{eval include $_G['style']['tpldirectory'].'/common/mathjax.php';}-->
不要忘记 mathjax.php 应该在上传后设置文件可执行权限,因为默认情况下禁止执行 php

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 14:48:53
hbghlyj 发表于 2024-9-16 05:59
只需将 <!--{template common/mathjax}--> 替换为
<!--{eval include $_G['style']['tpldirectory'].'/common/mathjax.php';}-->

@kuing 现在这样可以吗?在我这边可以正常工作。如截图所示

没有参数“highlight=”有参数“highlight=”

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-16 14:55:34
hbghlyj 发表于 2024-9-16 13:59
我同意,Discuz 模板系统带来很多麻烦,我们必须绕过它。

只需将 <!--{template common/mathjax}--> 替换 ...
那你当时用 <!--{template common/mathjax}--> 时会出现什么情况?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 14:57:47
kuing 发表于 2024-9-16 06:55
那你当时用 <!--{template common/mathjax}--> 时会出现什么情况?
当时我修改了/data/template/1_1_common_mathjax.tpl.php 所以正常
所以我没有意识到问题是模板解析直到我刷新缓存时我才意识到问题是模板解析

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 15:01:44
这次我们努力把docker镜像弄好了,下次我们就可以在GitHub CodeSpace上重用这个docker镜像。

GitHub Codespace 很棒:无需本地安装 php,也无需租用服务器。

甚至有人搞清楚了如何在 GitHub Codespace 上运行 Wordpress(一款流行的非常复杂的 php 软件)
screen[2].png

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 15:13:57
在此之后,MathJax 配置就会动态生成,因此我们可以应用多项检查来生成 MathJax 配置,例如,我们可以检测页面上 xy 环境的使用,仅当页面使用 xy 环境时才加载 xyjax 脚本。

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 15:16:23
我有一个问题,将 MathJax 放在页面顶部或底部哪个更好?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 16:00:05

第二种方式,不需要添加模板,保留seohead但把新增的“if”块放在seohead前面

kuing 发表于 2024-9-15 12:37
“其他头部信息”里除了 mathjax 还有其他东西,所以 $_G['setting']['seohead'] 还是应该保留。

你的意 ...
是的,应该保留seohead但在它之前添加“if”块。

将 MathJax 移到seohead顶部,第一行是“window.MathJax = {”,我们将这一行移到seohead之外

用以下内容替换$_G['setting']['seohead']
  1. window.MathJax = {
  2. <!--{if !empty($_GET['highlight'])}-->
  3.   startup: {
  4.     typeset: false
  5.   },
  6. <!--{/if}-->
  7. $_G['setting']['seohead']
Copy the Code

我们只在 $_G['setting']['seohead'] 之前添加了内容,并没有将其删除。

这将产生预期的效果,并且比模板更有优势,因为“seohead”的内容不会被解析,“seohead”的内容中保留了原始的 MathJax 配置。

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 16:03:05

第三种方式,不需要修改任何服务器端代码,只需要更改 mathjax 配置

kuing 发表于 2024-9-15 08:13
如何做到确保先 mathjax 再 mark?

不必确保 mathjax 的执行顺序。

我们让 mathjax 将任何公式中出现的任何 <mark> 标签替换为其文本内容。

无论是在 mark 之前还是之后执行 MathJax,这都可以确保关键字正确显示。

因此,这种方法不需要更改任何服务器端代码,我们只需要更改 mathjax 配置。

我们将 MathJax 配置为
  • MathJax 公式中的 <mark> 标签会被替换为其内容。
  • 不在公式中的 <mark> 标签则保持不变。

例如,将以下代码保存为 HTML
  1. <script>
  2. MathJax = {
  3.   startup: {
  4.     ready: function() {
  5.       const {HTMLDomStrings} = MathJax._.handlers.html.HTMLDomStrings;
  6.       HTMLDomStrings.OPTIONS.includeHtmlTags['mark'] = '';
  7.       var handleTag = HTMLDomStrings.prototype.handleTag;
  8.       HTMLDomStrings.prototype.handleTag = function (node, ignore) {
  9.         if (this.adaptor.kind(node) === 'mark') {
  10.           const text = this.adaptor.textContent(node);
  11.           this.snodes.push([node, text.length]);
  12.           this.string += text;
  13.         }
  14.         return handleTag.call(this, node, ignore);
  15.       }
  16.       MathJax.startup.defaultReady();
  17.     }
  18.   }
  19. };
  20. </script>
  21. <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
  22. <mark>x_2</mark> \(x_1+<mark>x_2</mark>+x_3\)
Copy the Code

输出结果如下图所示
124126yzqqrjlnnqiqqq6j.png

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-16 20:40:35
因为 Discuz 有模板系统,所以总是有两个版本的文件(一个是原始的,一个是解析过的)
也许可以让模板在解析时出现语法错误时保留以前的解析过的版本,这样用户就不会看到错误
将错误记录到错误日志中,也可以事后调查错误

当前系统直到该文件被访问才解析模板文件,有点不方便
更智能的系统,例如,Webpack 可以监视文件并在文件发生变化时重新编译

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-17 23:52:07
hbghlyj 发表于 2024-9-17 23:27
好的,测试结果怎么样🙂
昨晚顾着找片下片看片,忘了……

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-9-18 03:45:23
Last edited by kuing at 2024-9-18 04:14:00
hbghlyj 发表于 2024-9-17 23:27
好的,测试结果怎么样🙂
尝试了
  1. <!--{eval include $_G['style']['tpldirectory'].'/common/mathjax.php';}-->
Copy the Code
的方法,头部确实没问题。

但实际看带 highlight 的链接时,公式有时显示有时不显示,你可以看看这个链接:
kuing.cjhb.site/forum.php?mod=viewthread& … hlight=%5Cint_u%5Eck
不断刷新就会显现。
当公式不显示时,关键词也不会高亮,这时打开控制台,会看到:
Uncaught TypeError: MathJax.typesetPromise is not a function

是页尾的
  1. MathJax.typesetPromise().then(()=>instance.mark('$_GET['highlight']'));
Copy the Code
这句的问题吗?
这一句运行的时刻,有时先于 tex-svg.js 加载完毕的时刻,所以就变成了未定义?是这样吗?

手机版Mobile version|Leisure Math Forum

2025-4-20 22:11 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list