如何通过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(ortex-svg.jsfor 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 oldtex2jaxdelimiter 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 includedcolor.js).- Note:
AMSmath.jsandAMSsymbols.jsare 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,提问作者放言垢
相关产品推荐
相关产品推荐

