# drdrang/php-markdown-extra-math

PHP
Latest commit 2f0f0f7 Mar 10, 2011 Stop htmlifying special characters in math spans and blocks.
I don't understand why I was filtering the equation text through
htmlspecialchars in the first place--obviously the wrong thing to do.
 Failed to load latest commit information. License.text Dec 17, 2009 PHP Markdown Extra Readme.text Dec 17, 2009 README.md Nov 23, 2010 markdown.php Mar 10, 2011

PHP Markdown Extra Math is an extension of Michel Fortin's PHP Markdown Extra, a PHP script for converting text written in Markdown to HTML. The extension consist of adding support for mathematical equations written in LaTeX to be processed by either the MathJax (default) or jsMath math rendering libraries.

## Use

Here's how it works. The author, writing in Markdown, inserts inline equations like this

where $$\alpha = (t_1 - t_0)/L$$ is the rate at which the thickness increases


enclosing the math in a $$…$$ pair, just as if writing in LaTeX. PHP Markdown Extra Math converts that to

where <span class="MathJax_Preview">[math]</span><script type="math/tex"> \alpha = (t_1 - t_0)/L </script> is the rate at which the thickness increases


for MathJax, or

where <span class="math"> \alpha = (t_1 - t_0)/L </span> is the rate at which the thickness increases


for jsMath. This is then converted by whichever math rendering library is being used to

(The example is shown as an image but will be rendered as selectable and scalable text if the server has MathJax or jsMath installed.)

Similarly, display Math is enclosed in $…$ like this:

Putting this into Castigliano's equation, we get

$\Delta = \frac{\partial U^*}{\partial F} = \frac{12F}{Eb} \int_0^L \frac{x^2}{(t_0 + \alpha x)^3} dx$


which PHP Markdown Extra Math will turn into this HTML

<p>Putting this into the Castigliano equation, we get</p>

<span class="MathJax_Preview">[math]</span><script type="math/tex; mode=display">\Delta = \frac{\partial U^*}{\partial F} = \frac{12F}{Eb} \int_0^L \frac{x^2}{(t_0 + \alpha x)^3} dx</script>


for MathJax, or

<p>Putting this into the Castigliano equation, we get</p>

<div class="math">\Delta = \frac{\partial U^*}{\partial F} = \frac{12F}{Eb} \int_0^L \frac{x^2}{(t_0 + \alpha x)^3} dx</div>


for jsMath. This will be rendered as:

## Configuration

The choice of MathJax or jsMath output is made on Line 42 of markdown.php:

@define( 'MARKDOWN_MATH_TYPE',      "mathjax" );


Change the "mathjax" to "jsmath" to change the rendering library.

## A MathJax detail

The <span class="MathJax_Preview">[…]</span> that precedes the MathJax code serves three purposes:

1. It's a placeholder that's displayed briefly while the equations are rendered.
2. It eliminates a rendering problem associated with Internet Explorer 8.
3. It gives Instapaper users a sense of what the rendered equation would be (if they understand LaTeX).