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

GitHub Pages中MathJax行内公式多行矩阵显示异常的解决请求

解决MathJax行内公式支持多行内容的问题

问题描述

我在GitHub Pages中使用以下MathJax配置文件mathjax.html:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    TeX: {
      equationNumbers: { autoNumber: "all" },
      tagSide: "right"
    },
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
      processEscapes: true
    }
  });
</script>
<script
  src="https://cdn.jsdelivr.net/gh/mathjax/MathJax@legacy-v2-develop/unpacked/MathJax.js?config=TeX-AMS_CHTML">
</script>

该文件已通过_includes文件夹下的head.html引入:

{% include mathjax.html %}

目前配置运行正常,但行内公式无法支持多行内容。例如用$包裹的多行矩阵代码:

Let $X = \left[ \begin{matrix} X_1 \\ X_2 \end{matrix} \right]$ follow a bivariate normal distribution:

显示异常,只能改用横向矩阵加转置的非预期形式:

Let $X = \left[ \begin{matrix} X_1 & X_2 \end{matrix} \right]^\mathrm{T}$ follow a bivariate normal distribution:

才能正常显示。而用$$包裹的独立公式可正常渲染多行内容,请问如何实现行内公式支持多行?

解决方案

方法1:全局配置行内公式使用显示样式

修改mathjax.html中的MathJax配置,在TeX选项中添加displaystyle: true,让所有行内公式默认使用显示模式排版,从而支持多行结构:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    TeX: {
      equationNumbers: { autoNumber: "all" },
      tagSide: "right",
      displaystyle: true // 新增配置,开启行内公式的显示模式渲染
    },
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
      processEscapes: true
    }
  });
</script>
<script
  src="https://cdn.jsdelivr.net/gh/mathjax/MathJax@legacy-v2-develop/unpacked/MathJax.js?config=TeX-AMS_CHTML">
</script>

配置修改后,原有的多行矩阵行内公式即可正常渲染,无需修改公式代码。

方法2:针对单个行内公式手动开启显示样式

如果不想全局修改行内公式的渲染模式,可在需要支持多行的行内公式前添加\displaystyle命令,强制该公式使用显示模式排版:

Let $\displaystyle X = \left[ \begin{matrix} X_1 \\ X_2 \end{matrix} \right]$ follow a bivariate normal distribution:

这种方法更灵活,适合仅部分行内公式需要多行支持的场景。

内容的提问来源于stack exchange,提问作者Joram Soch

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 05:07:36