You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

测试网页中MathJax无法加载physics包问题求助

问题原因与解决方案

你的问题核心是MathJax版本与配置语法不兼容:你使用的是MathJax 2.x的CDN链接,但配置代码用的是MathJax 3.x的语法,导致physics包无法正确加载,\qty命令自然无法渲染。

具体修正步骤:

  1. 替换为MathJax 3.x的CDN链接:原cdn.mathjax.org已停止维护,且2.x版本不支持你用的loader和tex.packages配置项,需切换到3.x的官方CDN。
  2. 修正配置语法:MathJax 3.x不再使用MathJax.Hub.Config,而是直接通过全局配置对象指定参数。
  3. 确保physics包正确加载:3.x中加载physics包的语法更简洁,无需混合2.x的配置项。

修正后的完整代码:

<head>
    <title>MathJax TeX Test Page</title>
    <script>
      window.MathJax = {
        tex: {
          inlineMath: [['$', '$'], ['\\(', '\\)']],
          equationNumbers: { autoNumber: 'AMS' },
          packages: {'[+]': ['physics']}
        },
        svg: {
          fontCache: 'global'
        }
      };
    </script>
    <script type="text/javascript" id="MathJax-script" async
      src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
    </script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Audiowide|Sofia|Tai+Heritage+Pro|Trykker|Tiro+Telugu|Vesper+Libre|Brawler|Georama|Fjord+One|Trirong|Fresca|Anonymous+Pro|Baskervville">
    <style>
      body {
        font-family: 'Baskervville', serif;
        font-size: 20px;
      }
    </style>
</head>
<body>
    When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
    \begin{equation}
    \color{red}{x = {-b \pm \sqrt{b^2-4ac} \over 2a}}.  
    \end{equation}
    Now $\qty[ c ]$ renders correctly!
</body>

关键说明:

  • 3.x版本中,tex-svg.js是推荐的渲染器(也可选择tex-mml-chtml.js等),自动处理包的加载,无需额外指定loader。
  • 原代码中的HTML-CSS配置是2.x的,3.x对应使用svg或chtml的配置项。
  • 无需手动\require{physics},因为配置中已经将physics包加入到加载列表中。

内容的提问来源于stack exchange,提问作者Ted Black

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 11:10:25