Phlox Midas
Phlox Midas

Reputation: 4349

Can MathJax be made to only convert LaTeX if it's inside a certain tag?

I have a text editor in which a user can write HTML code. I don't want them to write LaTeX outside of a particular element. It might be something like:

<x-latexmath>...</x-latexmath>

I want it so if they have LaTeX math outside of that tag, it's just displayed as normal text. How might this be possible?

Upvotes: 12

Views: 714

Answers (1)

Davide Cervone
Davide Cervone

Reputation: 12250

MathJax doesn't have a way to use user-defined tags to trigger math processing, but you can use MathJax's tex2jax preprocessor's processClass and ignoreClass parameters to allow you to control which parts of the page to process. See the text2jax configuration for details, but the idea would be to use

<body class="tex2jax_ignore">
...
<span class="tex2jax_process">...</span>
...
</body>

so that the main part of the page isn't processed, and only the span's (or div's if you prefer) containing the mathematics will be processed by MathJax.

Upvotes: 11

Related Questions