# php - How to display latex code in div from a textarea?

Get the solution ↓↓↓#### Solution:

They use MathJax. You can read about how to use it at your website reading here and syntax examples here.

Usage example:

```
<!DOCTYPE html>
<html>
<head>
<title>MathJax TeX Test Page</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</head>
<body>
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</body>
</html>
```

Renders as:

**EDIT:** If you don't want to render the math equations in one textarea, you can mark the element with an specific class like:`math-editor`

and configure MathJax as:

```
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
ignoreClass: "math-editor" // put this here
}
});
</script>
```

This`ignoreClass`

property is explained here. Or you could use the`processClass`

property to mark what *should* be processed.

Also, you can bind the textarea with a jQuery function to capture the event when the user types something inside the textarea to copy the text and paste at another div that can be rendered by MathJax.

**EDIT2**: another demo showing how to update a div with rendered code after inputing plain text in a textarea.

**Share solution ↓**

### Additional Information:

**Date the issue was resolved:**

Link To Answer People are also looking for solutions of the problem: filter_sanitize_string

### Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

### Similar questions

Find the answer in similar questions on our website.

### Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.