{ "metadata": { "name": "Typesetting Math Using MathJax" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Typesetting Math" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Markdown parser included in IPython is MathJax-aware. This means that you can freely mix in mathematical expressions using the [MathJax subset of Tex and LaTeX](http://docs.mathjax.org/en/latest/tex.html#tex-support). [Some examples from the MathJax site](http://www.mathjax.org/demos/tex-samples/) are reproduced below, as well as the Markdown+TeX source." ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Inline Typesetting (Mixing Markdown and TeX)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can mix math and *Markdown* **text** in a paragraph:\n", "\n", "## Source\n", "``` This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. \n", "```\n", "## Display\n", "This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. " ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Display mode equations" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "The Lorenz equations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In IPython 0.13.1 you have to use `\\\\\\` for LaTeX newlines rather than just `\\\\`. This is fixed in master.\n", "\n", "### Source\n", "```\\begin{aligned}\n", "\\dot{x} & = \\sigma(y-x) \\\\\\\n", "\\dot{y} & = \\rho x - y - xz \\\\\\\n", "\\dot{z} & = -\\beta z + xy\n", "\\end{aligned}\n", "```\n", "### Display\n", "\\begin{aligned}\n", "\\dot{x} & = \\sigma(y-x) \\\\\\\n", "\\dot{y} & = \\rho x - y - xz \\\\\\\n", "\\dot{z} & = -\\beta z + xy\n", "\\end{aligned}" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "The Cauchy-Schwarz inequality" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also use ``$$`` to indicate display mode equations:\n", "\n", "### Source\n", "```$$\n", "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n", "$$\n", "```\n", "### Display\n", "$$\n", "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n", "$$" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "The probability of getting \\(k\\) heads when flipping \\(n\\) coins" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Source\n", "```\\begin{equation*}\n", "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n", "\\end{equation*}\n", "```\n", "### Display\n", "\\begin{equation*}\n", "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n", "\\end{equation*}" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Go to the [MathJax website](http://www.mathjax.org/) and copy an example equations. Paste it into a Markdown cell and verify it gets rendered correctly. Then try some LaTeX of your own." ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }