Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 911
Phlox Midas Avatar asked Jul 01 '12 22:07

Phlox Midas


People also ask

Does MathJax use LaTeX?

MathJax allows page authors to write formulas using TeX and LaTeX notation, MathML (a World Wide Web Consortium standard for representing mathematics in XML format), or AsciiMath notation.

What is the difference between MathJax and LaTeX?

MathJax can display mathematical notation written in LaTeX or MathML markup. Because MathJax is meant only for math display, whereas LaTeX is a document layout language, MathJax only supports the subset of LaTeX used to describe mathematical notation.

What is MathJax used for?

MathJax is a javascript display engine for rendering \TeX or MathML-coded mathematics in browsers without requiring font installation or browser plug-ins. Any modern browser with javascript enabled will be MathJax-ready.


1 Answers

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.

like image 192
Davide Cervone Avatar answered Oct 19 '22 05:10

Davide Cervone