Skip to content

Instantly share code, notes, and snippets.

@fomightez
Last active December 22, 2021 09:09
Show Gist options
  • Save fomightez/207dc5e48dfe0ac4513a8ba7bcf2eb01 to your computer and use it in GitHub Desktop.
Save fomightez/207dc5e48dfe0ac4513a8ba7bcf2eb01 to your computer and use it in GitHub Desktop.
Latex Example Use in a Jupyter Notebook

Looks way better rendered at nbviewer than here.

Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<font color=\"red\"><H1>LATEX INFO</H1></font>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In new Jupyter notebooks I have been working you can just type latex in markdown cells and it works."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" No need for `%%latex` in a code cell then. --> see very first line of TD's answer at http://stackoverflow.com/questions/13208286/how-to-write-latex-in-ipython-notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Example of new way on next line, but won't work in old canopy I have on home computer. \n",
"(kept old one so far because lets me edit directly in cnaopy whereas new Canopy goes to browser and is a bit annoying in opening and closing.) \n",
"To see it work, easiest way is to upload to tmpnb.org and use there."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\\begin{aligned}\n",
"\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n",
"\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
"\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
"\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n",
"\\end{aligned}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Just verified it works there. The only issue is why it puts a line next to the right side latex cell? ---> Known issue in Chrome that should eventullay resolved without need to do anything, see http://stackoverflow.com/questions/35171714/ipython-jupyter-notebook-producing-ghost-line-in-all-equations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Also see it used in the notebook `Fishers exact test in Jupyter notebook.ipynb` which currently only works at work computer or by uploading to tmpnb.org, but I hope to eventually laso have it on `binder.org`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Easy Equation writing examples**\n",
"\n",
"\n",
"$$c = \\sqrt{a^2 + b^2}$$\n",
"\n",
"Logarithmic growth of a population of cells can be described mathematically as\n",
"$$N = N_oe^{ln2(t/t_2)}$$\n",
"(from page 177 of Methods in Yeast Genetics, 205 Edition) \n",
"\n",
"**See [here](http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference) for an awesome reference for MathJax **"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\"and use single $\\$\\ (rather than double $\\$\\$\\) to keep the equation in-line. stackoverflow.com/q/19412644/1224255\" - from http://stackoverflow.com/questions/13208286/how-to-write-latex-in-ipython-notebook (<---this itself was tricky to write and I had to use minrk's April 18th answer at https://github.com/ipython/ipython/issues/3197/ as a basis"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Based on [here](https://tex.stackexchange.com/questions/158897/how-do-i-get-a-hyphen-in-mathrm) I figured out (probably again) how to add hyphen when in math mode in Jupyter notebooks and not have it loolike a minus sign.\n",
"\n",
"$$\\frac{mito\\ purification\\ RNA\\textrm-Seq\\ data}{total\\ cell\\ RNA\\textrm-seq\\ data}$$\n",
"\n",
"VS. \n",
"\n",
"$$\\frac{obs_a - obs_b}{exp_a - exp_b}$$\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"The mass-energy equivalence is described by the famous equation\n",
" \n",
"$$E=mc^2$$\n",
" \n",
"discovered in 1905 by Albert Einstein. \n",
"In natural units ($c$ = 1), the formula expresses the identity\n",
" \n",
"\\begin{equation}\n",
"E=m\n",
"\\end{equation}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#from JupyterLab demo notebook November 2, 2016\n",
"from IPython.display import Latex\n",
"Latex('''The mass-energy equivalence is described by the famous equation\n",
" \n",
"$$E=mc^2$$\n",
" \n",
"discovered in 1905 by Albert Einstein. \n",
"In natural units ($c$ = 1), the formula expresses the identity\n",
" \n",
"\\\\begin{equation}\n",
"E=m\n",
"\\\\end{equation}''')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Below is old stuff I had in this notebook before Jupyter and new way of putting latex in a markdown cell as described above**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(Link on cell on next line seems to lead to dead link now???)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"from http://nbviewer.ipython.org/url/github.com/ipython/ipython/raw/master/examples/notebooks/Part%205%20-%20Rich%20Display%20System.ipynb"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\begin{aligned}\n",
"\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n",
"\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
"\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
"\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n",
"\\end{aligned}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%latex\n",
"\\begin{aligned}\n",
"\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n",
"\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
"\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
"\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n",
"\\end{aligned}"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\begin{tabular}{ | c | c c c | } \\hline\n",
" $k$ & $x_1^k$ & $x_2^k$ & $x_3^k$ \\\\\n",
" \\hline\n",
" 0 & -0.30000000 & 0.60000000 & 0.70000000 \\\\\n",
" 1 & 0.47102965 & 0.04883157 & -0.53345964 \\\\\n",
" 2 & 0.49988691 & 0.00228830 & -0.52246185 \\\\\n",
" 3 & 0.49999976 & 0.00005380 & -0.52365600 \\\\\n",
" 4 & 0.50000000 & 0.00000307 & -0.52359743 \\\\\n",
" 5 & 0.50000000 & 0.00000007 & -0.52359885 \\\\\n",
" 6 & 0.50000000 & 0.00000000 & -0.52359877 \\\\\n",
" 7 & 0.50000000 & 0.00000000 & -0.52359878 \\\\\n",
" \\hline\n",
"\\end{tabular}}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%latex\n",
"\\begin{tabular}{ | c | c c c | } \\hline\n",
" $k$ & $x_1^k$ & $x_2^k$ & $x_3^k$ \\\\\n",
" \\hline\n",
" 0 & -0.30000000 & 0.60000000 & 0.70000000 \\\\\n",
" 1 & 0.47102965 & 0.04883157 & -0.53345964 \\\\\n",
" 2 & 0.49988691 & 0.00228830 & -0.52246185 \\\\\n",
" 3 & 0.49999976 & 0.00005380 & -0.52365600 \\\\\n",
" 4 & 0.50000000 & 0.00000307 & -0.52359743 \\\\\n",
" 5 & 0.50000000 & 0.00000007 & -0.52359885 \\\\\n",
" 6 & 0.50000000 & 0.00000000 & -0.52359877 \\\\\n",
" 7 & 0.50000000 & 0.00000000 & -0.52359878 \\\\\n",
" \\hline\n",
"\\end{tabular}}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\documentclass[12pt]{article}\n",
"\n",
"\\setlength{\\parskip}{1.2ex}\t % space between paragraphs\n",
"\\setlength{\\parindent}{2em}\t % amount of indention\n",
"\\setlength{\\textwidth}{175cm}\t % default = 6.5\"\n",
"\\setlength{\\oddsidemargin}{-5mm} % default = 0\"\n",
"\\setlength{\\textheight}{225mm}\t % default = 9\"\n",
"\\setlength{\\topmargin}{-12mm}\t % default = 0\"\n",
"\n",
"\t% --- define your own commands!! ---\n",
"\\newcommand{\\iii}{\\indent \\indent \\indent}\t% triple-depth indent\n",
"\n",
"\\title{A Sample \\LaTeX\\ Document}\n",
"\\author{Schl\\oe ff\\d{o}nffl\\t{oo}\\ae g\\\"{e}n, \\L\\\"{a}rs}\n",
"\\date{July 14, 1992}\n",
"\n",
"\\begin{document}\n",
"\t\t\t\t(PAGE 1)\n",
"\\maketitle\n",
"\n",
"\\noindent\n",
"I{\\footnotesize MPORTANT} S{\\footnotesize TUFF} \\\\\n",
"{\\bf \tI{\\bf \\footnotesize MPORTANT} S{\\bf \\footnotesize TUFF}} \\\\\n",
"\\textbf{ I{\\footnotesize MPORTANT} S{\\footnotesize TUFF}}\n",
"\n",
"This is a document produced by the \\LaTeX\\ software, and generated by the\n",
"source file {\\tt sample.tex}. Compare the source text file (left-hand\n",
"sides) with the document it produces using \\LaTeX\\ (right-hand sides).\n",
"\n",
"\\section{Ordinary Text}\t% Produces section heading. Lower-level sections\n",
"\t\t\t% are begun with similar \\subsection and\n",
"\t\t\t% \\subsubsection commands; numbering is automatic!\n",
"\n",
"\\subsection{Spacing in the source text}\n",
"The ends of words and sentences are marked\n",
" by spaces. It doesn't matter how many\n",
"spaces\n",
"you\n",
"type; one is as good as 100.\n",
"The end of a line counts as a space.\n",
"\n",
"One or more blank lines denote the end of a paragraph.\n",
"\n",
"Since any number of consecutive spaces are treated like a single one, the\n",
"formatting of the input file makes no difference to \\TeX, but it makes a\n",
"difference to you. When you use \\LaTeX, making your input file as easy to\n",
"read as possible will be a great help as you write your document and when\n",
"you change it. Keep typed lines {\\bf short} in length, and use\n",
"\\verb9 % comments9. % like this!\n",
"\n",
"Because printing is different from typewriting, there are a number of things\n",
"that you have to do differently when preparing an input file than if you were\n",
"just typing the document directly. Quotation marks like ``this'' have to\n",
"be handled specially.\n",
"\n",
"\\subsection{Special characters}\n",
"Dashes come in three sizes: an\n",
" intra-word\n",
"dash, a medium dash for number ranges like\n",
" 1--2,\n",
"and a punctuation\n",
" dash---like\n",
"this.\n",
"\n",
"\\TeX\\ interprets some common characters as commands, so you must type\n",
"special commands to generate them. These characters include the\n",
"following: \\$ \\& \\% \\# \\{ and \\}.\n",
"\n",
"\\subsection{Fonts}\t\t(PAGE 2)\n",
"In printing, text is emphasized by using an {\\em italic\\/}\n",
"type style. % The \\/ command produces the tiny extra space that\n",
" % should be added between a slanted and a following\n",
" % unslanted letter.\n",
"\\begin{em}\n",
" A long segment of text can also be emphasized in this way. Text within\n",
" such a segment given additional emphasis\n",
" with\\/ {\\em Roman}\n",
" type. Italic type loses its ability to emphasize and become simply\n",
" distracting when used excessively.\n",
"\\end{em}\n",
"\n",
"Other font types are available: \\\\\n",
"\\indent {\\bf Bold face type,}\t\\\\\n",
"\\indent {\\tt typewriter style type,}\t\\\\\n",
"\\indent {\\sf sans-serif type,}\t\\\\\n",
"\\indent {\\sl slanted type,}\t\\\\\n",
"\\indent {\\sc all caps type.}\t\\\\\n",
"Formulae and other mathematical expressions are given\n",
"their own ``math mode'' font.\n",
"\n",
"\\section{Spacing}\n",
"A sentence-ending space should be larger than the space between words\n",
"within a sentence. You sometimes have to type special commands in\n",
"conjunction with punctuation characters to get this right, as in the\n",
"following sentence.\n",
" Gnats, gnus, etc.\\ % `\\ ' makes an inter-word space.\n",
" all begin with G\\@. % \\@ marks end-of-sentence punctuation.\n",
"Generating an ellipsis\n",
" \\ldots\\\t% `\\ ' needed because TeX ignores spaces after\n",
"\t\t% command names like \\ldots made from \\ + letters.\n",
"with the right spacing around the periods requires a special command.\n",
"\n",
"It is sometimes necessary to prevent \\TeX\\ from breaking a line where\n",
"it might otherwise do so. This may be at a space, as between the\n",
"``Mr.'' and ``Jones'' in\n",
"``Mr.~Jones'', %\t~ produces an unbreakable interword space.\n",
"or within a word---especially when the word is a symbol like\n",
"\\mbox{\\em itemnum\\/} that makes little sense when hyphenated\n",
"across lines.\n",
"\n",
"In math mode, \\TeX\\ ignores the spaces you type and formats\n",
"the formula the way it thinks is best. Some authors feel that\n",
"\\TeX\\ cramps formulae, and they want to add more space; however,\n",
"\\TeX\\ knows more about typesetting formulae than do many authors.\n",
"Adding extra space usually makes a formula prettier but\n",
"harder to read, because it visually fractures the formula into\n",
"separate units.\n",
"\n",
"Though fiddling with the spacing is dangerous, you sometimes\n",
"have to do it to make a formula look just right. One reason\n",
"is that \\TeX\\ may not understand the formula's logical structure,\n",
"interpreting (for example) ${\\bf y\\:dx}$ as the product of\n",
"three quantities rather than as $y$ times the differential $dx$,\n",
"so that it doesn't add the little extra space after the $y$.\n",
"You can define your own commands to take care of such cases,\n",
"or use these special spacing commands:\t\\\\\n",
"\\iii \\verb2\\,2~~~thin space~~~~~~(any mode) \\\\\t\t% \"verbatim\"\n",
"\\iii \\verb9\\:9~~~medium space~~~~(math mode only) \\\\\n",
"\\iii \\verb#\\;#~~~thick space~~~~~(math mode only) \\\\\n",
"\\iii \\verb2\\!2~~~thin backspace~~(math mode only) \\\\\n",
"A most precise spacing command can be used in either math or\n",
"paragraph modes; the \\verb2\\kern2 command. Use it with the\n",
"unit ``em'', which is the width of a capital M. Example:\n",
"to print `R' over an `I' you might use the command\n",
"\\verb@I\\kern-0.27emR@ to produce ``I\\kern-0.27emR''.\n",
"\n",
"\\section{Displayed Text}\t\t(PAGE 3)\n",
"Text is displayed by indenting it from the left margin.\n",
"Quotations are commonly displayed. There are short quotations\n",
"\\begin{quote}\n",
" This is a short a quotation. It consists of a\n",
" single paragraph of text. There is no paragraph\n",
" indentation.\n",
"\\end{quote}\n",
"and longer ones.\n",
"\\begin{quotation}\n",
" This is a longer quotation. It consists of two paragraphs\n",
" of text. The beginning of each paragraph is indicated\n",
" by an extra indentation.\n",
"\n",
" This is the second paragraph of the quotation. It is just\n",
" as dull as the first paragraph.\n",
"\\end{quotation}\n",
"\n",
"Footnotes\\footnote{This is an example of a footnote.} pose no problem.\n",
"Likewise, bibliographic references \\cite{Lam} are handled with ease.\n",
"!`\\TeX\\ can g\\`{e}n\\'{e}rate alm\\\"{o}st all the accents and\n",
"spe\\c{c}ial symbols used in Western \\cite{Sch} l\\aa nguages! Likewise,\n",
"its arsenal of mathematical sym$\\beta$ols, introduced below, is formidable.\n",
"\n",
"Another frequently-displayed structure is a list.\n",
"The following is an example of an {\\em itemized} list.\n",
" \\begin{itemize}\n",
" \\item This is the first item of an itemized list. Each item\n",
" in the list is marked with a ``tick''. The document\n",
" style determines what kind of tick mark is used.\n",
"\n",
" \\item This is the second item of the list. Need there be more?\n",
" \\end{itemize}\n",
"\n",
"\\section{Mathematical Formulae}\n",
"\\TeX\\ is good at typesetting mathematical formulas like\n",
" $ x-3y = 7 $\n",
"or\n",
" $ y_{i+1} = x_{i}^{2n} - \\sqrt{5}x_{i}^{n} + 1$.\n",
"Remember that a letter like\n",
" \\( x \\) % $ ... $ and \\( ... \\) are equivalent\n",
"is a formula when it denotes a mathematical symbol, and should\n",
"be treated as one.\n",
"\n",
"Mathematical formulas may also be\t\t% use \\[ \\]\n",
"{\\em displayed}. A displayed formula\t\t% or $$ $$\n",
"is one-line long; multiline formulas\t\t% or \\begin{equation}\n",
"require special formatting instructions.\t% \\begin{eqnarray}\n",
"The following formulae demonstrate\n",
"many constructions you might find useful.\n",
"Refer to equation (\\ref{eq:fermat}), which is probably true,\n",
"while equations (\\ref{eq:dumb}-\\ref{eq:realdumb}) are silly.\n",
"Note that the \\verb9equation9 and \\verb9eqnarray9 environments\n",
"number the equations, but \\verb9eqnarray*9 doesn't.\n",
"\\[ x_{i+1} ~=~ N^{i+1}(x_{0}) ~=~ N(x_{i}) ~=~\n",
"\tx_{i} - \\frac{f(x_{i})}{f'(x_{i})}\t\\]\n",
"\n",
"$$ \\frac{\\partial u}{\\partial t} + \\nabla^{4}u + \\nabla^{2}u +\n",
"\t\\frac12 |\\nabla u|^{2}~ =~ c^2 $$\n",
"\n",
"\t\t\t\t(PAGE 4)\n",
"\\begin{equation} a^{p} + b^p \\neq c^{p} ~~~\\mbox{for } p>2\n",
"\t~~ \\mbox{(see proof in margin)} \\label{eq:fermat}\n",
"\\end{equation}\n",
"$$ \\lim_{n \\rightarrow \\infty}x_{n} \\geq \\pi $$\n",
"$$ \\forall x \\in {\\cal O} ~~\\exists \\delta ~~~\\mbox{such that}~~~\n",
"\t|y-x|<\\delta ~\\Rightarrow ~y \\in {\\cal O} $$\n",
"\\vspace{4mm}\n",
"$$\n",
"\\Psi' = \\frac{d}{d \\phi} \\left( \\begin{array}{c}\n",
" \\phi_{2} \\\\ \\phi_{3} \\\\ 1 - \\phi_{2} - \\phi_{1}^{2}/2\n",
" \\end{array} \\right)\n",
" ~~~~~~~~~~~~~\n",
" \\Theta = \\left(\t\\begin{array}{ccc}\n",
"\t0 \t\t\t& \t1\t&\t0\t\\\\\n",
"- \\theta_{1} \\psi_{1} - \\psi_{2} &\t0\t&\t\\psi_3\t\\\\\n",
"\t-\\phi_{1} \t\t&\t-1\t&\t0\n",
"\t\t\t\\end{array} \\right)\n",
"$$\n",
"\\vspace{4mm}\n",
"\\begin{eqnarray}\n",
"\t\\int_0^{\\infty} e^{-x^2}\\,dx\n",
"\t& = &\te^{-\\left(\\int_0^{\\infty}x\\,dx\\right)^2} \\label{eq:dumb} \\\\\n",
"\t& = &\te^{-\\infty} ~~~~~\\mbox{(bogus)} \\\\\n",
"\t& = &\t0.38-1.7i ~~~~~\\mbox{(not!)} \\label{eq:realdumb}\n",
"\\end{eqnarray}\n",
"\\vspace{4mm}\n",
"\\begin{eqnarray*}\t\t\t% \"*\" = no line numbering\n",
" \\sum_{n=1}^k \\frac1n\n",
"\t& \\approx &\t\\ln k + \\gamma \\\\\n",
"\t& = &\t\t(\\ln 10)(\\log_{10}k) + \\gamma \\\\\n",
"\t& \\approx &\t2.3026\\log_{10}k + 0.57772\n",
"\\end{eqnarray*}\n",
"\n",
"\\vspace{6mm}\n",
"\\centerline{\n",
"\\begin{tabular}{ | c | c c c | } \\hline\n",
" $k$ & $x_1^k$ & $x_2^k$ & $x_3^k$ \\\\\n",
" \\hline\n",
" 0 & -0.30000000 & 0.60000000 & 0.70000000 \\\\\n",
" 1 & 0.47102965 & 0.04883157 & -0.53345964 \\\\\n",
" 2 & 0.49988691 & 0.00228830 & -0.52246185 \\\\\n",
" 3 & 0.49999976 & 0.00005380 & -0.52365600 \\\\\n",
" 4 & 0.50000000 & 0.00000307 & -0.52359743 \\\\\n",
" 5 & 0.50000000 & 0.00000007 & -0.52359885 \\\\\n",
" 6 & 0.50000000 & 0.00000000 & -0.52359877 \\\\\n",
" 7 & 0.50000000 & 0.00000000 & -0.52359878 \\\\\n",
" \\hline\n",
"\\end{tabular}}\n",
"\n",
"Unary operators ``plus'' and ``minus'' -- just use exponentiation:\n",
"$$\t{}^{+}0.168 \\mbox{ or } {}^{-}1.168\t$$\n",
"\n",
"$$ \\Vert \\diamond\\star \\Vert ~~~ \\clubsuit\\diamondsuit\\heartsuit\\spadesuit\n",
" ~~~ \\sharp\\flat\\natural ~~~ \\cap\\cup\\pm\\mp ~~~ \\prod\\alpha\\beta\\gamma\n",
" ~~~ \\oint_Cf(z)dz ~~~ \\Gamma_{\\sqrt7}^{v,\\upsilon} ~~~ V\\bigoplus W $$\n",
"\n",
"\t\t\t\t(PAGE 5)\n",
"\\begin{thebibliography}{9}\t% 9 = maximum expected references!\n",
"\n",
"\\bibitem{Lam} Lamport, Leslie.\n",
"\\LaTeX : A Document Preparation System. \\\\\n",
"Copyright \\copyright 1986, Addison-Wesley Publ.Co.,Inc.\n",
"\n",
"\\bibitem{Sch} Schl\\oe ff\\d{o}nffl\\t{oo}\\ae g\\\"{e}n,\n",
"\\L\\\"{a}rs. Silly Typography.\t\t\\\\\n",
"{\\em Journal of Linguistic Horseplay 19D} (1977), 23-37.\n",
"\n",
"\\end{thebibliography}\n",
"\\end{document} % End of document."
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%latex\n",
"\\documentclass[12pt]{article}\n",
"\n",
"\\setlength{\\parskip}{1.2ex}\t % space between paragraphs\n",
"\\setlength{\\parindent}{2em}\t % amount of indention\n",
"\\setlength{\\textwidth}{175cm}\t % default = 6.5\"\n",
"\\setlength{\\oddsidemargin}{-5mm} % default = 0\"\n",
"\\setlength{\\textheight}{225mm}\t % default = 9\"\n",
"\\setlength{\\topmargin}{-12mm}\t % default = 0\"\n",
"\n",
"\t% --- define your own commands!! ---\n",
"\\newcommand{\\iii}{\\indent \\indent \\indent}\t% triple-depth indent\n",
"\n",
"\\title{A Sample \\LaTeX\\ Document}\n",
"\\author{Schl\\oe ff\\d{o}nffl\\t{oo}\\ae g\\\"{e}n, \\L\\\"{a}rs}\n",
"\\date{July 14, 1992}\n",
"\n",
"\\begin{document}\n",
"\t\t\t\t(PAGE 1)\n",
"\\maketitle\n",
"\n",
"\\noindent\n",
"I{\\footnotesize MPORTANT} S{\\footnotesize TUFF} \\\\\n",
"{\\bf \tI{\\bf \\footnotesize MPORTANT} S{\\bf \\footnotesize TUFF}} \\\\\n",
"\\textbf{ I{\\footnotesize MPORTANT} S{\\footnotesize TUFF}}\n",
"\n",
"This is a document produced by the \\LaTeX\\ software, and generated by the\n",
"source file {\\tt sample.tex}. Compare the source text file (left-hand\n",
"sides) with the document it produces using \\LaTeX\\ (right-hand sides).\n",
"\n",
"\\section{Ordinary Text}\t% Produces section heading. Lower-level sections\n",
"\t\t\t% are begun with similar \\subsection and\n",
"\t\t\t% \\subsubsection commands; numbering is automatic!\n",
"\n",
"\\subsection{Spacing in the source text}\n",
"The ends of words and sentences are marked\n",
" by spaces. It doesn't matter how many\n",
"spaces\n",
"you\n",
"type; one is as good as 100.\n",
"The end of a line counts as a space.\n",
"\n",
"One or more blank lines denote the end of a paragraph.\n",
"\n",
"Since any number of consecutive spaces are treated like a single one, the\n",
"formatting of the input file makes no difference to \\TeX, but it makes a\n",
"difference to you. When you use \\LaTeX, making your input file as easy to\n",
"read as possible will be a great help as you write your document and when\n",
"you change it. Keep typed lines {\\bf short} in length, and use\n",
"\\verb9 % comments9. % like this!\n",
"\n",
"Because printing is different from typewriting, there are a number of things\n",
"that you have to do differently when preparing an input file than if you were\n",
"just typing the document directly. Quotation marks like ``this'' have to\n",
"be handled specially.\n",
"\n",
"\\subsection{Special characters}\n",
"Dashes come in three sizes: an\n",
" intra-word\n",
"dash, a medium dash for number ranges like\n",
" 1--2,\n",
"and a punctuation\n",
" dash---like\n",
"this.\n",
"\n",
"\\TeX\\ interprets some common characters as commands, so you must type\n",
"special commands to generate them. These characters include the\n",
"following: \\$ \\& \\% \\# \\{ and \\}.\n",
"\n",
"\\subsection{Fonts}\t\t(PAGE 2)\n",
"In printing, text is emphasized by using an {\\em italic\\/}\n",
"type style. % The \\/ command produces the tiny extra space that\n",
" % should be added between a slanted and a following\n",
" % unslanted letter.\n",
"\\begin{em}\n",
" A long segment of text can also be emphasized in this way. Text within\n",
" such a segment given additional emphasis\n",
" with\\/ {\\em Roman}\n",
" type. Italic type loses its ability to emphasize and become simply\n",
" distracting when used excessively.\n",
"\\end{em}\n",
"\n",
"Other font types are available: \\\\\n",
"\\indent {\\bf Bold face type,}\t\\\\\n",
"\\indent {\\tt typewriter style type,}\t\\\\\n",
"\\indent {\\sf sans-serif type,}\t\\\\\n",
"\\indent {\\sl slanted type,}\t\\\\\n",
"\\indent {\\sc all caps type.}\t\\\\\n",
"Formulae and other mathematical expressions are given\n",
"their own ``math mode'' font.\n",
"\n",
"\\section{Spacing}\n",
"A sentence-ending space should be larger than the space between words\n",
"within a sentence. You sometimes have to type special commands in\n",
"conjunction with punctuation characters to get this right, as in the\n",
"following sentence.\n",
" Gnats, gnus, etc.\\ % `\\ ' makes an inter-word space.\n",
" all begin with G\\@. % \\@ marks end-of-sentence punctuation.\n",
"Generating an ellipsis\n",
" \\ldots\\\t% `\\ ' needed because TeX ignores spaces after\n",
"\t\t% command names like \\ldots made from \\ + letters.\n",
"with the right spacing around the periods requires a special command.\n",
"\n",
"It is sometimes necessary to prevent \\TeX\\ from breaking a line where\n",
"it might otherwise do so. This may be at a space, as between the\n",
"``Mr.'' and ``Jones'' in\n",
"``Mr.~Jones'', %\t~ produces an unbreakable interword space.\n",
"or within a word---especially when the word is a symbol like\n",
"\\mbox{\\em itemnum\\/} that makes little sense when hyphenated\n",
"across lines.\n",
"\n",
"In math mode, \\TeX\\ ignores the spaces you type and formats\n",
"the formula the way it thinks is best. Some authors feel that\n",
"\\TeX\\ cramps formulae, and they want to add more space; however,\n",
"\\TeX\\ knows more about typesetting formulae than do many authors.\n",
"Adding extra space usually makes a formula prettier but\n",
"harder to read, because it visually fractures the formula into\n",
"separate units.\n",
"\n",
"Though fiddling with the spacing is dangerous, you sometimes\n",
"have to do it to make a formula look just right. One reason\n",
"is that \\TeX\\ may not understand the formula's logical structure,\n",
"interpreting (for example) ${\\bf y\\:dx}$ as the product of\n",
"three quantities rather than as $y$ times the differential $dx$,\n",
"so that it doesn't add the little extra space after the $y$.\n",
"You can define your own commands to take care of such cases,\n",
"or use these special spacing commands:\t\\\\\n",
"\\iii \\verb2\\,2~~~thin space~~~~~~(any mode) \\\\\t\t% \"verbatim\"\n",
"\\iii \\verb9\\:9~~~medium space~~~~(math mode only) \\\\\n",
"\\iii \\verb#\\;#~~~thick space~~~~~(math mode only) \\\\\n",
"\\iii \\verb2\\!2~~~thin backspace~~(math mode only) \\\\\n",
"A most precise spacing command can be used in either math or\n",
"paragraph modes; the \\verb2\\kern2 command. Use it with the\n",
"unit ``em'', which is the width of a capital M. Example:\n",
"to print `R' over an `I' you might use the command\n",
"\\verb@I\\kern-0.27emR@ to produce ``I\\kern-0.27emR''.\n",
"\n",
"\\section{Displayed Text}\t\t(PAGE 3)\n",
"Text is displayed by indenting it from the left margin.\n",
"Quotations are commonly displayed. There are short quotations\n",
"\\begin{quote}\n",
" This is a short a quotation. It consists of a\n",
" single paragraph of text. There is no paragraph\n",
" indentation.\n",
"\\end{quote}\n",
"and longer ones.\n",
"\\begin{quotation}\n",
" This is a longer quotation. It consists of two paragraphs\n",
" of text. The beginning of each paragraph is indicated\n",
" by an extra indentation.\n",
"\n",
" This is the second paragraph of the quotation. It is just\n",
" as dull as the first paragraph.\n",
"\\end{quotation}\n",
"\n",
"Footnotes\\footnote{This is an example of a footnote.} pose no problem.\n",
"Likewise, bibliographic references \\cite{Lam} are handled with ease.\n",
"!`\\TeX\\ can g\\`{e}n\\'{e}rate alm\\\"{o}st all the accents and\n",
"spe\\c{c}ial symbols used in Western \\cite{Sch} l\\aa nguages! Likewise,\n",
"its arsenal of mathematical sym$\\beta$ols, introduced below, is formidable.\n",
"\n",
"Another frequently-displayed structure is a list.\n",
"The following is an example of an {\\em itemized} list.\n",
" \\begin{itemize}\n",
" \\item This is the first item of an itemized list. Each item\n",
" in the list is marked with a ``tick''. The document\n",
" style determines what kind of tick mark is used.\n",
"\n",
" \\item This is the second item of the list. Need there be more?\n",
" \\end{itemize}\n",
"\n",
"\\section{Mathematical Formulae}\n",
"\\TeX\\ is good at typesetting mathematical formulas like\n",
" $ x-3y = 7 $\n",
"or\n",
" $ y_{i+1} = x_{i}^{2n} - \\sqrt{5}x_{i}^{n} + 1$.\n",
"Remember that a letter like\n",
" \\( x \\) % $ ... $ and \\( ... \\) are equivalent\n",
"is a formula when it denotes a mathematical symbol, and should\n",
"be treated as one.\n",
"\n",
"Mathematical formulas may also be\t\t% use \\[ \\]\n",
"{\\em displayed}. A displayed formula\t\t% or $$ $$\n",
"is one-line long; multiline formulas\t\t% or \\begin{equation}\n",
"require special formatting instructions.\t% \\begin{eqnarray}\n",
"The following formulae demonstrate\n",
"many constructions you might find useful.\n",
"Refer to equation (\\ref{eq:fermat}), which is probably true,\n",
"while equations (\\ref{eq:dumb}-\\ref{eq:realdumb}) are silly.\n",
"Note that the \\verb9equation9 and \\verb9eqnarray9 environments\n",
"number the equations, but \\verb9eqnarray*9 doesn't.\n",
"\\[ x_{i+1} ~=~ N^{i+1}(x_{0}) ~=~ N(x_{i}) ~=~\n",
"\tx_{i} - \\frac{f(x_{i})}{f'(x_{i})}\t\\]\n",
"\n",
"$$ \\frac{\\partial u}{\\partial t} + \\nabla^{4}u + \\nabla^{2}u +\n",
"\t\\frac12 |\\nabla u|^{2}~ =~ c^2 $$\n",
"\n",
"\t\t\t\t(PAGE 4)\n",
"\\begin{equation} a^{p} + b^p \\neq c^{p} ~~~\\mbox{for } p>2\n",
"\t~~ \\mbox{(see proof in margin)} \\label{eq:fermat}\n",
"\\end{equation}\n",
"$$ \\lim_{n \\rightarrow \\infty}x_{n} \\geq \\pi $$\n",
"$$ \\forall x \\in {\\cal O} ~~\\exists \\delta ~~~\\mbox{such that}~~~\n",
"\t|y-x|<\\delta ~\\Rightarrow ~y \\in {\\cal O} $$\n",
"\\vspace{4mm}\n",
"$$\n",
"\\Psi' = \\frac{d}{d \\phi} \\left( \\begin{array}{c}\n",
" \\phi_{2} \\\\ \\phi_{3} \\\\ 1 - \\phi_{2} - \\phi_{1}^{2}/2\n",
" \\end{array} \\right)\n",
" ~~~~~~~~~~~~~\n",
" \\Theta = \\left(\t\\begin{array}{ccc}\n",
"\t0 \t\t\t& \t1\t&\t0\t\\\\\n",
"- \\theta_{1} \\psi_{1} - \\psi_{2} &\t0\t&\t\\psi_3\t\\\\\n",
"\t-\\phi_{1} \t\t&\t-1\t&\t0\n",
"\t\t\t\\end{array} \\right)\n",
"$$\n",
"\\vspace{4mm}\n",
"\\begin{eqnarray}\n",
"\t\\int_0^{\\infty} e^{-x^2}\\,dx\n",
"\t& = &\te^{-\\left(\\int_0^{\\infty}x\\,dx\\right)^2} \\label{eq:dumb} \\\\\n",
"\t& = &\te^{-\\infty} ~~~~~\\mbox{(bogus)} \\\\\n",
"\t& = &\t0.38-1.7i ~~~~~\\mbox{(not!)} \\label{eq:realdumb}\n",
"\\end{eqnarray}\n",
"\\vspace{4mm}\n",
"\\begin{eqnarray*}\t\t\t% \"*\" = no line numbering\n",
" \\sum_{n=1}^k \\frac1n\n",
"\t& \\approx &\t\\ln k + \\gamma \\\\\n",
"\t& = &\t\t(\\ln 10)(\\log_{10}k) + \\gamma \\\\\n",
"\t& \\approx &\t2.3026\\log_{10}k + 0.57772\n",
"\\end{eqnarray*}\n",
"\n",
"\\vspace{6mm}\n",
"\\centerline{\n",
"\\begin{tabular}{ | c | c c c | } \\hline\n",
" $k$ & $x_1^k$ & $x_2^k$ & $x_3^k$ \\\\\n",
" \\hline\n",
" 0 & -0.30000000 & 0.60000000 & 0.70000000 \\\\\n",
" 1 & 0.47102965 & 0.04883157 & -0.53345964 \\\\\n",
" 2 & 0.49988691 & 0.00228830 & -0.52246185 \\\\\n",
" 3 & 0.49999976 & 0.00005380 & -0.52365600 \\\\\n",
" 4 & 0.50000000 & 0.00000307 & -0.52359743 \\\\\n",
" 5 & 0.50000000 & 0.00000007 & -0.52359885 \\\\\n",
" 6 & 0.50000000 & 0.00000000 & -0.52359877 \\\\\n",
" 7 & 0.50000000 & 0.00000000 & -0.52359878 \\\\\n",
" \\hline\n",
"\\end{tabular}}\n",
"\n",
"Unary operators ``plus'' and ``minus'' -- just use exponentiation:\n",
"$$\t{}^{+}0.168 \\mbox{ or } {}^{-}1.168\t$$\n",
"\n",
"$$ \\Vert \\diamond\\star \\Vert ~~~ \\clubsuit\\diamondsuit\\heartsuit\\spadesuit\n",
" ~~~ \\sharp\\flat\\natural ~~~ \\cap\\cup\\pm\\mp ~~~ \\prod\\alpha\\beta\\gamma\n",
" ~~~ \\oint_Cf(z)dz ~~~ \\Gamma_{\\sqrt7}^{v,\\upsilon} ~~~ V\\bigoplus W $$\n",
"\n",
"\t\t\t\t(PAGE 5)\n",
"\\begin{thebibliography}{9}\t% 9 = maximum expected references!\n",
"\n",
"\\bibitem{Lam} Lamport, Leslie.\n",
"\\LaTeX : A Document Preparation System. \\\\\n",
"Copyright \\copyright 1986, Addison-Wesley Publ.Co.,Inc.\n",
"\n",
"\\bibitem{Sch} Schl\\oe ff\\d{o}nffl\\t{oo}\\ae g\\\"{e}n,\n",
"\\L\\\"{a}rs. Silly Typography.\t\t\\\\\n",
"{\\em Journal of Linguistic Horseplay 19D} (1977), 23-37.\n",
"\n",
"\\end{thebibliography}\n",
"\\end{document} % End of document."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-6-014c9c395e7a>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-6-014c9c395e7a>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m from http://spot.colorado.edu/~sitelic/samplecode/latex/AiryBessel.html\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"from http://spot.colorado.edu/~sitelic/samplecode/latex/AiryBessel.html "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\n",
"$$\n",
"\\frac{1}{3}\\\n",
"$$\n",
"\n",
"$$\n",
"\\frac{obs}{expe}\\\n",
"$$\n",
"\n",
"$$ Ai(z) =\n",
"\t\\frac13\\sqrt{z}\\left[\n",
"\tI_{-1/3}(\\zeta)\n",
"\t-I_{1/3}(\\zeta) \\right]\n",
"\t=\n",
"\t\\pi^{-1}\\sqrt{z/3}K_{1/3}(\\zeta)\n",
"$$\n",
"\n",
"{\\bf 10.4.15}\n",
"$$ Ai(-z) =\n",
"\t\\frac13\\sqrt{z}\n",
"\t\\left[\n",
"\tJ_{1/3}(\\zeta) +\n",
"\tJ_{-1/3}(\\zeta) \\right]\n",
"\t=\n",
"\t\\frac12 \\sqrt{z/3} \\left[\n",
"\te^{\\pi i/6} H_{1/3}^{(1)}(\\zeta)\n",
"\t+ e^{-\\pi i/6}H_{1/3}^{(2)}(\\zeta)\n",
"\t\\right]\n",
"$$"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%latex\n",
"\n",
"$$\n",
"\\frac{1}{3}\\\n",
"$$\n",
"\n",
"$$\n",
"\\frac{obs}{expe}\\\n",
"$$\n",
"\n",
"$$ Ai(z) =\n",
"\t\\frac13\\sqrt{z}\\left[\n",
"\tI_{-1/3}(\\zeta)\n",
"\t-I_{1/3}(\\zeta) \\right]\n",
"\t=\n",
"\t\\pi^{-1}\\sqrt{z/3}K_{1/3}(\\zeta)\n",
"$$\n",
"\n",
"{\\bf 10.4.15}\n",
"$$ Ai(-z) =\n",
"\t\\frac13\\sqrt{z}\n",
"\t\\left[\n",
"\tJ_{1/3}(\\zeta) +\n",
"\tJ_{-1/3}(\\zeta) \\right]\n",
"\t=\n",
"\t\\frac12 \\sqrt{z/3} \\left[\n",
"\te^{\\pi i/6} H_{1/3}^{(1)}(\\zeta)\n",
"\t+ e^{-\\pi i/6}H_{1/3}^{(2)}(\\zeta)\n",
"\t\\right]\n",
"$$\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.4"
},
"widgets": {
"state": {},
"version": "1.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment