Skip to content

How to prevent rendering: use tex2jax_ignore

Davide P. Cervone edited this page May 26, 2013 · 1 revision

From https://groups.google.com/d/msg/mathjax-users/HsA2aWhUdkE/WkjZhVj0D0IJ


Hi,

I wonder how can I make MathJax stop rendering \begin{align*}...\end{align*} environment. On my bbs, such texts are used to show codes:

[code]
\begin{aligned}
  \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t}
     & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
  \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
  \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t}
     & = \vec{\mathbf{0}} \\
  \nabla \cdot \vec{\mathbf{B}} & = 0
\end{aligned}
[/code]

However, MathJax will render them.

Thanks!


It depends on what HTML the [code] command generates. If it creates something like <pre>, then you can add that tag into the skipTags array in the tex2jax block of your configuration. (But <pre> should already be there, so I assume [code] is generating something else). If it creates a tag with a particular class name, you could add that class to the pattern in the ignoreClass property of the tex2jax block of your configuration. E.g., if [code] produced <div class="code"> then set ignoreClass to "tex2jax_ignore|code".

If you can't do either of those, then wrapping the code in <div class="tex2jax_ignore">...</div> would prevent MathJax from processing the contents of the <div> (i.e., your code).

See the tex2jax configuration options documenation for details (look for skipTags and ignoreClass).

Davide


More discussions

https://groups.google.com/d/msg/mathjax-users/f8pkmEDG_vk/mueFG9wmUyEJ

Fred has already pointed you to the documentation on this.

There are two approaches that would probably work for you. The first is to use MathJax's ignoreClass and processClass values to control the tex2jax processing (assuming your input is TeX). Set processClass to include the math class, and add class="tex2jax_ignore" to the <body> element in your document (or put a <div class="tex2jax_ignore"> around the contents of the page). This will cause tex2jax to only look for math in the containers that have class="math".

Alternatively, if you are able to recognize the mathematics yourself already, you could decide not to use tex2jax at all, and mark the mathematics directly using the <script> tags that MathJax uses for storing the math on the page. Use <script type="math/tex">...</script> for in-line math and <script type="math/tex; mode=display">...</script> for display math. You can put these inside your class="math" spans and divs if you want. You could also include <span class="MathJax_Preview">...</span> just before the <script type="math/tex"> script (with no intervening tags, text, or whitespace) to include a preview for before MathJax processes the page (MathJax will remove it as it goes). That could be just the original TeX code, or something else that marks where your mathematics will appear.

See the MathJax processing model documentation and in particular the section on how math is stored on the page for details.

Davide

Clone this wiki locally