javascript - 使用 textcolor 时如何配置 MathJax 以识别等式中的 textrm{}?

标签 javascript html css mathjax

我正在尝试从最近实现它的 LaTEX 文档制作一个 HTML 页面,我在 head 标记之后使用了以下 mathjax,脚本配置:

<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>    
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],

  tex2jax: {
    inlineMath: [ ['$','$'], ["\\(","\\)"] ],
    displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
    processEscapes: true
  },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    "HTML-CSS": { 
      styles: {".MathJax": {color: "#FF0000 ! important"}} 
    }
  });                 

  MathJax.Hub.Queue(
    ["resetEquationNumbers",MathJax.InputJax.TeX],
    ["PreProcess",MathJax.Hub],
    ["Reprocess",MathJax.Hub]
 );
</script>

当我尝试编写以下等式时:

\[
\det A=|A|=\left\{
\begin{array}{ll}
-\textrm{fixation d'une  \textcolor{red}{ligne:}} i=\color{red}{p} \Rightarrow |A|=(-1)^{\color{red}{p}+j}\Delta_{\color{red}{p}j}\\
-\textrm{fixation d'une colonne:  } j=\color{red}{p} \Rightarrow |A|=(-1)^{\color{red}{p}+i}\Delta_{i\color{red}{p}}
\end{array}
\right.
\]

命令 textcolor{red} 不起作用。我可以用 MathJax 做什么来配置它,以便在等式中获得彩色文本?

这是我编译的结果:

screen of my compilation

最佳答案

根据 the documentation ,MathJax 并不关注文本模式,只允许在其文本模式宏(\text{} 等)中使用以下内容:$ 用于重新进入数学模式,\ref\eqref

所以没有办法让 \text 中的 \textcolor 工作。

但是,您可以将 \color 包裹在 \text 周围来为文本着色,因此您可以定义自定义宏 \textwithcolor{red}{some text mode},例如,通过使用 $\require{color}\newcommand{\textwithColor}[2]{\color{#1}{\text{#2}}}\textwithColor{red} {halleo}$

您仍然需要退出文本模式才能使用它。

FWIW,有一个开放的issue for MathJax v3在文本模式下重新考虑宏。

关于javascript - 使用 textcolor 时如何配置 MathJax 以识别等式中的 textrm{}?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51447166/

相关文章:

javascript - Twitter-bootstrap 导航栏下拉菜单表现异常(不在移动设备上工作,不在桌面上显示)

html - IE9标题栏只显示域名不显示页面标题

javascript - 颜色阴影响应 div 的数量

javascript - 允许使用一个或多个连续大写字母和数字的 PascalCased 的正则表达式

javascript - 如何禁用 Highcharts 纵坐标中的 'k' 显示?

php - css样式和对齐问题

html - Bootstrap Carousel 和 <img> 标签与 object-fit & object-position 不工作

css - 修复 Chrome 上的 css/jquery 动画问题

html - 当屏幕尺寸缩小时,div 重叠在另一个 div 上

带有内联 SVG 的 CSS 剪辑路径不起作用