As I embark on the PyESL project, I’ll need to include math equations in future blog posts. The easiest way to accomplish this is to use MathJax so that I can incorporate Tex/LaTeX/MathML-based equations within HTML. In Jekyll, all you need to do is add the MathJax javascript to the header section of your default.html and add a new variable to your _config.yml file.

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


and add the following to your _config.yml file:

markdown: kramdown


For example, this markdown:

Inline equation \\( {y} = {m}{x} + {b} \\) and block equation \\[ {y} = {m}{x}+{b} \\] 


produces:

Inline equation \( {y} = {m}{x}+{b} \) and block equation \[ {y} = {m}{x}+{b} \]

Here, the parentheses denote an inline equation while the square brackets denote a block equation.


And this is a multiline equation:

\[ \begin{align} {RSS} &= (\textbf{Y} - \textbf{X}{\beta})^{T}(\textbf{Y} - \textbf{X}{\beta}) \
&= \textbf{Y}^{T}\textbf{Y} - \textbf{Y}^{T}\textbf{X}{\beta} - {\beta}^{T}\textbf{X}^{T}\textbf{Y} + {\beta}^{T}\textbf{X}^{T}\textbf{X}{\beta} \qquad \because\textbf{AB}^{T}=\textbf{B}^{T}\textbf{A}^{T} \
&= \textbf{Y}^{T}\textbf{Y} - 2\textbf{Y}^{T}\textbf{X}{\beta} + {\beta}^{T}\textbf{X}^{T}\textbf{X}{\beta} \qquad \because \textbf{Y}^{T}\textbf{X}{\beta} = \textbf{X}^{T}{\beta}^{T}\textbf{Y} \
\end{align} \]

Taking the derivative and solving for \( {\beta} \):

\[ \begin{align} \frac{dRSS}{d\beta} &= - 2\textbf{Y}^{T}\textbf{X} + \textbf{X}^{T}\textbf{X}{\beta} + {\beta}^{T}\textbf{X}^{T}\textbf{X} \
0 &= - 2\textbf{Y}^{T}\textbf{X} + 2{\beta}^{T}\textbf{X}^{T}\textbf{X} \qquad \because \textbf{X}^{T}\textbf{X}{\beta} = {\beta}^{T}\textbf{X}^{T}\textbf{X} \
0 &= - \textbf{Y}^{T}\textbf{X} + {\beta}^{T}\textbf{X}^{T}\textbf{X} \
0 &= - \textbf{X}^{T}\textbf{Y} + \textbf{X}^{T}\textbf{X}{\beta} \qquad \because\textbf{AB}^{T}=\textbf{B}^{T}\textbf{A}^{T} \
\textbf{X}^{T}\textbf{X}{\beta} &= \textbf{X}^{T}\textbf{Y} \
{\beta} &= (\textbf{X}^{T}\textbf{X})^{-1}\textbf{X}^{T}\textbf{Y} \end{align} \]


Published

Feb 28, 2015