如何为MathJax逃脱双反斜杠? [英] How do I escape double backslashes for MathJax?

查看:60
本文介绍了如何为MathJax逃脱双反斜杠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过将以下代码添加到 footer.php 中来使MathJax与WordPress兼容.它适用于简单的数学符号和方程式.

 < script type ="text/x-mathjax-config">MathJax.Hub.Config({tex2jax:{inlineMath:[[''','$'],["\\(","\\)"]],processEscapes:是}});</script>< script type ="text/javascript" src ="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> 

但是不适用于多线方程,例如

它呈现为一行,如下所示.

这是由于默认情况下在WordPress或markdown编辑器中将 \\ 渲染为 \ 引起的.一种可能的解决方案是将 $$ ... $$ 中的所有 \\ 转换为 \\\\ .

我希望我可以直接使用 \\ 作为换行符.它可以在 StackEdit 上运行,但是我不知道如何,可能会转义 \\ MathJax.


这是源代码.(我使用markdown编辑器.)

$$\ begin {bmatrix}PR(p_1)\\PR(p_2)\\\ vdots \\PR(p_N)\ end {bmatrix} =\ begin {bmatrix}{(1-d)/N} \\{(1-d)/N} \\\ vdots \\{(1-d)/N}\ end {bmatrix}+ d\ begin {bmatrix}\ ell(p_1,p_1)&\ ell(p_1,p_2)&\ cdots&\ ell(p_1,p_N)\\\ ell(p_2,p_1)&\ ddots&&\ vdots \\\ vdots&&\ell(p_i,p_j) &\\\ ell(p_N,p_1)&\ cdots&&\ ell(p_N,p_N)\ end {bmatrix}\ cdot\ begin {bmatrix}PR(p_1)\\PR(p_2)\\\ vdots \\PR(p_N)\ end {bmatrix}$$ 

解决方案

\ 是许多编程语言中常用的转义字符.

示例:在C语言中, \ n 表示换行符.这里的 n 表示换行,而 \ 则告诉编译器与正常的 n .转义字符 \ 用于告诉编译器紧随其后的字符是不正常的,应区别对待(例如,作为 \ n 换行符)./p>

您可以在要使用的每个实际 \ 之前使用 \ .因此,如果您想要 \ begin {bmatrix} ,则必须编写 \\ begin {bmatrix} ;如果您想要 \\ ,则需要使用 \\\\.

在某些系统中,也可以将文本标记为普通"文本.这样,您可以标记整个文本块,以忽略所有字符,否则这些字符在编程语言中将具有特殊含义.这因系统而异,Markdown使用`code block` ``code block''.

.

尝试将您的数学标记为代码块,您应该能够正常使用反斜杠,例如`math here` .

详细说明: http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-in-html-documents

I make MathJax work with WordPress by adding the following code to footer.php. It works for simple math symbols and equations.

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
            processEscapes: true
    }
});
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

But it doesn't work for the equations with multiline, such as,

It is rendered as one line as shown below.

This is caused by rendering \\ as \ by default in WordPress or markdown editor. One possible solution is to turn all \\ within $$...$$ into \\\\.

I expect I can use \\ as a line break directly. It works on StackEdit, but I don't know how, probably escaping \\ for MathJax.


Here is the source code. (I use markdown editor.)

$$
\begin{bmatrix}
PR(p_1) \\
PR(p_2) \\
\vdots \\
PR(p_N)
\end{bmatrix} =
\begin{bmatrix}
{(1-d)/ N} \\
{(1-d) / N} \\
\vdots \\
{(1-d) / N}
\end{bmatrix}
+ d
\begin{bmatrix}
\ell(p_1,p_1) & \ell(p_1,p_2) & \cdots & \ell(p_1,p_N) \\
\ell(p_2,p_1) & \ddots &  & \vdots \\
\vdots & & \ell(p_i,p_j) & \\
\ell(p_N,p_1) & \cdots & & \ell(p_N,p_N)
\end{bmatrix} 
\cdot
\begin{bmatrix}
PR(p_1) \\
PR(p_2) \\
\vdots \\
PR(p_N)
\end{bmatrix}
$$

解决方案

\ is an escape character commonly used across many programming languages.

Example: In C languages \n indicates a line break. Here the n is indicating a new line and the \ is telling the compiler to look at the n differently then a normal n. The escape character \ is used to tell the compiler that the character directly following it is not normal and should be treated differently (as a \n newline character for example).

You could use a \ before every actual \ you want to use. So if you wanted \begin{bmatrix} you would have to write \\begin{bmatrix} and if you want \\ you need to use \\\\.

It is also possible to mark text as 'verbatim' text in some systems. This way you can mark a whole block of text to ignore all characters that would otherwise have a special meaning in the programming language. This is different from system to system, Markdown uses `code block` or ``code block``.

Try marking your math as a code block and you should be able to use backslashes normally e.g. `math here`.

Detailed explanation: http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-in-html-documents

这篇关于如何为MathJax逃脱双反斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆