0
votes

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 : enter image description here

How can I prevent auto removing of backslashes?

1

1 Answers

0
votes

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);