I've a personal blog built on minimal-mistakes Jekyll theme. Some of the posts use LaTex parsed by MathJax. I've been using MathJax v2 with the following configuration:
MathJax.Hub.Config({
showProcessingMessages: false,
messageStyle: "none",
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
TeX: {
MultLineWidth: "100%",
equationNumbers: { autoNumber: "AMS" }
},
"HTML-CSS": { fonts: ["Latin-Modern"] }
});
MathJax.js?config=TeX-AMS-MML_HTMLorMML
Here's an equation and its output.
$$
E[X] = \sum_{i=1}^{k-1}\sum_{j=i+1}^{k} X_{ij}Pr[\text{i and j have the same birthday}]
$$
$$ Pr[\text{i and j have unique birthdays}] = 365/365 * 364/365 $$ ($$ i $$ may have been born on any of the $$ 365 $$ days, and $$ j $$ on any of the remaining $$ 364 $$ days).
$$
\therefore Pr[\text{i and j have the same birthday}] = 1 - \frac{364}{365} = \frac{1}{365} \\
\begin{equation*}
\begin{aligned}
E[X] & = \frac{1}{365} * \sum_{i=1}^{k-1}\sum_{j=i+1}^{k} X_{ij} \\
& = \frac{1}{365} * \sum_{i=1}^{k-1} (k - i - 1 + 1) \\
& = \frac{1}{365} * \sum_{i=1}^{k-1} (k - i) \\
& = \frac{1}{365} * (\sum_{i=1}^{k-1} k - \mathop{\sum_{i=1}^{k-1}} i) \\
& = \frac{1}{365} * (k(k - 1) - (1 + 2 +...+ k - 1)) \\
& = \frac{1}{365} * (k(k - 1) - \frac{k(k - 1)}{2}) \\
& = \frac{k(k - 1)}{(365 * 2)}
\end{aligned}
\end{equation*}
$$
I upgraded MaxJax to v3, and obtained the v3 configuration using the conversion tool provided by MathJax.
v3 configuration:
window.MathJax = {
tex: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
multlineWidth: "100%",
tags: "ams"
},
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
}
};
As you can see, the equation is moved to the extreme right, and overlaid on top of the text above it. How do I fix this?
I actually upgraded to v4.0.0-beta.7 in order to get better validation, and for the newline support.
As for the problem above, I ended up with the following. Thanks to Davide P. Cervone for looking into the ticket I'd opened on MathJax GitHub repo.
$$
\\ X = \begin{cases}
1 & \text{if the pair has the same birthday} \\
0 & \text{otherwise}
\end{cases} \\
\begin{aligned}
E[X] = \sum_{i=1}^{k-1}\sum_{j=i+1}^{k} X_{ij}Pr[\text{i and j have the same birthday}]
\end{aligned} \\
Pr[\text{i and j have unique birthdays}] = 365/365 * 364/365 $$ ($$ i $$ may have been born on any of the $$ 365 $$ days, and $$ j $$ on any of the remaining $$ 364 $$ days).
$$\\
\therefore Pr[\text{i and j have the same birthday}] = 1 - \frac{364}{365} = \frac{1}{365}
$$
$$
\begin{equation*}
\begin{aligned}
E[X] & = \frac{1}{365} * \sum_{i=1}^{k-1}\sum_{j=i+1}^{k} X_{ij} \\
& = \frac{1}{365} * \sum_{i=1}^{k-1} (k - i - 1 + 1) \\
& = \frac{1}{365} * \sum_{i=1}^{k-1} (k - i) \\
& = \frac{1}{365} * (\sum_{i=1}^{k-1} k - \mathop{\sum_{i=1}^{k-1}} i) \\
& = \frac{1}{365} * (k(k - 1) - (1 + 2 +...+ k - 1)) \\
& = \frac{1}{365} * (k(k - 1) - \frac{k(k - 1)}{2}) \\
& = \frac{k(k - 1)}{(365 * 2)}
\end{aligned}
\end{equation*}
$$
The live rendering can be seen on this page from my blog.