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

如何通过CDN在MathJax v3中配置xypic.js

How to Use xypic.js with MathJax v3 via CDN

Got it, let's get your xypic setup working with MathJax v3—since v3 uses a completely different configuration system than v2, that old v2 code won't carry over directly. Here's the step-by-step fix:

Key Differences from MathJax v2

First, forget about MathJax.Ajax.config.path and MathJax.Hub.Config—v3 uses a global MathJax object for all configuration, and extensions like xypic are managed as TeX packages rather than separate scripts to reference via paths.

Full Working Configuration

Replace your old v2 script block with this:

<!-- Load MathJax v3 with TeX input and CHTML output (use tex-svg.js for SVG if preferred) -->
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>

<!-- MathJax v3 Configuration -->
<script>
MathJax = {
  tex: {
    // Match your original inline math delimiters
    inlineMath: [['$', '$'], ['\\(', '\\)']],
    // Add xypic and color extensions to the default TeX packages
    packages: {'[+]': ['xypic', 'color']}
  },
  startup: {
    // Auto-typeset math on page load (default is true, included here for clarity)
    typeset: true
  }
};
</script>

Breakdown of the Configuration

  • CDN Script: We load tex-chtml.js (or tex-svg.js for SVG rendering) which includes the core TeX input processor and output renderer. MathJax automatically fetches the xypic extension from the same CDN, so no need to manually specify paths.
  • tex.inlineMath: This replaces your old tex2jax delimiter setup—keeps the same $...$ and \(...\) inline math syntax you used in v2.
  • tex.packages: The [+] syntax tells MathJax to add these extensions to the default set of TeX packages.
    • xypic: Enables the xypic diagram commands you're used to.
    • color: Adds support for color commands (since your v2 config included color.js).
    • Note: AMSmath.js and AMSsymbols.js are included in MathJax v3's default TeX packages, so you don't need to add them explicitly.

Test It Out

To verify everything works, add a sample xypic diagram to your page:

$$
\xymatrix{
  A \ar[r]^f \ar[d]_g & B \ar[d]^h \\
  C \ar[r]_k & D
}
$$

This should render the commutative diagram just like it did in MathJax v2.

内容的提问来源于stack exchange,提问作者放言垢

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 14:27:32