/ latex

Using LaTeX on your website with MathJax

Recently, I had the need to display formulas on some website. And then, I remembered that
when I was at school, which means almost 10 years from now; I was trying to find a tool that could
convert \(\LaTeX\) code into an HTML representation.

Nowadays, this has become possible, even if ten years earlier, tools
like LaTex2HTML already existed, they were not really the kind of result I wanted.

So, what is this beautiful tool that can convert your \(\LaTeX\)? Let me introduce you to MathJax.
A full documentation set is available here: MathJax documentation.

For my needs, the installation had been really simple, and it is the way we recognize the great products. All I had to
do was to add a call in the <head> tag of my HTML template in order to make it work perfectly.

<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

Next, since I wanted to display inline \(\LaTeX\) code, I added a small configuration Javascript call before calling the MathJax Javascript file.

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: {inlineMath: [['\\(','\\)']]}
});
</script>
<script type="text/javascript" src="path-to-mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

Perhaps later, I'll remove the inline for the $ character since, I might have to display the $ character in order to display currencies.

Here is one example of the kind of power \(\LaTeX\) has:

\frac{n!}{k!(n-k)!} = \binom{n}{k}

will produce the following result:

$$\frac{n!}{k!(n-k)!} = \binom{n}{k}$$