Forgot password?
 Create new account
View 215|Reply 4

[MathJax]阻止MathJax添加任何css

[Copy link]

3151

Threads

8498

Posts

610K

Credits

Credits
66208
QQ

Show all posts

hbghlyj Posted at 2022-5-8 20:35:02 |Read mode
Last edited by hbghlyj at 2024-3-31 12:37:00测试的页面上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. ...
Copy the Code
源代码:从HTMLDocument.ts第213行开始的public addStyleSheet() {...},从OutputJax.ts第442行开始的public stylesheet(html){⋯⋯}

3151

Threads

8498

Posts

610K

Credits

Credits
66208
QQ

Show all posts

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

3151

Threads

8498

Posts

610K

Credits

Credits
66208
QQ

Show all posts

 Author| hbghlyj Posted at 2022-5-8 20:45:15
我们在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');
Copy the Code
并改为
  1.     e.Loader.preLoad('loader', 'startup', 'core', 'input/tex', 'input/mml', 'output/chtml', 'output/chtml/fonts/tex.js');
Copy the Code
即可在预加载中,去掉'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"],⋯⋯⋯
Copy the Code
并改为
  1. {"[mml]/mml3":["input/mml"],"[tex]/all-packages":["input/tex-base"],"[tex]/action":["input/tex-base","[tex]/newcommand"],⋯⋯⋯
Copy the Code
找到
  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.     }));
Copy the Code
并删掉

3151

Threads

8498

Posts

610K

Credits

Credits
66208
QQ

Show all posts

 Author| hbghlyj Posted at 2022-5-8 21:12:08
经过1#和3#的修改以后就没有任何MathJax添加的style元素了

3151

Threads

8498

Posts

610K

Credits

Credits
66208
QQ

Show all posts

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

手机版Mobile version|Leisure Math Forum

2025-4-21 14:09 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list