测试网页中MathJax无法加载physics包问题求助
问题原因与解决方案
你的问题核心是MathJax版本与配置语法不兼容:你使用的是MathJax 2.x的CDN链接,但配置代码用的是MathJax 3.x的语法,导致physics包无法正确加载,\qty命令自然无法渲染。
具体修正步骤:
- 替换为MathJax 3.x的CDN链接:原
cdn.mathjax.org已停止维护,且2.x版本不支持你用的loader和tex.packages配置项,需切换到3.x的官方CDN。 - 修正配置语法:MathJax 3.x不再使用
MathJax.Hub.Config,而是直接通过全局配置对象指定参数。 - 确保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
相关产品推荐
相关产品推荐

