A LOT OF CLEANUP IN examples/Notebook
Jonathan Frederic -
r20536:d6d419bc
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -4,53 +4,7
4 "cell_type": "markdown",
4 "cell_type": "markdown",
5 "metadata": {},
5 "metadata": {},
6 "source": [
6 "source": [
7 "# Running the Notebook Server"
7 "# Configuring the Notebook and Server"
8 ]
9 },
10 {
11 "cell_type": "markdown",
12 "metadata": {},
13 "source": [
14 "The IPython notebook server is a custom web server that runs the notebook web application. Most of the time, users run the notebook server on their local computer using IPython's command line interface."
15 ]
16 },
17 {
18 "cell_type": "markdown",
19 "metadata": {},
20 "source": [
21 "## Starting the notebook server using the command line"
22 ]
23 },
24 {
25 "cell_type": "markdown",
26 "metadata": {},
27 "source": [
28 "You can start the notebook server from the command line (Terminal on Mac/Linux, CMD prompt on Windows) by running the following command: \n",
29 "\n",
30 " ipython notebook\n",
31 "\n",
32 "This will print some information about the notebook server in your terminal, including the URL of the web application (by default, `http://127.0.0.1:8888`). It will then open your default web browser to this URL.\n",
33 "\n",
34 "When the notebook opens, you will see the **notebook dashboard**, which will show a list of the notebooks and subdirectories in the directory where the notebook server was started. As of IPython 2.0, the dashboard allows you to navigate to different subdirectories. Because of this, it is no longer necessary to start a separate notebook server for each subdirectory. Most of the time, you will want to start a notebook server in the highest directory in your filesystem where notebooks can be found. Often this will be your home directory.\n",
35 "\n",
36 "You can start more than one notebook server at the same time. By default, the first notebook server starts on port 8888 and later notebook servers search for open ports near that one.\n",
37 "\n",
38 "You can also specify the port manually:\n",
39 "\n",
40 " ipython notebook --port 9999\n",
41 "\n",
42 "Or start notebook server without opening a web browser.\n",
43 "\n",
44 " ipython notebook --no-browser\n",
45 "\n",
46 "The notebook server has a number of other command line arguments that can be displayed with the `--help` flag: \n",
47 "\n",
48 " ipython notebook --help\n",
49 "\n",
50 "<div class=\"alert alert-failure\">\n",
51 "It used to be possible to specify kernel options, such as <code>--pylab inline</code> from the command line. This is deprecated in IPython 2.0 and will be removed in IPython 3.0. To enable matplotlib based plotting for the Python kernel use the <code>%matplotlib</code> magic command.\n",
52 "</div>\n",
53 "\n"
54 ]
8 ]
55 },
9 },
56 {
10 {
@@ -71,19 +25,11
71 },
25 },
72 {
26 {
73 "cell_type": "code",
27 "cell_type": "code",
74 "execution_count": 7,
28 "execution_count": null,
75 "metadata": {
29 "metadata": {
76 "collapsed": false
30 "collapsed": false
77 },
31 },
78 "outputs": [
32 "outputs": [],
79 {
80 "name": "stdout",
81 "output_type": "stream",
82 "text": [
83 "/Users/bgranger/.ipython/profile_default\r\n"
84 ]
85 }
86 ],
87 "source": [
33 "source": [
88 "!ipython profile locate default"
34 "!ipython profile locate default"
89 ]
35 ]
@@ -99,22 +45,11
99 },
45 },
100 {
46 {
101 "cell_type": "code",
47 "cell_type": "code",
102 "execution_count": 3,
48 "execution_count": null,
103 "metadata": {
49 "metadata": {
104 "collapsed": false
50 "collapsed": false
105 },
51 },
106 "outputs": [
52 "outputs": [],
107 {
108 "name": "stdout",
109 "output_type": "stream",
110 "text": [
111 "[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_config.py'\r\n",
112 "[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_qtconsole_config.py'\r\n",
113 "[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_notebook_config.py'\r\n",
114 "[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_nbconvert_config.py'\r\n"
115 ]
116 }
117 ],
118 "source": [
53 "source": [
119 "!ipython profile create my_profile"
54 "!ipython profile create my_profile"
120 ]
55 ]
@@ -128,19 +63,11
128 },
63 },
129 {
64 {
130 "cell_type": "code",
65 "cell_type": "code",
131 "execution_count": 5,
66 "execution_count": null,
132 "metadata": {
67 "metadata": {
133 "collapsed": false
68 "collapsed": false
134 },
69 },
135 "outputs": [
70 "outputs": [],
136 {
137 "name": "stdout",
138 "output_type": "stream",
139 "text": [
140 "/Users/bgranger/.ipython/profile_my_profile\r\n"
141 ]
142 }
143 ],
144 "source": [
71 "source": [
145 "!ipython profile locate my_profile"
72 "!ipython profile locate my_profile"
146 ]
73 ]
@@ -194,22 +121,11
194 },
121 },
195 {
122 {
196 "cell_type": "code",
123 "cell_type": "code",
197 "execution_count": 1,
124 "execution_count": null,
198 "metadata": {
125 "metadata": {
199 "collapsed": false
126 "collapsed": false
200 },
127 },
201 "outputs": [
128 "outputs": [],
202 {
203 "data": {
204 "text/plain": [
205 "'sha1:6c2164fc2b22:ed55ecf07fc0f985ab46561483c0e888e8964ae6'"
206 ]
207 },
208 "execution_count": 1,
209 "metadata": {},
210 "output_type": "execute_result"
211 }
212 ],
213 "source": [
129 "source": [
214 "from IPython.lib import passwd\n",
130 "from IPython.lib import passwd\n",
215 "password = passwd(\"secret\")\n",
131 "password = passwd(\"secret\")\n",
@@ -371,7 +287,7
371 "name": "python",
287 "name": "python",
372 "nbconvert_exporter": "python",
288 "nbconvert_exporter": "python",
373 "pygments_lexer": "ipython3",
289 "pygments_lexer": "ipython3",
374 "version": "3.4.2"
290 "version": "3.4.3"
375 }
291 }
376 },
292 },
377 "nbformat": 4,
293 "nbformat": 4,
@@ -54,34 +54,11
54 },
54 },
55 {
55 {
56 "cell_type": "code",
56 "cell_type": "code",
57 "execution_count": 6,
57 "execution_count": null,
58 "metadata": {
58 "metadata": {
59 "collapsed": false
59 "collapsed": false
60 },
60 },
61 "outputs": [
61 "outputs": [],
62 {
63 "name": "stdout",
64 "output_type": "stream",
65 "text": [
66 "{\n",
67 " \"stdin_port\": 52858, \n",
68 " \"ip\": \"127.0.0.1\", \n",
69 " \"hb_port\": 52859, \n",
70 " \"key\": \"7efd45ca-d8a2-41b0-9cea-d9116d0fb883\", \n",
71 " \"shell_port\": 52856, \n",
72 " \"iopub_port\": 52857\n",
73 "}\n",
74 "\n",
75 "Paste the above JSON into a file, and connect with:\n",
76 " $> ipython <app> --existing <file>\n",
77 "or, if you are local, you can connect with just:\n",
78 " $> ipython <app> --existing kernel-b3bac7c1-8b2c-4536-8082-8d1df24f99ac.json \n",
79 "or even just:\n",
80 " $> ipython <app> --existing \n",
81 "if this is the most recent IPython session you have started.\n"
82 ]
83 }
84 ],
85 "source": [
62 "source": [
86 "%connect_info"
63 "%connect_info"
87 ]
64 ]
@@ -110,7 +87,7
110 },
87 },
111 {
88 {
112 "cell_type": "code",
89 "cell_type": "code",
113 "execution_count": 1,
90 "execution_count": null,
114 "metadata": {
91 "metadata": {
115 "collapsed": false
92 "collapsed": false
116 },
93 },
@@ -121,7 +98,7
121 },
98 },
122 {
99 {
123 "cell_type": "code",
100 "cell_type": "code",
124 "execution_count": 2,
101 "execution_count": null,
125 "metadata": {
102 "metadata": {
126 "collapsed": false
103 "collapsed": false
127 },
104 },
@@ -147,7 +124,7
147 "name": "python",
124 "name": "python",
148 "nbconvert_exporter": "python",
125 "nbconvert_exporter": "python",
149 "pygments_lexer": "ipython3",
126 "pygments_lexer": "ipython3",
150 "version": "3.4.2"
127 "version": "3.4.3"
151 }
128 }
152 },
129 },
153 "nbformat": 4,
130 "nbformat": 4,
@@ -18,25 +18,21
18 "cell_type": "markdown",
18 "cell_type": "markdown",
19 "metadata": {},
19 "metadata": {},
20 "source": [
20 "source": [
21 "`NbConvert` is the library, and the command line tool that allow to convert from notebook to other formats.\n",
21 "`NbConvert` is both a library and command line tool that allows you to convert notebooks to other formats. It ships with many common formats: `html`, `latex`, `markdown`, `python`, `rst`, and `slides`\n",
22 "It is a technological preview in 1.0 but is already usable and highly configurable.\n",
22 "NbConvert relys on the Jinja templating engine, so implementing a new format or tweeking an existing one is easy."
23 "It ships already with many default available formats : `html`, `latex`, `markdown`, `python`, `rst` and `slides`\n",
24 "which are fully base on Jinja templating engine, so writing a converter for your custom format or tweeking the existing \n",
25 "one should be extra simple."
26 ]
23 ]
27 },
24 },
28 {
25 {
29 "cell_type": "markdown",
26 "cell_type": "markdown",
30 "metadata": {},
27 "metadata": {},
31 "source": [
28 "source": [
32 "You can invoke nbconvert by doing\n",
29 "You can invoke nbconvert by running\n",
33 "\n",
30 "\n",
34 "```bash\n",
31 "```bash\n",
35 "$ ipython nbconvert <options and arguments>\n",
32 "$ ipython nbconvert <options and arguments>\n",
36 "```\n",
33 "```\n",
37 "\n",
34 "\n",
38 "Call `ipython nbconvert` with the `--help` flag or no aruments to get basic help on how to use it.\n",
35 "Call `ipython nbconvert` with the `--help` flag or without any aruments to display the basic help. For detailed configuration help, use the `--help-all` flag."
39 "For more information about configuration use the `--help-all` flag"
40 ]
36 ]
41 },
37 },
42 {
38 {
@@ -50,230 +46,105
50 "cell_type": "markdown",
46 "cell_type": "markdown",
51 "metadata": {},
47 "metadata": {},
52 "source": [
48 "source": [
53 "We will be converting `Custom Display Logic.ipynb`. \n",
49 "As a test, the `Index.ipynb` notebook in the directory will be convert. \n",
54 "Be sure to have runed some of the cells in it to have output otherwise you will only see input in nbconvert.\n",
50 "\n",
55 "Nbconvert **do not execute the code** in the notebook files, it only converts what is inside."
51 "If you're converting a notebook with code in it, make sure to run the code cells that you're interested in before attempting to convert the notebook. Nbconvert **does not execute the code cell** of the notebooks that it converts."
56 ]
52 ]
57 },
53 },
58 {
54 {
59 "cell_type": "code",
55 "cell_type": "code",
60 "execution_count": 1,
56 "execution_count": null,
61 "metadata": {
57 "metadata": {
62 "collapsed": false
58 "collapsed": false
63 },
59 },
64 "outputs": [
60 "outputs": [],
65 {
66 "name": "stderr",
67 "output_type": "stream",
68 "text": [
69 "[NbConvertApp] Using existing profile dir: u'/Users/bussonniermatthias/.ipython/profile_default'\n",
70 "[NbConvertApp] Converting notebook 04 - Custom Display Logic.ipynb to html\n",
71 "[NbConvertApp] Support files will be in 04 - Custom Display Logic_files/\n",
72 "[NbConvertApp] Loaded template html_full.tpl\n",
73 "[NbConvertApp] Writing 221081 bytes to 04 - Custom Display Logic.html\n"
74 ]
75 }
76 ],
77 "source": [
61 "source": [
78 "%%bash\n",
62 "%%bash\n",
79 "ipython nbconvert '04 - Custom Display Logic.ipynb'"
63 "ipython nbconvert 'Index.ipynb'"
80 ]
64 ]
81 },
65 },
82 {
66 {
83 "cell_type": "markdown",
67 "cell_type": "markdown",
84 "metadata": {},
68 "metadata": {},
85 "source": [
69 "source": [
86 "Html is the default value (that can be configured) , so the verbose form would be "
70 "Html is the (configurable) default value. The verbose form of the same command as above is "
87 ]
71 ]
88 },
72 },
89 {
73 {
90 "cell_type": "code",
74 "cell_type": "code",
91 "execution_count": 2,
75 "execution_count": null,
92 "metadata": {
76 "metadata": {
93 "collapsed": false
77 "collapsed": false
94 },
78 },
95 "outputs": [
79 "outputs": [],
96 {
97 "name": "stderr",
98 "output_type": "stream",
99 "text": [
100 "[NbConvertApp] Using existing profile dir: u'/Users/bussonniermatthias/.ipython/profile_default'\n",
101 "[NbConvertApp] Converting notebook 04 - Custom Display Logic.ipynb to html\n",
102 "[NbConvertApp] Support files will be in 04 - Custom Display Logic_files/\n",
103 "[NbConvertApp] Loaded template html_full.tpl\n",
104 "[NbConvertApp] Writing 221081 bytes to 04 - Custom Display Logic.html\n"
105 ]
106 }
107 ],
108 "source": [
80 "source": [
109 "%%bash\n",
81 "%%bash\n",
110 "ipython nbconvert --to=html '04 - Custom Display Logic.ipynb'"
82 "ipython nbconvert --to=html 'Index.ipynb'"
111 ]
83 ]
112 },
84 },
113 {
85 {
114 "cell_type": "markdown",
86 "cell_type": "markdown",
115 "metadata": {},
87 "metadata": {},
116 "source": [
88 "source": [
117 "You can also convert to latex, which will take care of extractin the embeded base64 encoded png, or the svg and call inkscape to convert those svg to pdf if necessary :"
89 "You can also convert to latex, which will extract the embeded images. If the embeded images are SVGs, inkscape is used to convert them to pdf:"
118 ]
90 ]
119 },
91 },
120 {
92 {
121 "cell_type": "code",
93 "cell_type": "code",
122 "execution_count": 3,
94 "execution_count": null,
123 "metadata": {
95 "metadata": {
124 "collapsed": false
96 "collapsed": false
125 },
97 },
126 "outputs": [
98 "outputs": [],
127 {
128 "name": "stderr",
129 "output_type": "stream",
130 "text": [
131 "[NbConvertApp] Using existing profile dir: u'/Users/bussonniermatthias/.ipython/profile_default'\n",
132 "[NbConvertApp] Converting notebook 04 - Custom Display Logic.ipynb to latex\n",
133 "[NbConvertApp] Support files will be in 04 - Custom Display Logic_files/\n",
134 "Setting Language: .UTF-8\n",
135 "\n",
136 "(process:26432): Gtk-WARNING **: Locale not supported by C library.\n",
137 "\tUsing the fallback 'C' locale.\n",
138 "Setting Language: .UTF-8\n",
139 "\n",
140 "(process:26472): Gtk-WARNING **: Locale not supported by C library.\n",
141 "\tUsing the fallback 'C' locale.\n",
142 "Setting Language: .UTF-8\n",
143 "\n",
144 "(process:26512): Gtk-WARNING **: Locale not supported by C library.\n",
145 "\tUsing the fallback 'C' locale.\n",
146 "Setting Language: .UTF-8\n",
147 "\n",
148 "(process:26552): Gtk-WARNING **: Locale not supported by C library.\n",
149 "\tUsing the fallback 'C' locale.\n",
150 "Setting Language: .UTF-8\n",
151 "\n",
152 "(process:26592): Gtk-WARNING **: Locale not supported by C library.\n",
153 "\tUsing the fallback 'C' locale.\n",
154 "[NbConvertApp] Loaded template latex_article.tplx\n",
155 "[NbConvertApp] Writing 41196 bytes to 04 - Custom Display Logic.tex\n"
156 ]
157 }
158 ],
159 "source": [
99 "source": [
160 "%%bash\n",
100 "%%bash\n",
161 "ipython nbconvert --to=latex '04 - Custom Display Logic.ipynb'"
101 "ipython nbconvert --to=latex 'Index.ipynb'"
162 ]
102 ]
163 },
103 },
164 {
104 {
165 "cell_type": "markdown",
105 "cell_type": "markdown",
166 "metadata": {},
106 "metadata": {},
167 "source": [
107 "source": [
168 "You should just have to compile the generated `.tex` file. If you get the required packages installed, if should compile out of the box.\n",
108 "Note that the latex conversion creates latex, not a PDF. To create a PDF you need the required third party packages to compile the latex.\n",
169 "\n",
109 "\n",
170 "For convenience we allow to run extra action after the conversion has been done, in particular for `latex` we have a `pdf` post-processor. \n",
110 "A `--post` flag is provided for convinience which allows you to have nbconvert automatically compile a PDF for you from your output."
171 "You can define the postprocessor tu run with the `--post` flag."
172 ]
111 ]
173 },
112 },
174 {
113 {
175 "cell_type": "code",
114 "cell_type": "code",
176 "execution_count": 4,
115 "execution_count": null,
177 "metadata": {
116 "metadata": {
178 "collapsed": false
117 "collapsed": false
179 },
118 },
180 "outputs": [
119 "outputs": [],
181 {
182 "name": "stderr",
183 "output_type": "stream",
184 "text": [
185 "[NbConvertApp] Using existing profile dir: u'/Users/bussonniermatthias/.ipython/profile_default'\n",
186 "[NbConvertApp] Converting notebook 04 - Custom Display Logic.ipynb to latex\n",
187 "[NbConvertApp] Support files will be in 04 - Custom Display Logic_files/\n",
188 "Setting Language: .UTF-8\n",
189 "\n",
190 "(process:26658): Gtk-WARNING **: Locale not supported by C library.\n",
191 "\tUsing the fallback 'C' locale.\n",
192 "Setting Language: .UTF-8\n",
193 "\n",
194 "(process:26698): Gtk-WARNING **: Locale not supported by C library.\n",
195 "\tUsing the fallback 'C' locale.\n",
196 "Setting Language: .UTF-8\n",
197 "\n",
198 "(process:26738): Gtk-WARNING **: Locale not supported by C library.\n",
199 "\tUsing the fallback 'C' locale.\n",
200 "Setting Language: .UTF-8\n",
201 "\n",
202 "(process:26778): Gtk-WARNING **: Locale not supported by C library.\n",
203 "\tUsing the fallback 'C' locale.\n",
204 "Setting Language: .UTF-8\n",
205 "\n",
206 "(process:26818): Gtk-WARNING **: Locale not supported by C library.\n",
207 "\tUsing the fallback 'C' locale.\n",
208 "[NbConvertApp] Loaded template latex_article.tplx\n",
209 "[NbConvertApp] Writing 41196 bytes to 04 - Custom Display Logic.tex\n",
210 "[NbConvertApp] Building PDF: ['pdflatex', '04 - Custom Display Logic.tex']\n"
211 ]
212 }
213 ],
214 "source": [
120 "source": [
215 "%%bash\n",
121 "%%bash\n",
216 "ipython nbconvert --to=latex '04 - Custom Display Logic.ipynb' --post=pdf"
122 "ipython nbconvert --to=latex 'Index.ipynb' --post=pdf"
217 ]
123 ]
218 },
124 },
219 {
125 {
220 "cell_type": "markdown",
126 "cell_type": "markdown",
221 "metadata": {},
127 "metadata": {},
222 "source": [
128 "source": [
223 "Have a look at `04 - Custom Display Logic.pdf`, toward the end, where we compared `display()` vs `display_html()` and returning the object.\n",
129 "## Custom templates"
224 "See how the cell where we use `display_html` was not able to display the circle, whereas the two other ones were able to select one of the oher representation they know how to display."
225 ]
130 ]
226 },
131 },
227 {
132 {
228 "cell_type": "markdown",
133 "cell_type": "markdown",
229 "metadata": {},
134 "metadata": {},
230 "source": [
135 "source": [
231 "### Customizing template"
136 "Look at the first 20 lines of the `python` exporter"
232 ]
233 },
234 {
235 "cell_type": "markdown",
236 "metadata": {},
237 "source": [
238 "let's look at the first 20 lines of the `python` exporter"
239 ]
137 ]
240 },
138 },
241 {
139 {
242 "cell_type": "code",
140 "cell_type": "code",
243 "execution_count": 5,
141 "execution_count": null,
244 "metadata": {
142 "metadata": {
245 "collapsed": false
143 "collapsed": false
246 },
144 },
247 "outputs": [
145 "outputs": [],
248 {
249 "name": "stdout",
250 "output_type": "stream",
251 "text": [
252 "# 1. Implementing special display methods such as `_repr_html_`.\n",
253 "# 2. Registering a display function for a particular type.\n",
254 "# \n",
255 "# In this Notebook we show how both approaches work.\n",
256 "\n",
257 "# Before we get started, we will import the various display functions for displaying the different formats we will create.\n",
258 "\n",
259 "# In[54]:\n",
260 "\n",
261 "from IPython.display import display\n",
262 "from IPython.display import (\n",
263 " display_html, display_jpeg, display_png,\n",
264 " display_javascript, display_svg, display_latex\n",
265 ")\n",
266 "\n",
267 "\n",
268 "### Implementing special display methods\n",
269 "\n",
270 "# The main idea of the first approach is that you have to implement special display methods, one for each representation you want to use. Here is a list of the names of the special methods and the values they must return:\n",
271 "# \n"
272 ]
273 }
274 ],
275 "source": [
146 "source": [
276 "pyfile = !ipython nbconvert --to python '04 - Custom Display Logic.ipynb' --stdout\n",
147 "pyfile = !ipython nbconvert --to python 'Index.ipynb' --stdout\n",
277 "for l in pyfile[20:40]:\n",
148 "for l in pyfile[20:40]:\n",
278 " print l"
149 " print l"
279 ]
150 ]
@@ -282,26 +153,16
282 "cell_type": "markdown",
153 "cell_type": "markdown",
283 "metadata": {},
154 "metadata": {},
284 "source": [
155 "source": [
285 "We see that the non-code cell are exported to the file. To have a cleaner script, we will export only the code contained in the code cells.\n",
156 "From the code, you can see that non-code cells are also exported. If you want to change this behavior, you can use a custom template. The custom template inherits from the Python template and overwrites the markdown blocks so that they are empty."
286 "\n",
287 "To do so, we will inherit the python template, and overwrite the markdown blocks to be empty."
288 ]
157 ]
289 },
158 },
290 {
159 {
291 "cell_type": "code",
160 "cell_type": "code",
292 "execution_count": 6,
161 "execution_count": null,
293 "metadata": {
162 "metadata": {
294 "collapsed": false
163 "collapsed": false
295 },
164 },
296 "outputs": [
165 "outputs": [],
297 {
298 "name": "stdout",
299 "output_type": "stream",
300 "text": [
301 "Overwriting simplepython.tpl\n"
302 ]
303 }
304 ],
305 "source": [
166 "source": [
306 "%%writefile simplepython.tpl\n",
167 "%%writefile simplepython.tpl\n",
307 "{% extends 'python.tpl'%}\n",
168 "{% extends 'python.tpl'%}\n",
@@ -321,57 +182,13
321 },
182 },
322 {
183 {
323 "cell_type": "code",
184 "cell_type": "code",
324 "execution_count": 7,
185 "execution_count": null,
325 "metadata": {
186 "metadata": {
326 "collapsed": false
187 "collapsed": false
327 },
188 },
328 "outputs": [
189 "outputs": [],
329 {
330 "name": "stdout",
331 "output_type": "stream",
332 "text": [
333 "\n",
334 "# This was input cell with prompt number : 54\n",
335 "from IPython.display import display\n",
336 "from IPython.display import (\n",
337 " display_html, display_jpeg, display_png,\n",
338 " display_javascript, display_svg, display_latex\n",
339 ")\n",
340 "\n",
341 "\n",
342 "# This was input cell with prompt number : 55\n",
343 "get_ipython().magic(u'load soln/mycircle.py')\n",
344 "\n",
345 "\n",
346 "# This was input cell with prompt number : 56\n",
347 "class MyCircle(object):\n",
348 " \n",
349 " def _repr_html_(self):\n",
350 " return \"&#x25CB; (<b>html</b>)\"\n",
351 "\n",
352 " def _repr_svg_(self):\n",
353 " return \"\"\"<svg width='100px' height='100px'>\n",
354 " <circle cx=\"50\" cy=\"50\" r=\"20\" stroke=\"black\" stroke-width=\"1\" fill=\"blue\"/>\n",
355 " </svg>\"\"\"\n",
356 " \n",
357 " def _repr_latex_(self):\n",
358 " return r\"$\\bigcirc \\LaTeX$\"\n",
359 "\n",
360 " def _repr_javascript_(self):\n",
361 " return \"alert('I am a circle!');\"\n",
362 "\n",
363 "\n",
364 "# This was input cell with prompt number : 57\n",
365 "c = MyCircle()\n",
366 "\n",
367 "\n",
368 "# This was input cell with prompt number : 58\n",
369 "...\n"
370 ]
371 }
372 ],
373 "source": [
190 "source": [
374 "pyfile = !ipython nbconvert --to python '04 - Custom Display Logic.ipynb' --stdout --template=simplepython.tpl\n",
191 "pyfile = !ipython nbconvert --to python 'Index.ipynb' --stdout --template=simplepython.tpl\n",
375 "\n",
192 "\n",
376 "for l in pyfile[4:40]:\n",
193 "for l in pyfile[4:40]:\n",
377 " print l\n",
194 " print l\n",
@@ -382,7 +199,7
382 "cell_type": "markdown",
199 "cell_type": "markdown",
383 "metadata": {},
200 "metadata": {},
384 "source": [
201 "source": [
385 "I'll let you read Jinja manual for the exact syntax of the template."
202 "For details about the template syntax, refer to [Jinja's manual](http://jinja.pocoo.org/docs/dev/)."
386 ]
203 ]
387 },
204 },
388 {
205 {
@@ -396,22 +213,22
396 "cell_type": "markdown",
213 "cell_type": "markdown",
397 "metadata": {},
214 "metadata": {},
398 "source": [
215 "source": [
399 "Notebook fileformat support attaching arbitrary JSON metadata to each cell of a notebook. In this part we will use those metadata."
216 "The notebook file format supports attaching arbitrary JSON metadata to each cell. Here, as an exercise, you will use the metadata to tags cells."
400 ]
217 ]
401 },
218 },
402 {
219 {
403 "cell_type": "markdown",
220 "cell_type": "markdown",
404 "metadata": {},
221 "metadata": {},
405 "source": [
222 "source": [
406 "First you need to choose another notebook you want to convert to html, and tag some of the cell with metadata.\n",
223 "First you need to choose another notebook you want to convert to html, and tag some of the cell with metadata. You can refere to the file `soln/celldiff.js` as an example or follow the Javascript tutorial to figure out how do change cell metadata. Assuming you have a notebook with some of the cells tagged as `Easy`|`Medium`|`Hard`|`<None>`, the notebook can be converted specially using a custom template. Design your remplate in the cells provided below.\n",
407 "You can see the file `soln/celldiff.js` for a solution on how to tag, or follow the javascript tutorial to see how to do that. Use what we have written there to tag cells of some notebooks to `Easy`|`Medium`|`Hard`|`<None>`, and convert this notebook using your template."
224 "\n",
225 "The following, unorganized lines of code, may be of help:"
408 ]
226 ]
409 },
227 },
410 {
228 {
411 "cell_type": "markdown",
229 "cell_type": "markdown",
412 "metadata": {},
230 "metadata": {},
413 "source": [
231 "source": [
414 "you might need the following : \n",
415 "```\n",
232 "```\n",
416 "{% extends 'html_full.tpl'%}\n",
233 "{% extends 'html_full.tpl'%}\n",
417 "{% block any_cell %}\n",
234 "{% block any_cell %}\n",
@@ -420,16 +237,16
420 "<div style='background-color:orange'>\n",
237 "<div style='background-color:orange'>\n",
421 "```\n",
238 "```\n",
422 "\n",
239 "\n",
423 "`metadata` might not exist, be sure to :\n",
240 "If your key name under `cell.metadata.example.difficulty`, the following code would get the value of it:\n",
424 "\n",
241 "\n",
425 "`cell['metadata'].get('example',{}).get('difficulty','')`\n",
242 "`cell['metadata'].get('example',{}).get('difficulty','')`\n",
426 "\n",
243 "\n",
427 "tip: use `%%writefile` to edit the template in the notebook :-)"
244 "Tip: Use `%%writefile` to edit the template in the notebook."
428 ]
245 ]
429 },
246 },
430 {
247 {
431 "cell_type": "code",
248 "cell_type": "code",
432 "execution_count": 8,
249 "execution_count": null,
433 "metadata": {
250 "metadata": {
434 "collapsed": false
251 "collapsed": false
435 },
252 },
@@ -472,10 +289,7
472 "cell_type": "markdown",
289 "cell_type": "markdown",
473 "metadata": {},
290 "metadata": {},
474 "source": [
291 "source": [
475 "As of all of IPython nbconvert can be configured using profiles and passing the `--profile` flag. \n",
292 "IPython nbconvert can be configured using the default profile and by selecting a non-default a profile via `--profile` flag. Additionally, if a `config.py` file exist in current working directory, nbconvert will use that as config."
476 "Moreover if a `config.py` file exist in current working directory nbconvert will use that, or read the config file you give to it with the `--config=<file>` flag. \n",
477 "\n",
478 "In the end, if you are often running nbconvert on the sam project, `$ ipython nbconvert` should be enough to get you up and ready."
479 ]
293 ]
480 }
294 }
481 ],
295 ],
@@ -495,7 +309,7
495 "name": "python",
309 "name": "python",
496 "nbconvert_exporter": "python",
310 "nbconvert_exporter": "python",
497 "pygments_lexer": "ipython3",
311 "pygments_lexer": "ipython3",
498 "version": "3.4.2"
312 "version": "3.4.3"
499 }
313 }
500 },
314 },
501 "nbformat": 4,
315 "nbformat": 4,
@@ -16,32 +16,11
16 },
16 },
17 {
17 {
18 "cell_type": "code",
18 "cell_type": "code",
19 "execution_count": 7,
19 "execution_count": null,
20 "metadata": {
20 "metadata": {
21 "collapsed": false
21 "collapsed": false
22 },
22 },
23 "outputs": [
23 "outputs": [],
24 {
25 "data": {
26 "application/javascript": [
27 "\n",
28 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
29 " help : 'run cell',\n",
30 " help_index : 'zz',\n",
31 " handler : function (event) {\n",
32 " IPython.notebook.execute_cell();\n",
33 " return false;\n",
34 " }}\n",
35 ");"
36 ],