找回密码
 快速注册
搜索
查看: 76|回复: 4

[MathJax]阻止MathJax添加任何css

[复制链接]

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-5-8 20:35 |阅读模式
本帖最后由 hbghlyj 于 2024-3-31 12:37 编辑 测试的页面上MathJax添加了一共4个style元素(inline css stylesheet)
image[1].png
但是使用Output/NativeMML后这些css都是无用的.我们在MathJax的startup中的ready函数的defaultReady进行之前加一个步骤,把addStyleSheet这个方法改成空的(也可以delete但是会报错).
  1. ...
  2.     startup: {
  3.         ready: function () {
  4.                 MathJax._.handlers.html.HTMLDocument.HTMLDocument.prototype.addStyleSheet=()=>{};
  5.                 MathJax.startup.defaultReady();
  6.         }
  7.     }
  8. ...
复制代码
源代码:从HTMLDocument.ts第213行开始的public addStyleSheet() {...},从OutputJax.ts第442行开始的public stylesheet(html){⋯⋯}

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-8 20:36
本帖最后由 hbghlyj 于 2024-3-31 12:37 编辑 按照1#修改以后,第4个Style元素被去掉了.但是还剩3个:
image[1].png
我们看一下内容:
image[1].png
我们发现这些css规则是和Context menu有关的,所以应该是MathJax的ui/menu component所加入的,虽然我已经在option中设置了enableMenu:false,但是ui/menu这个组件仍然被预加载了.

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-8 20:45
我们在tex-mml-chtml.js中找到下面这一行:
  1.     e.Loader.preLoad('loader', 'startup', 'core', 'input/tex', 'input/mml', 'output/chtml', 'output/chtml/fonts/tex.js', 'ui/menu', 'a11y/assistive-mml');
复制代码
并改为
  1.     e.Loader.preLoad('loader', 'startup', 'core', 'input/tex', 'input/mml', 'output/chtml', 'output/chtml/fonts/tex.js');
复制代码
即可在预加载中,去掉'ui/menu', 'a11y/assistive-mml'这两个组件.
找到下面这一行:
  1. {"a11y/semantic-enrich":["input/mml","[sre]"],"a11y/complexity":["a11y/semantic-enrich"],"a11y/explorer":["a11y/semantic-enrich","ui/menu"],"[mml]/mml3":["input/mml"],"[tex]/all-packages":["input/tex-base"],"[tex]/action":["input/tex-base","[tex]/newcommand"],⋯⋯⋯
复制代码
并改为
  1. {"[mml]/mml3":["input/mml"],"[tex]/all-packages":["input/tex-base"],"[tex]/action":["input/tex-base","[tex]/newcommand"],⋯⋯⋯
复制代码
找到
  1.     var un = r(5865),
  2.     pn = r(8310),
  3.     hn = r(4001),
  4.     fn = r(473),
  5.     dn = r(4414);
  6.     (0, t.combineWithMathJax) ({
  7.       _: {
  8.         ui: {
  9.           menu: {
  10.             MJContextMenu: un,
  11.             Menu: pn,
  12.             MenuHandler: hn,
  13.             MmlVisitor: fn,
  14.             SelectableInfo: dn
  15.           }
  16.         }
  17.       }
  18.     }),
  19.     MathJax.startup && 'undefined' != typeof window && MathJax.startup.extendHandler((function (t) {
  20.       return (0, hn.MenuHandler) (t)
  21.     }), 20);
  22.     var yn = r(351);
  23.     (0, t.combineWithMathJax) ({
  24.       _: {
  25.         a11y: {
  26.           'assistive-mml': yn
  27.         }
  28.       }
  29.     }),
  30.     MathJax.startup && MathJax.startup.extendHandler((function (t) {
  31.       return (0, yn.AssistiveMmlHandler) (t)
  32.     }));
复制代码
并删掉

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-8 21:12
经过1#和3#的修改以后就没有任何MathJax添加的style元素了

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-7-4 04:32
Making a Custom Build of MathJax
只要在preload里去掉ui/menu组件, MathJax就不会添加CtxtMenu相关的css了
QQ图片20220401132641.png
custom-mathjax.min.js

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

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

Powered by Discuz!

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