我正在尝试从最近实现它的 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 做什么来配置它,以便在等式中获得彩色文本?
这是我编译的结果:
最佳答案
根据 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/