{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Latex Tutorial\n", "\n", "The subtitle to this notebook is How to Write Beautiful Answers in your CS Homeworks (Part Two) because we are going to continue to explore how to use the Markup Cells (where you put text with various formatting commands). \n", "\n", "In this tutorial you will learn how to use Latex, a typesetting language for mathematics, in Markdown cells to write beautiful mathematical expressions. \n", "\n", "Wikipedia has a very complete summary of Latex commands for math\n", "here and \n", "Wikibooks has a nice summary here, however, beware, as the way we are using Latex in notebooks, the advanced formatting stuff relying on \n", "libraries does not work. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Basic Latex\n", "\n", "Latex allows you to typeset math expressions, using dollar signs `$` to indicate\n", "the beginning and ending of \"math mode.\" \n", "\n", "\n", "There are two modes in Latex, essentially inline and display math:\n", "\n", "**(A)** Inline Mode (surround a math expression with $):\n", "\n", " If you enclose a math expression in single dollar signs, it will be rendered\n", " in-line: $2^0 + 2^1 + 2^2 + 2^3$.\n", "\n", "If you enclose a math expression in single dollar signs, it will be rendered in-line: $2^0 + 2^1 + 2^2 + 2^3$.\n", "\n", "This works fine for simple mathematical statements:\n", "\n", " $P(H) = 0.5$\n", "\n", "$P(H) = 0.5$\n", "\n", " \n", "**(B)** Display Mode (surround a math expression with $$):\n", "\n", "If you enclose a math expression in double dollar signs, separated by blank lines, \n", "it will be centered in its own paragraph:\n", " \n", " $$2^0 + 2^1 + 2^2 + 2^3$$.\n", " \n", "$$2^0 + 2^1 + 2^2 + 2^3.$$\n", "\n", "\n", "Normally, blank spaces in your Latex expressions will be ignored; if you want to create white\n", "space, you can use one of the following:\n", "\n", " \\, - a thin space\n", " \\: - a medium space\n", " \\; - a thick space\n", " \\quad - 4 thick spaces\n", " \\hspace{1cm} - a space of the indicated size\n", " \n", " \n", " $$0 1\\,2\\:3\\;4\\quad 5\\hspace{1cm}6 $$\n", "\n", "\n", "$$0 1\\,2\\:3\\;4\\quad 5\\hspace{1cm}6 $$\n", "$$0 1\\,2\\:3\\;4\\;\\;\\;\\; 5\\hspace{1cm}6 $$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. The Most Useful Mathematical Symbols\n", "\n", "**(A)** Normal letters will look a little different in math context, but they\n", "will then be consistent with the rest of the math fonts:\n", "\n", " $x$ x\n", "\n", "$x$ x\n", "\n", " \n", "The most useful math symbols are the following:\n", "\n", "| Symbol | Latex | Symbol | Latex | \n", "|----------|--------|---------|--------|\n", "| $\\alpha$ | `\\alpha` | $\\exists$ | `\\exists` | \n", "| $\\beta$ | `\\beta` | $\\forall$ | `\\forall` | \n", "| $\\delta$ | `\\delta` | $\\implies$ | `\\implies` | \n", "| $\\theta$ | `\\theta` | $\\iff$ | `\\iff` | \n", "| $\\lambda$ | `\\lambda` | $\\rightarrow$ | `\\rightarrow` | \n", "| $\\mu$ | `\\mu` | $\\leftarrow$ | `\\leftarrow` | \n", "| $\\pi$ | `\\pi` | $\\longrightarrow$ | `\\longrightarrow` | \n", "| $\\rho$ | `\\rho` | $\\infty$ | `\\infty` | \n", "| $\\sigma$ | `\\sigma` | $\\emptyset$ | `\\emptyset` |\n", "| $\\Sigma$ | `\\Sigma` | | |\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. The Most Common Mathematical Operators\n", "\n", "**(A)** Standard mathematical operators are displayed as you might expect:\n", "\n", " $3 + x * 0.5 / 2 - 5$\n", "\n", "$3 + x * 0.5 / 2 - 5$\n", "\n", "The most useful symbols are the following:\n", "\n", "| Symbol | Latex | Symbol | Latex |\n", "|----------|--------|----------|--------|\n", "| $\\lt$ | `<` or `\\lt` | $>$ | `>` or `\\gt` | \n", "| $\\le$ | `\\le` |$\\ge$ | `\\ge` | \n", "| $=$ | `=` | $\\ne$ | `\\ne` | \n", "| $>$ | `>` | $>$ | `>` | \n", "| $\\in$ | `\\in` | $\\notin$ | `\\notin` | \n", "| $\\cup$ | `\\cup` | $\\subset$ | `\\subset` | \n", "| $\\cap$ | `\\cap` | $\\subseteq$ | `\\subseteq` | \n", "| $\\overline{A}$ | `\\overline{A}` | $\\supset$ | `\\supset` | \n", "| $\\wedge$ | `\\wedge` | $\\supseteq$ | `\\supseteq`\n", "| $\\vee$ | `\\vee` | $\\cdot$ | `\\cdot` | \n", "| $\\neg$ | `\\neg` | $\\cdots$ | `\\cdots` | \n", "| $\\sim$ | `\\sim` | $\\ldots$ | `\\ldots` | \n", "| $\\approx$ | `\\approx` | $\\not\\approx$ | `\\not\\approx` | \n", "| $\\cong$ | `\\cong` | $\\ast$ | `\\ast` |\n", "| $\\div$ | `\\div` | $\\times$ | `\\times` | \n", "| $\\pm$ | `\\pm` | $\\setminus$ | `\\setminus` | \n", " \n", "\n", "so you can write things like this:\n", "\n", " $$(A\\cap B) \\subseteq (D\\cap E^c)$$\n", "\n", "$$(A\\cap B) \\subseteq (D\\cap E^c)$$\n", " \n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Superscripts and Subscripts\n", "\n", "**(A)** Making superscripts and subscripts is easy, using `^` (hat) and `_` (underscore), but make sure to put the whole sub- or superscripted\n", "expression in curly braces, that is, make sure you do this:\n", "\n", " $2^{2k+1}$\n", "\n", "$2^{2k+1}$\n", "\n", "instead of this, which is surely not correct:\n", "\n", " $2^2k+1$\n", "\n", "$2^2k+1$\n", "\n", "\n", "\n", "Here are some examples of subscripts and superscripts:\n", "\n", "| Expression | Latex | \n", "|----------|--------|\n", "| $2^x$ | `2^x` | \n", "| $A^c$ | `A^c` |\n", "| $e^{3\\pi + \\varphi}$ | `e^{3\\pi + \\varphi}` | \n", "| $2^{2^x}$ | `2^{2^x}`\n", "| $X^2_k$ | `X^2_k` |\n", "| $x^y_1 x_1^y$ | `x^y_1 x_1^y` | \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5. Fractions and Combinations\n", "\n", "The Latex `\\frac{...}{...}` command is very easy to use, as is the equivalent\n", "expression `{ ... \\over ... }`; here are some simple examples:\n", "\n", "\n", "| Expression | Latex | \n", "|----------|--------|\n", "| $\\frac{1}{2}$ | `\\frac{1}{2}` | \n", "| ${x+1 \\over y - 1}$ | `{x+1 \\over y - 1}` | \n", "| $\\frac{\\frac{x}{y} + \\frac{e^x}{\\pi}}{2z \\over 5}$ | `frac{\\frac{x}{y} + \\frac{e^x}{\\pi}}{2z \\over 5}` | \n", "\n", "You can do a lot with this, if you just follow the syntax:\n", "\n", " $$\\frac{1}{1 + \\frac{1}{1 + \\frac{1}{1 + \\frac{1}{1 + \\frac{1}{\\cdots}}}}}$$\n", "\n", "$$\\frac{1}{1 + \\frac{1}{1 + \\frac{1}{1 + \\frac{1}{1 + \\frac{1}{\\cdots}}}}}$$\n", "\n", "In order to write combinations, as in the phrase \"N choose K,\" you use a syntax very similar to fractions, but you have to remember that the name is based on another term for this operator, called the \"binomial coefficients\":\n", "\n", "| Expression | Latex | \n", "|----------|--------|\n", "| $\\binom{N}{K}$ | `\\binom{N}{K}` | \n", "| ${N \\choose K}$ | `{N \\choose K}` | \n", "\n", "You can nest these expressions to produce complicated formats very easily:\n", "\n", " $${ {10 \\choose 6} \\over {8 \\choose 3}}$$\n", "\n", "$${ {10 \\choose 5} \\over {8 \\choose 3}}$$\n", "\n", "Or, equivalently, \n", "\n", " $$\\frac{\\binom{10}{6}}{\\binom{8}{3}}$$\n", "\n", "$$\\frac{\\binom{10}{6}}{\\binom{8}{3}}$$\n", "\n", "Generally the \"infix\" notation is a bit easier to read in complicated expressions; in any\n", "case, when using the infix style, remember to surround the expression in curly braces!\n", "\n", "\n", "The fraction notion can also be used for diagramming proofs in logic. Thus, the *resolution rule* can be\n", "written in Latex as:\n", "\n", " $$\\frac{A\\vee B \\quad \\neg B\\vee C}{B}$$\n", "\n", "$$\\frac{A\\vee B \\quad \\neg B\\vee C}{B}$$\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6. Summations, Products, Limits, and Integrals\n", " \n", "\n", "Sub- and superscripts are both useful when defining operators\n", "like summation, which typically take upper and lower bounds:\n", "\n", " $\\sum_{i=1}^{10} A_i$\n", "\n", "$\\sum_{i=1}^{10} A_i$\n", "\n", " $\\prod_{i=1}^{10} A_i$\n", "\n", "$\\prod_{i=1}^{10} A_i$\n", "\n", " $\\int_{i=0}^{\\infty} A_i$\n", "\n", "$\\int_{i=0}^{\\infty} A_i$\n", "\n", " $\\bigcup_{i=0}^{\\infty} A_i$\n", "\n", "$\\bigcup_{i=0}^{\\infty} A_i$\n", "\n", " $\\lim_{k \\to \\infty} A_i$\n", "\n", "$\\lim_{k \\to \\infty} A_i$\n", "\n", "If you use `$$` you will get somewhat better formatted versions of these for\n", "display math:\n", "\n", " $$\\sum_{i=1}^{10} A_i$$\n", "\n", "$$\\sum_{i=1}^{10} A_i$$\n", "\n", " $$\\prod_{i=1}^{10} A_i$$\n", "\n", "$$\\prod_{i=1}^{10} A_i$$\n", "\n", "$$\\int_{i=0}^{\\infty} A_i$$\n", "\n", "$$\\bigcup_{i=0}^{\\infty} A_i$$\n", "\n", "$$\\lim_{k \\to \\infty} A_i$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 7. Brackets and Delimiters\n", "\n", "Some mathematical operations require a left and a right delimiter. \n", "\n", "| Expression | Latex | Meaning |\n", "|----------|--------|----------|\n", "| ${ 10 \\choose 4}$ | `{ 10 \\choose 4}` | 10 choose 5 |\n", "| $\\lfloor x \\rfloor$ | `\\lfloor x \\rfloor` | Floor of x |\n", "| $\\lceil x \\rceil$ | `\\lceil x \\rceil` | Ceiling of x |\n", "| $\\langle a, b, c \\rangle$ | `\\langle x \\rangle` | Sequence or list |\n", "| $[ a, b, c ]$ | `[ a, b, c ]` | Sequence or list |\n", "| $\\{ a, b, c \\}$ | `\\{ a, b, c \\}` | Set |\n", "| $\\sqrt{x + 7}$ | `\\sqrt{x + 7}` | square root |\n", "| $\\sqrt[3]{x + 7}$ | `\\sqrt[3]{x + 7}` | cube root |\n", "\n", "Sometimes these delimiters are not big enough for the expression inside, such\n", "as a fraction:\n", "\n", " $\\lfloor\\frac{x+1}{y - 1}\\rfloor$\n", "\n", "$\\lfloor\\frac{x+1}{y - 1}\\rfloor$\n", "\n", "In this case, you can use the `\\left` and `\\right` to make the delimiter stretch a bit bigger:\n", "\n", " $\\left\\lfloor\\frac{x+1}{y - 1}\\right\\rfloor$\n", "\n", "$\\left\\lfloor\\frac{x+1}{y - 1}\\right\\rfloor$\n", "\n", "\n", "Here are some other examples:\n", "\n", " $\\left[\\frac{x+1}{y - 1}\\right]$\n", "\n", "$\\left[\\frac{x+1}{y - 1}\\right]$\n", "\n", " $\\left\\{\\frac{x+1}{y - 1}\\right\\}$\n", "\n", "$\\left\\{\\frac{x+1}{y - 1}\\right\\}$\n", "\n", " $\\left(\\frac{x+1}{y - 1}\\right)$\n", "\n", "$\\left(\\frac{x+1}{y - 1}\\right)$\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 8. Linear Algebra in Latex: \n", "\n", "#### Useful math fonts and symbols\n", "\n", "Here are some useful ways to format your math so that it looks like the notations typically used\n", "in linear algebra.\n", "\n", "Matrices are typically written as upper-case letters, while symbols for vectors are typically written in lower-case bold, which you can do with the `\\bf` command\n", "inside curly braces in math mode:\n", "\n", " $A{\\bf x} = {\\bf b}$\n", "\n", "$A{\\bf x} = {\\bf b}$\n", "\n", "It is usual to *not* put the subscripts in bold:\n", "\n", " $A{\\bf x}_k = {\\bf b}_k$\n", "\n", "$A{\\bf x}_k = {\\bf b}_k$\n", "\n", "The symbol for $n$-dimensional space of the reals is written as follows:\n", "\n", " $\\mathbb{R}^n$\n", "\n", "$\\mathbb{R}^n$\n", "\n", "The dot product can be written with `\\cdot`:\n", "\n", " ${\\bf u}\\cdot {\\bf v}$\n", "\n", "${\\bf u}\\cdot {\\bf v}$\n", "\n", "and some additional useful symbols for arrows are as shown here:\n", "\n", " $A \\rightarrow B \\longrightarrow C \\leftarrow D \\longleftrightarrow E \\leftrightarrow F \\longleftrightarrow$\n", "\n", "$A \\rightarrow B \\longrightarrow C \\leftarrow D \\longleftrightarrow E \\leftrightarrow F \\longleftrightarrow$\n", "\n", " $A \\Rightarrow B \\Longrightarrow C \\Leftarrow D \\Longleftrightarrow E \\Leftrightarrow F \\Longleftrightarrow$\n", "\n", "$A \\Rightarrow B \\Longrightarrow C \\Leftarrow D \\Longleftrightarrow E \\Leftrightarrow F \\Longleftrightarrow$\n", "\n", " $A \\rightsquigarrow B \\leftrightsquigarrow C $\n", "\n", "$A \\rightsquigarrow B \\leftrightsquigarrow C $\n", "\n", "\n", "\n", "For a very complete list of Latex math symbols, check out these pages: PDF, \n", "HTML\n", "\n", "\n", "#### Drawing Matrices\n", "\n", "To write matrices in Latex, you can use a couple of different environments, which require\n", "using `begin` and `end` as shown here:\n", "\n", "`matrix` just presents the matrix without brackets:\n", "\n", " $\\begin{matrix}\n", " 1 & 2 & 3 \\\\\n", " 4 & 5 & 6\n", " \\end{matrix}$\n", "\n", "$\\begin{matrix}\n", "1 & 2 & 3 \\\\\n", "4 & 5 & 6\n", "\\end{matrix}$\n", "\n", "`pmatrix` adds \"parenthesis brackets\":\n", "\n", " $\\begin{pmatrix}\n", " 1 & 2 & 3 & 4 \\\\ 5 & 6 & 7 & 8 \\\\\n", " \\end{pmatrix}$\n", "\n", "$\\begin{pmatrix}\n", "1 & 2 & 3 & 4 \\\\ 5 & 6 & 7 & 8 \\\\\n", "\\end{pmatrix}$\n", "\n", "Of course, you can simply write a tuple with commas very simply:\n", "\n", " $(1,2,3,4)$\n", "\n", "$(1,2,3,4)$\n", "\n", "`bmatrix` adds square brackets, which are standard in linear algebra texts:\n", "\n", " $\\begin{bmatrix}\n", " 1 & 2 & 3 \\\\\n", " 4 & 5 & 6\n", " \\end{bmatrix}$\n", "\n", "$\\begin{bmatrix}\n", "1 & 2 & 3 \\\\\n", "4 & 5 & 6\n", "\\end{bmatrix}$\n", "\n", "To draw only some elements in a matrix, and display dots for the missing elements, for example, \n", "\n", "- centered, horizontal dots: `$\\cdots$` = $\\cdots$\n", "- centered, vertical dots: `$\\vdots$` = $\\vdots$\n", "- diagonal dots: `$\\ddots$` = $\\ddots$ \n", "\n", "just put the dots in the appropriate location in the `bmatrix`:\n", "\n", " $A_{m,n} = \n", " \\begin{bmatrix}\n", " a_{1,1} & a_{1,2} & \\cdots & a_{1,n} \\\\\n", " a_{2,1} & a_{2,2} & \\cdots & a_{2,n} \\\\\n", " \\vdots & \\vdots & \\ddots & \\vdots \\\\\n", " a_{m,1} & a_{m,2} & \\cdots & a_{m,n} \n", " \\end{bmatrix}$\n", "\n", "$A_{m,n} = \n", "\\begin{bmatrix}\n", "a_{1,1} & a_{1,2} & \\cdots & a_{1,n} \\\\\n", "a_{2,1} & a_{2,2} & \\cdots & a_{2,n} \\\\\n", "\\vdots & \\vdots & \\ddots & \\vdots \\\\\n", "a_{m,1} & a_{m,2} & \\cdots & a_{m,n} \n", "\\end{bmatrix}$\n", "\n", "#### Drawing Augmented Matrices\n", "\n", "To draw an \"augmented matrix\" and to distinguish the right-most column of constants\n", " with a vertical line, use the `array` environment inside explicit brackets, as shown here:\n", " \n", " $\\left[ \n", " \\begin{array}{cc|c}\n", " 1 & 2 & 3 \\\\\n", " 4 & 5 & 6 \\\\\n", " \\end{array}\n", " \\right]$\n", "\n", "\n", "$\\left[ \n", " \\begin{array}{cc|c}\n", " 1 & 2 & 3 \\\\\n", " 4 & 5 & 6 \\\\\n", " \\end{array}\n", "\\right]$\n", "\n", "#### Drawing Determinants and Norms\n", "\n", "Single vertical bars used to indicate determinants use the `vmatrix` environment:\n", "\n", " $\\begin{vmatrix} \n", " 3 & -4 & 2 \\\\\n", " 0 & -1 & 5 \\\\\n", " -8 & 8 & 7 \\\\\n", " \\end{vmatrix}$\n", "\n", "$\\begin{vmatrix} \n", " 3 & -4 & 2 \\\\\n", " 0 & -1 & 5 \\\\\n", " -8 & 8 & 7 \\\\\n", "\\end{vmatrix}$\n", "\n", "Vector norms can be written as follows:\n", "\n", " $\\| {\\bf v}_2 \\|$\n", "\n", "$\\| {\\bf v}_2 \\|$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 8. Lining things up\n", "\n", "The most common need for alignment is in a proof where\n", "you want to show the way that an expression is transformed,\n", "instead of shoving it all together on the same line:\n", "\n", "$$Var(X_2)\\,=\\, E(X^2_2) - E(X_2)^2\\,=\\, 9.537 * 10^{11} - (952.67)^2 \\,=\\, 9.537 × 10^{11}$$\n", "\n", "we can put it on different lines using the `aligned` environment, indicating where where the alignment\n", "position is using `&` and where the end of the line is with `\\\\`:\n", "\n", " $$\\begin{aligned}\n", " Var(X_2) &= E(X^2_2) - E(X_2)^2 \\\\ \n", " &= 9.537 \\cdot 10^{11} - (952.67)^2 \\\\\n", " &= 9.537 \\cdot 10^{11} \\\\ \n", " \\end{aligned}$$\n", "\n", "$$\\begin{aligned}\n", " Var(X_2) &= E(X^2_2) - E(X_2)^2 \\\\ \n", " &= 9.537 \\cdot 10^{11} - (952.67)^2 \\\\\n", " &= 9.537 \\cdot 10^{11} \\\\ \n", "\\end{aligned}$$\n", "\n", "\n", "\n", "A similar kind of arrangement is used to define functions by cases, in which\n", "case you use the `equation` environment:\n", "\n", " \\begin{equation}\n", " f(n) = \\begin{cases}\n", " 1 & n = 0\\\\\n", " 1 & n = 1\\\\\n", " f(n-1) + f(n-2) & \\text{otherwise}\n", " \\end{cases}\n", " \\end{equation}\n", "\n", "\\begin{equation}\n", " f(n) = \\begin{cases}\n", " 1 & n = 0\\\\\n", " 1 & n = 1\\\\\n", " f(n-1) + f(n-2) & \\text{otherwise}\n", " \\end{cases}\n", "\\end{equation}\n", "\n", "A similar kind of arrangement is used when you want to display an array\n", "or matrix, and might want to adjust the alignment in each \"cell\" to left, center, or right,\n", "here is an example where the first column is left-aligned, the next is centered, and\n", "the last is right-aligned, which is accomplished by the code \"lcr\" in the command:\n", "\n", " $$ \\left[\n", " \\begin{array}{lcr}\n", " \\lambda - a & -b & -c \\\\\n", " -d & \\lambda - e & -f \\\\\n", " -g & -h & \\lambda - i \\end{array} \n", " \\right]\n", " $$\n", "\n", "$$\\left[ \\begin{array}{lcr}\n", "\\lambda - a & -b & -c \\\\\n", "-d & \\lambda - e & -f \\\\\n", "-g & -h & \\lambda - i \\end{array} \\right]\n", "$$\n", "\n", "Finally, Latex provides a number of special ways to format tables\n", "and matrices, here are some examples:\n", "\n", " $$ M=\n", " \\begin{bmatrix}\n", " 1 & 2 & 3 & 4 & 5 \\\\\n", " 3 & 4 & 5 & 6 & 7\n", " \\end{bmatrix}\n", " $$\n", "\n", "$$ M=\n", " \\begin{bmatrix}\n", " 1 & 2 & 3 & 4 & 5 \\\\\n", " 3 & 4 & 5 & 6 & 7\n", " \\end{bmatrix}\n", "$$\n", "\n", " $$ M=\n", " \\begin{pmatrix}\n", " 1 & 2 \\\\\n", " 3 & 4 \n", " \\end{pmatrix}\n", " $$\n", "\n", "$$ M=\n", " \\begin{pmatrix}\n", " 1 & 2 \\\\\n", " 3 & 4 \n", " \\end{pmatrix}\n", "$$\n", "\n", " $$A_{m,n} = \n", " \\begin{pmatrix}\n", " a_{1,1} & a_{1,2} & \\cdots & a_{1,n} \\\\\n", " a_{2,1} & a_{2,2} & \\cdots & a_{2,n} \\\\\n", " \\vdots & \\vdots & \\ddots & \\vdots \\\\\n", " a_{m,1} & a_{m,2} & \\cdots & a_{m,n} \n", " \\end{pmatrix}$$\n", " \n", "\n", "$$A_{m,n} = \n", " \\begin{pmatrix}\n", " a_{1,1} & a_{1,2} & \\cdots & a_{1,n} \\\\\n", " a_{2,1} & a_{2,2} & \\cdots & a_{2,n} \\\\\n", " \\vdots & \\vdots & \\ddots & \\vdots \\\\\n", " a_{m,1} & a_{m,2} & \\cdots & a_{m,n} \n", " \\end{pmatrix}$$\n", " \n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 9. Text in Math Mode\n", "\n", "Sometimes you want to write text, but it doesn't work very well!\n", "\n", " $$3 apples + 8 pears = 11 pieces of fruit$$\n", "\n", "$$3 apples + 8 pears = 11 pieces of fruit$$\n", "\n", "Just surround it with the Latex command `\\text{...}`. Note: it will look better if you include spaces around the text:\n", "\n", " $$3 \\text{ apples } + 8 \\text{ pears } = 11 \\text{ pieces of fruit }$$\n", "\n", "$$3 \\text{ apples } + 8 \\text{ pears } = 11 \\text{ pieces of fruit }$$" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 2 }