How do I escape double backslashes for MathJax?

╄→гoц情女王★ 提交于 2020-12-29 07:38:05

问题


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}
$$

回答1:


\ 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



来源:https://stackoverflow.com/questions/42228504/how-do-i-escape-double-backslashes-for-mathjax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!