Backslashes are auto-removed while inserting LaTeX formulas to MySQL with PHP

て烟熏妆下的殇ゞ 提交于 2019-12-12 03:13:49

问题


I'm writing simple math question generating program in PHP. There are users who add questions, and users who can examine themselves. For the questions with math formulas I am using LaTeX. But after inserting formula to MySQL database backslashes are removed and formula becomes unusable. Here is example of LaTeX formula:

\[
  \mathbf{V}_1 \times \mathbf{V}_2 =
   \begin{vmatrix}
    \mathbf{i} & \mathbf{j} & \mathbf{k} \\
    \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\
    \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \\
   \end{vmatrix}
\]

And same formula after insertion to database:

[
  mathbf{V}_1   imes mathbf{V}_2 =
   egin{vmatrix}
    mathbf{i} & mathbf{j} & mathbf{k} 
    frac{partial X}{partial u} & frac{partial Y}{partial u} & 0 
    frac{partial X}{partial v} & frac{partial Y}{partial v} & 0 
   end{vmatrix}
]

And how this formula shown after being rendered :

How can I prevent auto removing of backslashes?


回答1:


I've tried this function in php before inserting the string containing LaTeX formula and it works:

$question_with_latex = mysql_real_escape_string($question_with_latex); 


来源:https://stackoverflow.com/questions/29300071/backslashes-are-auto-removed-while-inserting-latex-formulas-to-mysql-with-php

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