简体   繁体   中英

PHP not displaying MathJax from MySQL

Hello I'm stuck rendering MathJax from MySQL database. Since I couldn't find the right answer I would like to ask about rendering MathJax from MySQL database with PHP.

The MathJax code renders when I write it through text editor directly to the page. ( https://i.stack.imgur.com/wkkvA.png ) But when I save it to the database and try to echo saved data it doesn't apply MathJax style. ( https://i.stack.imgur.com/EQsql.png ).

I'm storing the data as TEXT in MySQL. ( https://i.stack.imgur.com/TPrIc.png ) I'm adding MathJax to website through

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>`

I've tried to read the MathJax docummentation but i wasn't able to find solution. I've also tried googling i couldn't find answer that would help me.

I tryed this and it works:

<head>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body>
<div id="has-math">
<div id="preview">\(\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1){6}\)</div>
<br> Original: \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}
</div>
<script>
MathJax.typeset();
</script>
</body>

So put your content in the 'preview' div: <div id="preview">\(\)</div>

like <div id="preview">\(1+1\)</div>

The rest is on you:-)

Did research here on the fly and is a very complex tool.

Notice: This just shows what you have saved and loaded from db and you can not edit it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM