diff --git a/testing/latex_envs/latex_env_doc.ipynb b/testing/latex_envs/latex_env_doc.ipynb new file mode 100644 index 0000000..64a7801 --- /dev/null +++ b/testing/latex_envs/latex_env_doc.ipynb @@ -0,0 +1,638 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#Table of Contents\n", + "* [1. Goal](#1.-Goal)\n", + "\t* [1.1 Initial goal](#1.1-Initial-goal)\n", + "\t* [1.2 Possibilities](#1.2-Possibilities)\n", + "* [2. Usage and examples](#2.-Usage-and-examples)\n", + "\t* [2.1 Installation](#2.1-Installation)\n", + "\t* [2.2 A first example:](#2.2-A-first-example:)\n", + "\t* [2.3 Second example](#2.3-Second-example)\n", + "\t* [2.4 Third example:](#2.4-Third-example:)\n", + "* [3. (post)-Converters](#3.-%28post%29-Converters)\n", + "\t* [3.1 Installation](#3.1-Installation)\n", + "\t* [3.2 Conversion to html](#3.2-Conversion-to-html)\n", + "\t* [3.3 Conversion to LaTeX](#3.3-Conversion-to-LaTeX)\n", + "* [4. Disclaimer, sources and thanks](#4.-Disclaimer,-sources-and-thanks)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "IPython.load_extensions('calico-document-tools');" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%javascript \n", + "IPython.load_extensions('calico-document-tools');" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "IPython.load_extensions('latex_envs');" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%javascript \n", + "IPython.load_extensions('latex_envs');" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 1. Goal" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1.1 Initial goal" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The initial goal was only to add an environment `theorem` in my workflow. That is to be able to type something like\n", + "\\begin{listing}\n", + "\\begin{theorem} \n", + "Let $u$ and $v$ be two vectors of $\\mathbb{R}^n$. The dot product can be expressed as\n", + "$$u^Tv = |u||v| \\cos \\theta,$$ \n", + "where $\\theta$ is the angle between $u$ and $v$ ...\n", + "\\end{theorem}\n", + "\\end{listing}\n", + "in a markdown cell and have it rendered, like\n", + "\n", + "\\begin{theorem}\n", + "Let $u$ and $v$ be two vectors of $\\mathbb{R}^n$. The dot product can be expressed as $$u^Tv = |u||v| \\cos \\theta,$$ where $\\theta$ is the angle between $u$ and $v$ ...\n", + "\\end{theorem}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1.2 Possibilities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The initial project has evolved to account for more environments. We also added some LaTeX commands (e.g. textit, textbf) -- this is useful in the case of copy-paste from a LaTeX document. Labels and references are supported, including for equations. \n", + "\n", + "**Available environments **\n", + "\n", + "- *property, theorem, lemma, corollary, proposition, definition,remark, problem, exercise, example*,\n", + "- *enumerate, itemize* and an environment *listing*,\n", + "- *textboxa*, wich is a `textbox` environment ddefined as a demonstration (see below).\n", + "\n", + "More environments can be added easily in the javascript source file `thmsInNb.js`. Two counters for numbering are implemented: one for theorems' like environments, and the second for exercises' like environments. \n", + "\n", + "\n", + "*Limitations:*\n", + "\n", + "- The automatic numbering of environments is updated each time the cell is rendered. One should reload the page to update everything. \n", + "- Environments can be nested. This is not always perfect..." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# 2. Usage and examples" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2.1 Installation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The extension consists in two javascript scripts: `latex_envs.js`, `thmsInNb.js` together with a stylesheet `latex_envs.css`. \n", + "Follow the instructions in the [wiki](https://github.com/ipython-contrib/IPython-notebook-extensions/wiki) to install the extension. You can simply copy these files in the notebook extension directory (usually ~/.ipython/nbextensions) and load the extension in the notebook by \n", + "\n", + " %%javascript \n", + " IPython.load_extensions('latex_envs');" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2.2 A first example:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This example shows another example of environment, featuring automatic numerotation, and the use of labels and references. Also note that standard markdown can be present in the environment and is interpreted. \n", + "*The rendering is done according to the stylesheet `latex_env.css`, which of course, can be tailored to specific uses and tastes*. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\\begin{listing}\n", + "\\begin{definition} \\label{def:FT}\n", + "Let $x[n]$ be a sequence of length $N$. Then, its **Fourier transform** is given by\n", + "\\begin{equation}\n", + "\\label{eq:FT}\n", + "X[k]= \\frac{1}{N} \\sum_{n=0}^{N-1} x[n] e^{-j2\\pi \\frac{kn}{N}}\n", + "\\end{equation}\n", + "\\end{definition}\n", + "\\end{listing}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\\begin{definition} \\label{def:FT}\n", + "Let $x[n]$ be a sequence of length $N$. Then, its **Fourier transform** is given by\n", + "\\begin{equation}\n", + "\\label{eq:FT2}\n", + "X[k]= \\frac{1}{N} \\sum_{n=0}^{N-1} x[n] e^{-j2\\pi \\frac{kn}{N}}\n", + "\\end{equation}\n", + "\\end{definition}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is an extremely important tool in signal processing. We put this in evidence using the `textboxa` environment -- which is defined here uin the css, and that one should define in the LaTeX counterpart:\n", + "\\begin{listing}\n", + "\\begin{textboxa}\n", + "The Fourier transform is an extremely useful tool to have in your toolbox!\n", + "\\end{textboxa}\n", + "\\end{listing}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\\begin{textboxa}\n", + "The Fourier transform is an extremely useful tool to have in your toolbox!\n", + "\\end{textboxa}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As an example, consider the Fourier transform (\\ref{eq:FT2}) of a pure cosine wave given by\n", + "$$\n", + "x[n]= \\cos(2\\pi k_0 n/N),\n", + "$$\n", + "where $k_0$ is an integer. Its Fourier transform is given by \n", + "$$\n", + "X[k] = \\frac{1}{2} \\left( \\delta[k-k_0] + \\delta[k-k_0] \\right), \n", + "$$\n", + "modulo $N$. This is illustrated in the following simple script:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAEZCAYAAACKF66QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGkVJREFUeJzt3Xu8XGV97/HPV8KdCEbaEJGbYsQqIlbRqj1svHCAo0hb\nRbHFeMOengq8PN6gVkk9VdS2pyhWX1URo1IQLUSwKEROIuANgSAiIKIGUMkGFDTIRYTv+WM9m0yG\nmdkze8/O7Gfn+3699ivr+qzfrD35zrOfNbNGtomIiHo9YtQFRETE9CTIIyIqlyCPiKhcgjwionIJ\n8oiIyiXIIyIqlyAPACR9TNLfj7qOYZC0UNJFkn4j6Z9GXU8rSVtLOlfSnZI+P+p62klaJ2n3UdcR\ng5k36gKiN0lrgD8EHiiLDCy2vXaYx7H9N8NsT9KDwJ62fzLMdvv0RuBW248cwbEn8zKa3+cC2w+O\nuph2tuePuoYYXHrks5+BF9ueX34eOewQlzTl54GkXp0BTXG/6doNuHYqO85wXdDUdv1sDPGoV4K8\nUpK2lHSSpJ+Xn3+VtEVZ9xpJF7dt/6Ckx5XpT5ehlPMk3QUcUJb9n5btXyzpSkl3SPqGpL1b1q2R\n9HZJVwHr2l8IJF1UJr9X/lR/uaQxST8r+90CnCJpB0lflnSrpF+VIYedW9pZJek9ki4pwyTn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n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib inline\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt \n", + "from numpy.fft import fft\n", + "k0=4; N=128; n=np.arange(N); k=np.arange(N)\n", + "x=np.sin(2*np.pi*k0*n/N)\n", + "X=fft(x)\n", + "plt.stem(k,np.abs(X))\n", + "plt.xlim([0, 20])\n", + "plt.title(\"Fourier transform of a cosine\")\n", + "plt.xlabel(\"Frequency index (k)\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2.3 Second example" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This example shows a series of environments, with different facets; links, references, markdown or/and LaTeX formatting within environments. Again, the rendering is done according to the stylesheet `latex_env.css`, which can be tailored. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\\begin{listing}\n", + "\\begin{definition} \\label{def:diffeq}\n", + "We call \\textbf{difference equation} an equation of the form\n", + "$$\n", + "\\label{eq:diffeq}\n", + "y[n]= \\sum_{k=1}^{p} a_k y[n-k] + \\sum_{i=0}^q b_i x[n-i]\n", + "$$\n", + "\\end{definition}\n", + "\n", + "\\begin{property}\n", + "If all the $a_k$ in equation (\\ref{eq:diffeq}) of definition \\ref{def:diffeq} are zero, then the filter has a **finite impulse response**. \n", + "\\end{property}\n", + "\n", + "\\begin{proof}\n", + "Let $\\delta[n]$ denote the Dirac impulse. Take $x[n]=\\delta[n]$ in (\\ref{eq:diffeq}). This yields, by definition, the impulse response:\n", + "$$\n", + "\\label{eq:fir}\n", + "h[n]= \\sum_{i=0}^q b_i \\delta[n-i],\n", + "$$\n", + "which has finite support. \n", + "\\end{proof}\n", + "\n", + "\\begin{theorem}\n", + "The poles of a causal stable filter are located within the unit circle in the complex plane.\n", + "\\end{theorem}\n", + "\n", + "\\begin{example} \\label{ex:IIR1}\n", + "Consider $y[n]= a y[n-1] + x[n]$. The pole of the transfer function is $z=a$. The impulse response $h[n]=a^n$ has infinite support.\n", + "\\end{example}\n", + "\n", + "In the following exercise, you will check that the filter is stable iff $a$<1.\n", + "\n", + "\\begin{exercise}\\label{ex:exofilter}\n", + "Consider the filter defined in Example \\ref{ex:IIR1}. Using the **function** `lfilter` of scipy, compute and plot the impulse response for several values of $a$.\n", + "\\end{exercise}\n", + "\n", + "\\end{listing}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The lines above are rendered as follows (of course everything can be tailored in the stylesheet):\n", + "\n", + "\\begin{definition} \\label{def:diffeq}\n", + "We call \\textbf{difference equation} an equation of the form\n", + "\\begin{equation}\n", + "\\label{eq:diffeq}\n", + "y[n]= \\sum_{k=1}^{p} a_k y[n-k] + \\sum_{i=0}^q b_i x[n-i]\n", + "\\end{equation}\n", + "\\end{definition}\n", + "Properties of the filter are linked to the coefficients of the difference equation. For instance, an immediate property is \n", + "\n", + "\\begin{property}\n", + "If all the $a_k$ in equation (\\ref{eq:diffeq}) of definition \\ref{def:diffeq} are zero, then the filter has a **finite impulse response**. \n", + "\\end{property}\n", + "\n", + "\\begin{proof}\n", + "Let $\\delta[n]$ denote the Dirac impulse. Take $x[n]=\\delta[n]$ in (\\ref{eq:diffeq}). This yields, by definition, the impulse response:\n", + "\\begin{equation}\n", + "\\label{eq:fir}\n", + "h[n]= \\sum_{i=0}^q b_i \\delta[n-i],\n", + "\\end{equation}\n", + "which has finite support. \n", + "\\end{proof}\n", + "\n", + "\n", + "\\begin{theorem}\n", + "The poles of a causal stable filter are located within the unit circle in the complex plane.\n", + "\\end{theorem}\n", + "\n", + "\n", + "\\begin{example} \\label{ex:IIR1}\n", + "Consider $y[n]= a y[n-1] + x[n]$. The pole of the transfer function is $z=a$. The impulse response $h[n]=a^n$ has infinite support.\n", + "\\end{example}\n", + "\n", + "In the following exercise, you will check that the filter is stable iff $a$<1.\n", + "\n", + "\\begin{exercise}\\label{ex:exofilter}\n", + "Consider the filter defined in Example \\ref{ex:IIR1}. Using the **function** `lfilter` of scipy, compute and plot the impulse response for several values of $a$.\n", + "\\end{exercise}\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The solution of exercise \\ref{ex:exofilter}:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt \n", + "from scipy.signal import lfilter\n", + "d=np.zeros(100); d[0]=1 #dirac impulse\n", + "alist=[0.2, 0.8, 0.9, 0.95, 0.99, 0.999, 1.001, 1.01]\n", + "for a in alist:\n", + " h=lfilter([1], [1, -a],d)\n", + " _=plt.plot(h, label=\"a={}\".format(a))\n", + "plt.ylim([0,1.5])\n", + "plt.xlabel('Time')\n", + "_=plt.legend()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2.4 Third example:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This example shows that environments like itemize or enumerate are also available. As already indicated, this is useful for copying text from a TeX file. Following the same idea, text formating commands `\\textit`, `\\textbf`, `\\underline`, etc are also available." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\\begin{listing}\n", + "The following \\textit{environments} are available:\n", + "\\begin{itemize}\n", + " \\item \\textbf{Theorems and likes}\n", + " \\begin{enumerate}\n", + " \\item theorem,\n", + " \\item lemma,\n", + " \\item corollary\n", + " \\item ...\n", + " \\end{enumerate}\n", + " \\item \\textbf{exercises}\n", + " \\begin{enumerate}\n", + " \\item problem,\n", + " \\item example,\n", + " \\item exercise\n", + " \\end{enumerate}\n", + "\\end{itemize}\n", + "\\end{listing}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "which gives... \n", + "\n", + "The following \\textit{environments} are available:\n", + "\\begin{itemize}\n", + "\\item \\textbf{Theorems and likes}\n", + "\\begin{enumerate}\n", + "\\item theorem,\n", + "\\item lemma,\n", + "\\item corollary\n", + "\\item ...\n", + "\\end{enumerate}\n", + "\\item \\textbf{exercises}\n", + "\\begin{enumerate}\n", + "\\item problem,\n", + "\\item example,\n", + "\\item exercise\n", + "\\end{enumerate}\n", + "\\end{itemize}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 3. (post)-Converters" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The extension works in the live-notebook. Since it relies on a bunch of javascript, the notebook does not render as is in very nice services such as `nbviewer` or `github` viewer. Similarly, `nbconvert` does not know of the LaTeX constructs which are used and therefore do not fully convert notebooks making use of this extension. Therefore, it is necessary to add a post conversion step to conversions provided by `nbconvert`. Though an interface exists for adding post-converters to nbconvert, this (first) author was too lazy and not enough strong to implement the post conversion along these lines. What has be done are simple `bash` and `python` scripts that perform this conversion." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3.1 Installation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Copy the scripts files to a directory in your search path, or launch the scripts with the complete path. The two main scripts are `ipynb_thms_to_html` (conversion to html, of course:) and `ipynb_thms_to_latex` (conversion to LaTeX!)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3.2 Conversion to html" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Requirements**: You will need `perl`, `nodejs`, and `ipython3` (the script calls `ipython3`; if your interpreter is `ipython`, edit the script and replace the different occurences).\n", + "\n", + "The conversion to html is done by something like \n", + "\n", + " [path/]ipynb_thms_to_html filename\n", + "or a list of files such as\n", + "\n", + " [path/]ipynb_thms_to_html *.ipynb\n", + "In turn, this script makes somes substitutions using `perl`, and then uses the `nodesj` javascript interpreter to make the very same substitutions that are done in the live notebook.\n", + "The conversion uses the template `thmsInNb.tpl` (located in the script directory). It also copies the css `latex_env.css` in the directory of the output html file (it must be copied with html files in the case of web upload)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3.3 Conversion to LaTeX" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Requirements**: You will need `perl` and `ipython3`. \n", + "\n", + "The conversion to LaTeX is done by something like \n", + "\n", + " [path/]ipynb_thms_to_latex filename\n", + "or a list of files such as\n", + "\n", + " [path/]ipynb_thms_to_latex *.ipynb\n", + " \n", + "The script makes some substitutions and cleaning in arkdown cells, then calls the legacy `nbconvert`. Afterward, it runs through the LaTeX environments and converts their contents (which can contain markdown markup) to LaTeX. Note that the script contains a list of the LaTeX environments to process. In the case of the addition of an environment in the main javascript (`thmsInNb.js`), this list must also be updated. \n", + "\n", + "Finally, the script removes the header and footer in the LaTeX file. This is a personnal choice, and the corresponding line can be safely commented. \n", + "\n", + "\\begin{example}\n", + "As for an example, the present document has been converted using\n", + " \n", + " ipynb_thms_to_latex latex_env_doc.ipynb\n", + " \n", + "Then the resulting file (without header/footer) has been included in the main file `documentation.tex`, where some LaTeX definitions of environments are done (namely listings, colors, etc) and compiled using \n", + " \n", + " xelatex documentation\n", + " \n", + "The output can be consulted [here](documentation.pdf). \n", + "\\end{example}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 4. Disclaimer, sources and thanks" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is a not-quick but certainly dirty hack. I am a complete beginner in javascript and of course there are obviously a large amount of possible improvements of the code, in cleaning, factorizing, etc! Language also needs improvement. \n", + "\n", + "**Contributions will be welcome and deeply appreciated.** \n", + "\n", + "Originally, I used a piece of code from the nice online markdown editor `stackedit` [https://github.com/benweet/stackedit/issues/187](https://github.com/benweet/stackedit/issues/187), where the authors also considered the problem of incorporating LaTeX markup in their markdown. I also used examples and code from [https://github.com/ipython-contrib/IPython-notebook-extensions](https://github.com/ipython-contrib/IPython-notebook-extensions). \n" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "IPython.load_extensions('latex_envs');" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%javascript \n", + "IPython.load_extensions('latex_envs');" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "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.4.3+" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}