##// END OF EJS Templates
Remove Equation References/Numbering, Fix Bugs...
Aron Ahmadia -
Show More
@@ -1,212 +1,215 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // Cell
9 // Cell
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 var utils = IPython.utils;
14 var utils = IPython.utils;
15
15
16
16
17 var Cell = function () {
17 var Cell = function () {
18 this.placeholder = this.placeholder || '';
18 this.placeholder = this.placeholder || '';
19 this.read_only = false;
19 this.read_only = false;
20 this.selected = false;
20 this.selected = false;
21 this.element = null;
21 this.element = null;
22 this.metadata = {};
22 this.metadata = {};
23 // load this from metadata later ?
23 // load this from metadata later ?
24 this.user_highlight == 'auto';
24 this.user_highlight == 'auto';
25 this.create_element();
25 this.create_element();
26 if (this.element !== null) {
26 if (this.element !== null) {
27 this.element.data("cell", this);
27 this.element.data("cell", this);
28 this.bind_events();
28 this.bind_events();
29 }
29 }
30 this.cell_id = utils.uuid();
30 this.cell_id = utils.uuid();
31 };
31 };
32
32
33
33
34 // Subclasses must implement create_element.
34 // Subclasses must implement create_element.
35 Cell.prototype.create_element = function () {};
35 Cell.prototype.create_element = function () {};
36
36
37
37
38 Cell.prototype.bind_events = function () {
38 Cell.prototype.bind_events = function () {
39 var that = this;
39 var that = this;
40 // We trigger events so that Cell doesn't have to depend on Notebook.
40 // We trigger events so that Cell doesn't have to depend on Notebook.
41 that.element.click(function (event) {
41 that.element.click(function (event) {
42 if (that.selected === false) {
42 if (that.selected === false) {
43 $([IPython.events]).trigger('select.Cell', {'cell':that});
43 $([IPython.events]).trigger('select.Cell', {'cell':that});
44 }
44 }
45 });
45 });
46 that.element.focusin(function (event) {
46 that.element.focusin(function (event) {
47 if (that.selected === false) {
47 if (that.selected === false) {
48 $([IPython.events]).trigger('select.Cell', {'cell':that});
48 $([IPython.events]).trigger('select.Cell', {'cell':that});
49 }
49 }
50 });
50 });
51 };
51 };
52
52
53 // prototype typeset method does nothing, see TextCell typeset
54 Cell.prototype.typeset = function () {
55 };
53
56
54 Cell.prototype.select = function () {
57 Cell.prototype.select = function () {
55 this.element.addClass('ui-widget-content ui-corner-all');
58 this.element.addClass('ui-widget-content ui-corner-all');
56 this.selected = true;
59 this.selected = true;
57 };
60 };
58
61
59
62
60 Cell.prototype.unselect = function () {
63 Cell.prototype.unselect = function () {
61 this.element.removeClass('ui-widget-content ui-corner-all');
64 this.element.removeClass('ui-widget-content ui-corner-all');
62 this.selected = false;
65 this.selected = false;
63 };
66 };
64
67
65
68
66 Cell.prototype.get_text = function () {
69 Cell.prototype.get_text = function () {
67 };
70 };
68
71
69
72
70 Cell.prototype.set_text = function (text) {
73 Cell.prototype.set_text = function (text) {
71 };
74 };
72
75
73
76
74 Cell.prototype.refresh = function () {
77 Cell.prototype.refresh = function () {
75 this.code_mirror.refresh();
78 this.code_mirror.refresh();
76 };
79 };
77
80
78
81
79 Cell.prototype.edit = function () {
82 Cell.prototype.edit = function () {
80 };
83 };
81
84
82
85
83 Cell.prototype.render = function () {
86 Cell.prototype.render = function () {
84 };
87 };
85
88
86
89
87 Cell.prototype.toJSON = function () {
90 Cell.prototype.toJSON = function () {
88 var data = {};
91 var data = {};
89 data.metadata = this.metadata;
92 data.metadata = this.metadata;
90 return data;
93 return data;
91 };
94 };
92
95
93
96
94 Cell.prototype.fromJSON = function (data) {
97 Cell.prototype.fromJSON = function (data) {
95 if (data.metadata !== undefined) {
98 if (data.metadata !== undefined) {
96 this.metadata = data.metadata;
99 this.metadata = data.metadata;
97 }
100 }
98 };
101 };
99
102
100
103
101 Cell.prototype.is_splittable = function () {
104 Cell.prototype.is_splittable = function () {
102 return true;
105 return true;
103 };
106 };
104
107
105
108
106 Cell.prototype.get_pre_cursor = function () {
109 Cell.prototype.get_pre_cursor = function () {
107 var cursor = this.code_mirror.getCursor();
110 var cursor = this.code_mirror.getCursor();
108 var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
111 var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
109 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
112 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
110 return text;
113 return text;
111 }
114 }
112
115
113
116
114 Cell.prototype.get_post_cursor = function () {
117 Cell.prototype.get_post_cursor = function () {
115 var cursor = this.code_mirror.getCursor();
118 var cursor = this.code_mirror.getCursor();
116 var last_line_num = this.code_mirror.lineCount()-1;
119 var last_line_num = this.code_mirror.lineCount()-1;
117 var last_line_len = this.code_mirror.getLine(last_line_num).length;
120 var last_line_len = this.code_mirror.getLine(last_line_num).length;
118 var end = {line:last_line_num, ch:last_line_len}
121 var end = {line:last_line_num, ch:last_line_len}
119 var text = this.code_mirror.getRange(cursor, end);
122 var text = this.code_mirror.getRange(cursor, end);
120 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
123 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
121 return text;
124 return text;
122 };
125 };
123
126
124
127
125 Cell.prototype.grow = function(element) {
128 Cell.prototype.grow = function(element) {
126 // Grow the cell by hand. This is used upon reloading from JSON, when the
129 // Grow the cell by hand. This is used upon reloading from JSON, when the
127 // autogrow handler is not called.
130 // autogrow handler is not called.
128 var dom = element.get(0);
131 var dom = element.get(0);
129 var lines_count = 0;
132 var lines_count = 0;
130 // modified split rule from
133 // modified split rule from
131 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
134 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
132 var lines = dom.value.split(/\r|\r\n|\n/);
135 var lines = dom.value.split(/\r|\r\n|\n/);
133 lines_count = lines.length;
136 lines_count = lines.length;
134 if (lines_count >= 1) {
137 if (lines_count >= 1) {
135 dom.rows = lines_count;
138 dom.rows = lines_count;
136 } else {
139 } else {
137 dom.rows = 1;
140 dom.rows = 1;
138 }
141 }
139 };
142 };
140
143
141
144
142 Cell.prototype.toggle_line_numbers = function () {
145 Cell.prototype.toggle_line_numbers = function () {
143 if (this.code_mirror.getOption('lineNumbers') == false) {
146 if (this.code_mirror.getOption('lineNumbers') == false) {
144 this.code_mirror.setOption('lineNumbers', true);
147 this.code_mirror.setOption('lineNumbers', true);
145 } else {
148 } else {
146 this.code_mirror.setOption('lineNumbers', false);
149 this.code_mirror.setOption('lineNumbers', false);
147 }
150 }
148 this.code_mirror.refresh();
151 this.code_mirror.refresh();
149 };
152 };
150
153
151 Cell.prototype.force_highlight = function(mode) {
154 Cell.prototype.force_highlight = function(mode) {
152 this.user_highlight = mode;
155 this.user_highlight = mode;
153 this.auto_highlight();
156 this.auto_highlight();
154 };
157 };
155
158
156 Cell.prototype._auto_highlight = function (modes) {
159 Cell.prototype._auto_highlight = function (modes) {
157 //Here we handle manually selected modes
160 //Here we handle manually selected modes
158 if( this.user_highlight != undefined && this.user_highlight != 'auto' )
161 if( this.user_highlight != undefined && this.user_highlight != 'auto' )
159 {
162 {
160 var mode = this.user_highlight;
163 var mode = this.user_highlight;
161 CodeMirror.autoLoadMode(this.code_mirror, mode);
164 CodeMirror.autoLoadMode(this.code_mirror, mode);
162 this.code_mirror.setOption('mode', mode);
165 this.code_mirror.setOption('mode', mode);
163 return;
166 return;
164 }
167 }
165 var first_line = this.code_mirror.getLine(0);
168 var first_line = this.code_mirror.getLine(0);
166 // loop on every pairs
169 // loop on every pairs
167 for( var mode in modes) {
170 for( var mode in modes) {
168 var regs = modes[mode]['reg'];
171 var regs = modes[mode]['reg'];
169 // only one key every time but regexp can't be keys...
172 // only one key every time but regexp can't be keys...
170 for(var reg in regs ) {
173 for(var reg in regs ) {
171 // here we handle non magic_modes
174 // here we handle non magic_modes
172 if(first_line.match(regs[reg]) != null) {
175 if(first_line.match(regs[reg]) != null) {
173 if (mode.search('magic_') != 0) {
176 if (mode.search('magic_') != 0) {
174 this.code_mirror.setOption('mode',mode);
177 this.code_mirror.setOption('mode',mode);
175 CodeMirror.autoLoadMode(this.code_mirror, mode);
178 CodeMirror.autoLoadMode(this.code_mirror, mode);
176 return;
179 return;
177 }
180 }
178 var open = modes[mode]['open']|| "%%";
181 var open = modes[mode]['open']|| "%%";
179 var close = modes[mode]['close']|| "%%end";
182 var close = modes[mode]['close']|| "%%end";
180 var mmode = mode;
183 var mmode = mode;
181 mode = mmode.substr(6);
184 mode = mmode.substr(6);
182 CodeMirror.autoLoadMode(this.code_mirror, mode);
185 CodeMirror.autoLoadMode(this.code_mirror, mode);
183 // create on the fly a mode that swhitch between
186 // create on the fly a mode that swhitch between
184 // plain/text and smth else otherwise `%%` is
187 // plain/text and smth else otherwise `%%` is
185 // source of some highlight issues.
188 // source of some highlight issues.
186 // we use patchedGetMode to circumvent a bug in CM
189 // we use patchedGetMode to circumvent a bug in CM
187 CodeMirror.defineMode(mmode , function(config) {
190 CodeMirror.defineMode(mmode , function(config) {
188 return CodeMirror.multiplexingMode(
191 return CodeMirror.multiplexingMode(
189 CodeMirror.patchedGetMode(config, 'text/plain'),
192 CodeMirror.patchedGetMode(config, 'text/plain'),
190 // always set someting on close
193 // always set someting on close
191 {open: open, close: close,
194 {open: open, close: close,
192 mode: CodeMirror.patchedGetMode(config, mode),
195 mode: CodeMirror.patchedGetMode(config, mode),
193 delimStyle: "delimit"
196 delimStyle: "delimit"
194 }
197 }
195 );
198 );
196 });
199 });
197 this.code_mirror.setOption('mode', mmode);
200 this.code_mirror.setOption('mode', mmode);
198 return;
201 return;
199 }
202 }
200 }
203 }
201 }
204 }
202 // fallback on default (python)
205 // fallback on default (python)
203 var default_mode = this.default_mode || 'text/plain';
206 var default_mode = this.default_mode || 'text/plain';
204 this.code_mirror.setOption('mode', default_mode);
207 this.code_mirror.setOption('mode', default_mode);
205 };
208 };
206
209
207 IPython.Cell = Cell;
210 IPython.Cell = Cell;
208
211
209 return IPython;
212 return IPython;
210
213
211 }(IPython));
214 }(IPython));
212
215
@@ -1,237 +1,229 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2012 The IPython Development Team
2 // Copyright (C) 2008-2012 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // MathJax utility functions
9 // MathJax utility functions
10 //============================================================================
10 //============================================================================
11
11
12 IPython.namespace('IPython.mathjaxutils');
12 IPython.namespace('IPython.mathjaxutils');
13
13
14 IPython.mathjaxutils = (function (IPython) {
14 IPython.mathjaxutils = (function (IPython) {
15
15
16 var init = function () {
16 var init = function () {
17 if (window.MathJax) {
17 if (window.MathJax) {
18 // MathJax loaded
18 // MathJax loaded
19 } else if (window.mathjax_url != "") {
19 } else if (window.mathjax_url != "") {
20 // Don't have MathJax, but should. Show dialog.
20 // Don't have MathJax, but should. Show dialog.
21 var dialog = $('<div></div>')
21 var dialog = $('<div></div>')
22 .append(
22 .append(
23 $("<p></p>").addClass('dialog').html(
23 $("<p></p>").addClass('dialog').html(
24 "Math/LaTeX rendering will be disabled."
24 "Math/LaTeX rendering will be disabled."
25 )
25 )
26 ).append(
26 ).append(
27 $("<p></p>").addClass('dialog').html(
27 $("<p></p>").addClass('dialog').html(
28 "If you have administrative access to the notebook server and" +
28 "If you have administrative access to the notebook server and" +
29 " a working internet connection, you can install a local copy" +
29 " a working internet connection, you can install a local copy" +
30 " of MathJax for offline use with the following command on the server" +
30 " of MathJax for offline use with the following command on the server" +
31 " at a Python or IPython prompt:"
31 " at a Python or IPython prompt:"
32 )
32 )
33 ).append(
33 ).append(
34 $("<pre></pre>").addClass('dialog').html(
34 $("<pre></pre>").addClass('dialog').html(
35 ">>> from IPython.external import mathjax; mathjax.install_mathjax()"
35 ">>> from IPython.external import mathjax; mathjax.install_mathjax()"
36 )
36 )
37 ).append(
37 ).append(
38 $("<p></p>").addClass('dialog').html(
38 $("<p></p>").addClass('dialog').html(
39 "This will try to install MathJax into the IPython source directory."
39 "This will try to install MathJax into the IPython source directory."
40 )
40 )
41 ).append(
41 ).append(
42 $("<p></p>").addClass('dialog').html(
42 $("<p></p>").addClass('dialog').html(
43 "If IPython is installed to a location that requires" +
43 "If IPython is installed to a location that requires" +
44 " administrative privileges to write, you will need to make this call as" +
44 " administrative privileges to write, you will need to make this call as" +
45 " an administrator, via 'sudo'."
45 " an administrator, via 'sudo'."
46 )
46 )
47 ).append(
47 ).append(
48 $("<p></p>").addClass('dialog').html(
48 $("<p></p>").addClass('dialog').html(
49 "When you start the notebook server, you can instruct it to disable MathJax support altogether:"
49 "When you start the notebook server, you can instruct it to disable MathJax support altogether:"
50 )
50 )
51 ).append(
51 ).append(
52 $("<pre></pre>").addClass('dialog').html(
52 $("<pre></pre>").addClass('dialog').html(
53 "$ ipython notebook --no-mathjax"
53 "$ ipython notebook --no-mathjax"
54 )
54 )
55 ).append(
55 ).append(
56 $("<p></p>").addClass('dialog').html(
56 $("<p></p>").addClass('dialog').html(
57 "which will prevent this dialog from appearing."
57 "which will prevent this dialog from appearing."
58 )
58 )
59 ).dialog({
59 ).dialog({
60 title: "Failed to retrieve MathJax from '" + window.mathjax_url + "'",
60 title: "Failed to retrieve MathJax from '" + window.mathjax_url + "'",
61 width: "70%",
61 width: "70%",
62 modal: true,
62 modal: true,
63 })
63 })
64 } else {
64 } else {
65 // No MathJax, but none expected. No dialog.
65 // No MathJax, but none expected. No dialog.
66 };
66 };
67 };
67 };
68
68
69 // Some magic for deferring mathematical expressions to MathJax
69 // Some magic for deferring mathematical expressions to MathJax
70 // by hiding them from the Markdown parser.
70 // by hiding them from the Markdown parser.
71 // Some of the code here is adapted with permission from Davide Cervone
71 // Some of the code here is adapted with permission from Davide Cervone
72 // under the terms of the Apache2 license governing the MathJax project.
72 // under the terms of the Apache2 license governing the MathJax project.
73 // Other minor modifications are also due to StackExchange and are used with
73 // Other minor modifications are also due to StackExchange and are used with
74 // permission.
74 // permission.
75
75
76 var inline = "$"; // the inline math delimiter
76 var inline = "$"; // the inline math delimiter
77 var blocks, start, end, last, braces; // used in searching for math
77 var blocks, start, end, last, braces; // used in searching for math
78 var math; // stores math until pagedown (Markdown parser) is done
78 var math; // stores math until pagedown (Markdown parser) is done
79 var HUB = MathJax.Hub;
80
79
81 // MATHSPLIT contains the pattern for math delimiters and special symbols
80 // MATHSPLIT contains the pattern for math delimiters and special symbols
82 // needed for searching for math in the text input.
81 // needed for searching for math in the text input.
83 var MATHSPLIT = /(\$\$?|\\(?:begin|end)\{[a-z]*\*?\}|\\[\\{}$]|[{}]|(?:\n\s*)+|@@\d+@@)/i;
82 var MATHSPLIT = /(\$\$?|\\(?:begin|end)\{[a-z]*\*?\}|\\[\\{}$]|[{}]|(?:\n\s*)+|@@\d+@@)/i;
84
83
85 // The math is in blocks i through j, so
84 // The math is in blocks i through j, so
86 // collect it into one block and clear the others.
85 // collect it into one block and clear the others.
87 // Replace &, <, and > by named entities.
86 // Replace &, <, and > by named entities.
88 // For IE, put <br> at the ends of comments since IE removes \n.
87 // For IE, put <br> at the ends of comments since IE removes \n.
89 // Clear the current math positions and store the index of the
88 // Clear the current math positions and store the index of the
90 // math, then push the math string onto the storage array.
89 // math, then push the math string onto the storage array.
91 // The preProcess function is called on all blocks if it has been passed in
90 // The preProcess function is called on all blocks if it has been passed in
92 var process_math = function (i, j, pre_process) {
91 var process_math = function (i, j, pre_process) {
92 var HUB = MathJax.Hub;
93 var block = blocks.slice(i, j + 1).join("").replace(/&/g, "&amp;") // use HTML entity for &
93 var block = blocks.slice(i, j + 1).join("").replace(/&/g, "&amp;") // use HTML entity for &
94 .replace(/</g, "&lt;") // use HTML entity for <
94 .replace(/</g, "&lt;") // use HTML entity for <
95 .replace(/>/g, "&gt;") // use HTML entity for >
95 .replace(/>/g, "&gt;") // use HTML entity for >
96 ;
96 ;
97 if (HUB.Browser.isMSIE) {
97 if (HUB.Browser.isMSIE) {
98 block = block.replace(/(%[^\n]*)\n/g, "$1<br/>\n")
98 block = block.replace(/(%[^\n]*)\n/g, "$1<br/>\n")
99 }
99 }
100 while (j > i) {
100 while (j > i) {
101 blocks[j] = "";
101 blocks[j] = "";
102 j--;
102 j--;
103 }
103 }
104 blocks[i] = "@@" + math.length + "@@"; // replace the current block text with a unique tag to find later
104 blocks[i] = "@@" + math.length + "@@"; // replace the current block text with a unique tag to find later
105 if (pre_process)
105 if (pre_process)
106 block = pre_process(block);
106 block = pre_process(block);
107 math.push(block);
107 math.push(block);
108 start = end = last = null;
108 start = end = last = null;
109 }
109 }
110
110
111 // Break up the text into its component parts and search
111 // Break up the text into its component parts and search
112 // through them for math delimiters, braces, linebreaks, etc.
112 // through them for math delimiters, braces, linebreaks, etc.
113 // Math delimiters must match and braces must balance.
113 // Math delimiters must match and braces must balance.
114 // Don't allow math to pass through a double linebreak
114 // Don't allow math to pass through a double linebreak
115 // (which will be a paragraph).
115 // (which will be a paragraph).
116 //
116 //
117 var remove_math = function (text) {
117 var remove_math = function (text) {
118 if (!window.MathJax) {
119 return text;
120 }
121
118 start = end = last = null; // for tracking math delimiters
122 start = end = last = null; // for tracking math delimiters
119 math = []; // stores math strings for later
123 math = []; // stores math strings for later
120
124
121 // Except for extreme edge cases, this should catch precisely those pieces of the markdown
125 // Except for extreme edge cases, this should catch precisely those pieces of the markdown
122 // source that will later be turned into code spans. While MathJax will not TeXify code spans,
126 // source that will later be turned into code spans. While MathJax will not TeXify code spans,
123 // we still have to consider them at this point; the following issue has happened several times:
127 // we still have to consider them at this point; the following issue has happened several times:
124 //
128 //
125 // `$foo` and `$bar` are varibales. --> <code>$foo ` and `$bar</code> are variables.
129 // `$foo` and `$bar` are varibales. --> <code>$foo ` and `$bar</code> are variables.
126
130
127 var hasCodeSpans = /`/.test(text),
131 var hasCodeSpans = /`/.test(text),
128 de_tilde;
132 de_tilde;
129 if (hasCodeSpans) {
133 if (hasCodeSpans) {
130 text = text.replace(/~/g, "~T").replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, function (wholematch) {
134 text = text.replace(/~/g, "~T").replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, function (wholematch) {
131 return wholematch.replace(/\$/g, "~D");
135 return wholematch.replace(/\$/g, "~D");
132 });
136 });
133 de_tilde = function (text) { return text.replace(/~([TD])/g, function (wholematch, character) { return { T: "~", D: "$" }[character]; }) };
137 de_tilde = function (text) { return text.replace(/~([TD])/g, function (wholematch, character) { return { T: "~", D: "$" }[character]; }) };
134 } else {
138 } else {
135 de_tilde = function (text) { return text; };
139 de_tilde = function (text) { return text; };
136 }
140 }
137
141
138 blocks = IPython.utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT);
142 blocks = IPython.utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT);
139
143
140 for (var i = 1, m = blocks.length; i < m; i += 2) {
144 for (var i = 1, m = blocks.length; i < m; i += 2) {
141 var block = blocks[i];
145 var block = blocks[i];
142 if (block.charAt(0) === "@") {
146 if (block.charAt(0) === "@") {
143 //
147 //
144 // Things that look like our math markers will get
148 // Things that look like our math markers will get
145 // stored and then retrieved along with the math.
149 // stored and then retrieved along with the math.
146 //
150 //
147 blocks[i] = "@@" + math.length + "@@";
151 blocks[i] = "@@" + math.length + "@@";
148 math.push(block);
152 math.push(block);
149 }
153 }
150 else if (start) {
154 else if (start) {
151 //
155 //
152 // If we are in math, look for the end delimiter,
156 // If we are in math, look for the end delimiter,
153 // but don't go past double line breaks, and
157 // but don't go past double line breaks, and
154 // and balance braces within the math.
158 // and balance braces within the math.
155 //
159 //
156 if (block === end) {
160 if (block === end) {
157 if (braces) {
161 if (braces) {
158 last = i
162 last = i
159 }
163 }
160 else {
164 else {
161 process_math(start, i, de_tilde)
165 process_math(start, i, de_tilde)
162 }
166 }
163 }
167 }
164 else if (block.match(/\n.*\n/)) {
168 else if (block.match(/\n.*\n/)) {
165 if (last) {
169 if (last) {
166 i = last;
170 i = last;
167 process_math(start, i, de_tilde)
171 process_math(start, i, de_tilde)
168 }
172 }
169 start = end = last = null;
173 start = end = last = null;
170 braces = 0;
174 braces = 0;
171 }
175 }
172 else if (block === "{") {
176 else if (block === "{") {
173 braces++
177 braces++
174 }
178 }
175 else if (block === "}" && braces) {
179 else if (block === "}" && braces) {
176 braces--
180 braces--
177 }
181 }
178 }
182 }
179 else {
183 else {
180 //
184 //
181 // Look for math start delimiters and when
185 // Look for math start delimiters and when
182 // found, set up the end delimiter.
186 // found, set up the end delimiter.
183 //
187 //
184 if (block === inline || block === "$$") {
188 if (block === inline || block === "$$") {
185 start = i;
189 start = i;
186 end = block;
190 end = block;
187 braces = 0;
191 braces = 0;
188 }
192 }
189 else if (block.substr(1, 5) === "begin") {
193 else if (block.substr(1, 5) === "begin") {
190 start = i;
194 start = i;
191 end = "\\end" + block.substr(6);
195 end = "\\end" + block.substr(6);
192 braces = 0;
196 braces = 0;
193 }
197 }
194 }
198 }
195 }
199 }
196 if (last) {
200 if (last) {
197 process_math(start, last, de_tilde)
201 process_math(start, last, de_tilde)
198 }
202 }
199 return de_tilde(blocks.join(""));
203 return de_tilde(blocks.join(""));
200 }
204 }
201
205
202 //
206 //
203 // Put back the math strings that were saved,
207 // Put back the math strings that were saved,
204 // and clear the math array (no need to keep it around).
208 // and clear the math array (no need to keep it around).
205 //
209 //
206 var replace_math = function (text) {
210 var replace_math = function (text) {
211 if (!window.MathJax) {
212 return text;
213 }
214
207 text = text.replace(/@@(\d+)@@/g, function (match, n) {
215 text = text.replace(/@@(\d+)@@/g, function (match, n) {
208 return math[n]
216 return math[n]
209 });
217 });
210 math = null;
218 math = null;
211 return text;
219 return text;
212 }
220 }
213
221
214 var queue_render = function () {
215 // see https://groups.google.com/forum/?fromgroups=#!topic/mathjax-users/cpwy5eCH1ZQ
216 var jax = MathJax.Hub.getAllJax();
217
218 MathJax.Hub.Queue(
219 function () {
220 if (MathJax.InputJax.TeX.resetEquationNumbers) {
221 MathJax.InputJax.TeX.resetEquationNumbers();
222 }
223 },
224 ["PreProcess",MathJax.Hub],
225 ["Reprocess",MathJax.Hub]
226 );
227 }
228
229 return {
222 return {
230 init : init,
223 init : init,
231 process_math : process_math,
224 process_math : process_math,
232 remove_math : remove_math,
225 remove_math : remove_math,
233 replace_math : replace_math,
226 replace_math : replace_math
234 queue_render : queue_render
235 };
227 };
236
228
237 }(IPython)); No newline at end of file
229 }(IPython));
@@ -1,420 +1,428 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2012 The IPython Development Team
2 // Copyright (C) 2008-2012 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // TextCell
9 // TextCell
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 // TextCell base class
14 // TextCell base class
15 var key = IPython.utils.keycodes;
15 var key = IPython.utils.keycodes;
16
16
17 var TextCell = function () {
17 var TextCell = function () {
18 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
18 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
19 IPython.Cell.apply(this, arguments);
19 IPython.Cell.apply(this, arguments);
20 this.rendered = false;
20 this.rendered = false;
21 this.cell_type = this.cell_type || 'text';
21 this.cell_type = this.cell_type || 'text';
22 };
22 };
23
23
24
24
25 TextCell.prototype = new IPython.Cell();
25 TextCell.prototype = new IPython.Cell();
26
26
27
27
28 TextCell.prototype.create_element = function () {
28 TextCell.prototype.create_element = function () {
29 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
29 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
30 cell.attr('tabindex','2');
30 cell.attr('tabindex','2');
31 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
31 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
32 this.code_mirror = CodeMirror(input_area.get(0), {
32 this.code_mirror = CodeMirror(input_area.get(0), {
33 indentUnit : 4,
33 indentUnit : 4,
34 mode: this.code_mirror_mode,
34 mode: this.code_mirror_mode,
35 theme: 'default',
35 theme: 'default',
36 value: this.placeholder,
36 value: this.placeholder,
37 readOnly: this.read_only,
37 readOnly: this.read_only,
38 lineWrapping : true,
38 lineWrapping : true,
39 extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"},
39 extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"},
40 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
40 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
41 });
41 });
42 this.cell_id = IPython.utils.uuid();
42 // The tabindex=-1 makes this div focusable.
43 // The tabindex=-1 makes this div focusable.
44 // id is a unique cell_id necessary for updating MathJax intelligently
43 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
45 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
44 addClass('rendered_html').attr('tabindex','-1');
46 addClass('rendered_html').attr('tabindex','-1').attr('id',this.cell_id);
45 cell.append(input_area).append(render_area);
47 cell.append(input_area).append(render_area);
46 this.element = cell;
48 this.element = cell;
47 };
49 };
48
50
49
51
50 TextCell.prototype.bind_events = function () {
52 TextCell.prototype.bind_events = function () {
51 IPython.Cell.prototype.bind_events.apply(this);
53 IPython.Cell.prototype.bind_events.apply(this);
52 var that = this;
54 var that = this;
53 this.element.keydown(function (event) {
55 this.element.keydown(function (event) {
54 if (event.which === 13 && !event.shiftKey) {
56 if (event.which === 13 && !event.shiftKey) {
55 if (that.rendered) {
57 if (that.rendered) {
56 that.edit();
58 that.edit();
57 return false;
59 return false;
58 };
60 };
59 };
61 };
60 });
62 });
61 this.element.dblclick(function () {
63 this.element.dblclick(function () {
62 that.edit();
64 that.edit();
63 });
65 });
64 };
66 };
65
67
66
68
67 TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
69 TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
68 // This method gets called in CodeMirror's onKeyDown/onKeyPress
70 // This method gets called in CodeMirror's onKeyDown/onKeyPress
69 // handlers and is used to provide custom key handling. Its return
71 // handlers and is used to provide custom key handling. Its return
70 // value is used to determine if CodeMirror should ignore the event:
72 // value is used to determine if CodeMirror should ignore the event:
71 // true = ignore, false = don't ignore.
73 // true = ignore, false = don't ignore.
72
74
73 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
75 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
74 // Always ignore shift-enter in CodeMirror as we handle it.
76 // Always ignore shift-enter in CodeMirror as we handle it.
75 return true;
77 return true;
76 }
78 }
77 return false;
79 return false;
78 };
80 };
79
81
82 TextCell.prototype.typeset = function () {
83 if (window.MathJax){
84 var cell_math = document.getElementById(this.cell_id);
85 MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]);
86 }
87 };
88
80
89
81 TextCell.prototype.select = function () {
90 TextCell.prototype.select = function () {
82 IPython.Cell.prototype.select.apply(this);
91 IPython.Cell.prototype.select.apply(this);
83 var output = this.element.find("div.text_cell_render");
92 var output = this.element.find("div.text_cell_render");
84 output.trigger('focus');
93 output.trigger('focus');
85 };
94 };
86
95
87
96
88 TextCell.prototype.unselect = function() {
97 TextCell.prototype.unselect = function() {
89 // render on selection of another cell
98 // render on selection of another cell
90 this.render();
99 this.render();
91 IPython.Cell.prototype.unselect.apply(this);
100 IPython.Cell.prototype.unselect.apply(this);
92 };
101 };
93
102
94
103
95 TextCell.prototype.edit = function () {
104 TextCell.prototype.edit = function () {
96 if ( this.read_only ) return;
105 if ( this.read_only ) return;
97 if (this.rendered === true) {
106 if (this.rendered === true) {
98 var text_cell = this.element;
107 var text_cell = this.element;
99 var output = text_cell.find("div.text_cell_render");
108 var output = text_cell.find("div.text_cell_render");
100 output.hide();
109 output.hide();
101 text_cell.find('div.text_cell_input').show();
110 text_cell.find('div.text_cell_input').show();
102 this.code_mirror.refresh();
111 this.code_mirror.refresh();
103 this.code_mirror.focus();
112 this.code_mirror.focus();
104 // We used to need an additional refresh() after the focus, but
113 // We used to need an additional refresh() after the focus, but
105 // it appears that this has been fixed in CM. This bug would show
114 // it appears that this has been fixed in CM. This bug would show
106 // up on FF when a newly loaded markdown cell was edited.
115 // up on FF when a newly loaded markdown cell was edited.
107 this.rendered = false;
116 this.rendered = false;
108 if (this.get_text() === this.placeholder) {
117 if (this.get_text() === this.placeholder) {
109 this.set_text('');
118 this.set_text('');
110 this.refresh();
119 this.refresh();
111 }
120 }
112 }
121 }
113 };
122 };
114
123
115
124
116 // Subclasses must define render.
125 // Subclasses must define render.
117 TextCell.prototype.render = function () {};
126 TextCell.prototype.render = function () {};
118
127
119
128
120 TextCell.prototype.get_text = function() {
129 TextCell.prototype.get_text = function() {
121 return this.code_mirror.getValue();
130 return this.code_mirror.getValue();
122 };
131 };
123
132
124
133
125 TextCell.prototype.set_text = function(text) {
134 TextCell.prototype.set_text = function(text) {
126 this.code_mirror.setValue(text);
135 this.code_mirror.setValue(text);
127 this.code_mirror.refresh();
136 this.code_mirror.refresh();
128 };
137 };
129
138
130
139
131 TextCell.prototype.get_rendered = function() {
140 TextCell.prototype.get_rendered = function() {
132 return this.element.find('div.text_cell_render').html();
141 return this.element.find('div.text_cell_render').html();
133 };
142 };
134
143
135
144
136 TextCell.prototype.set_rendered = function(text) {
145 TextCell.prototype.set_rendered = function(text) {
137 this.element.find('div.text_cell_render').html(text);
146 this.element.find('div.text_cell_render').html(text);
138 };
147 };
139
148
140
149
141 TextCell.prototype.at_top = function () {
150 TextCell.prototype.at_top = function () {
142 if (this.rendered) {
151 if (this.rendered) {
143 return true;
152 return true;
144 } else {
153 } else {
145 return false;
154 return false;
146 }
155 }
147 };
156 };
148
157
149
158
150 TextCell.prototype.at_bottom = function () {
159 TextCell.prototype.at_bottom = function () {
151 if (this.rendered) {
160 if (this.rendered) {
152 return true;
161 return true;
153 } else {
162 } else {
154 return false;
163 return false;
155 }
164 }
156 };
165 };
157
166
158
167
159 TextCell.prototype.fromJSON = function (data) {
168 TextCell.prototype.fromJSON = function (data) {
160 IPython.Cell.prototype.fromJSON.apply(this, arguments);
169 IPython.Cell.prototype.fromJSON.apply(this, arguments);
161 if (data.cell_type === this.cell_type) {
170 if (data.cell_type === this.cell_type) {
162 if (data.source !== undefined) {
171 if (data.source !== undefined) {
163 this.set_text(data.source);
172 this.set_text(data.source);
164 // make this value the starting point, so that we can only undo
173 // make this value the starting point, so that we can only undo
165 // to this state, instead of a blank cell
174 // to this state, instead of a blank cell
166 this.code_mirror.clearHistory();
175 this.code_mirror.clearHistory();
167 this.set_rendered(data.rendered || '');
176 this.set_rendered(data.rendered || '');
168 this.rendered = false;
177 this.rendered = false;
169 this.render();
178 this.render();
170 }
179 }
171 }
180 }
172 };
181 };
173
182
174
183
175 TextCell.prototype.toJSON = function () {
184 TextCell.prototype.toJSON = function () {
176 var data = IPython.Cell.prototype.toJSON.apply(this);
185 var data = IPython.Cell.prototype.toJSON.apply(this);
177 data.cell_type = this.cell_type;
186 data.cell_type = this.cell_type;
178 data.source = this.get_text();
187 data.source = this.get_text();
179 return data;
188 return data;
180 };
189 };
181
190
182
191
183 // HTMLCell
192 // HTMLCell
184
193
185 var HTMLCell = function () {
194 var HTMLCell = function () {
186 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
195 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
187 IPython.TextCell.apply(this, arguments);
196 IPython.TextCell.apply(this, arguments);
188 this.cell_type = 'html';
197 this.cell_type = 'html';
189 };
198 };
190
199
191
200
192 HTMLCell.prototype = new TextCell();
201 HTMLCell.prototype = new TextCell();
193
202
194
203
195 HTMLCell.prototype.render = function () {
204 HTMLCell.prototype.render = function () {
196 if (this.rendered === false) {
205 if (this.rendered === false) {
197 var text = this.get_text();
206 var text = this.get_text();
198 if (text === "") { text = this.placeholder; }
207 if (text === "") { text = this.placeholder; }
199 this.set_rendered(text);
208 this.set_rendered(text);
200 this.typeset();
209 this.typeset();
201 this.element.find('div.text_cell_input').hide();
210 this.element.find('div.text_cell_input').hide();
202 this.element.find("div.text_cell_render").show();
211 this.element.find("div.text_cell_render").show();
203 this.rendered = true;
212 this.rendered = true;
204 }
213 }
205 };
214 };
206
215
207
216
208 // MarkdownCell
217 // MarkdownCell
209
218
210 var MarkdownCell = function () {
219 var MarkdownCell = function () {
211 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
220 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
212 IPython.TextCell.apply(this, arguments);
221 IPython.TextCell.apply(this, arguments);
213 this.cell_type = 'markdown';
222 this.cell_type = 'markdown';
214 };
223 };
215
224
216
225
217 MarkdownCell.prototype = new TextCell();
226 MarkdownCell.prototype = new TextCell();
218
227
219
228
220 MarkdownCell.prototype.render = function () {
229 MarkdownCell.prototype.render = function () {
221 if (this.rendered === false) {
230 if (this.rendered === false) {
222 var text = this.get_text();
231 var text = this.get_text();
223 if (text === "") { text = this.placeholder; }
232 if (text === "") { text = this.placeholder; }
224 else {
233 else {
225 text = IPython.mathjaxutils.remove_math(text)
234 text = IPython.mathjaxutils.remove_math(text)
226 var html = IPython.markdown_converter.makeHtml(text);
235 var html = IPython.markdown_converter.makeHtml(text);
227 html = IPython.mathjaxutils.replace_math(html)
236 html = IPython.mathjaxutils.replace_math(html)
228 try {
237 try {
229 this.set_rendered(html);
238 this.set_rendered(html);
230 } catch (e) {
239 } catch (e) {
231 console.log("Error running Javascript in Markdown:");
240 console.log("Error running Javascript in Markdown:");
232 console.log(e);
241 console.log(e);
233 this.set_rendered($("<div/>").addClass("js-error").html(
242 this.set_rendered($("<div/>").addClass("js-error").html(
234 "Error rendering Markdown!<br/>" + e.toString())
243 "Error rendering Markdown!<br/>" + e.toString())
235 );
244 );
236 }
245 }
237 this.element.find('div.text_cell_input').hide();
246 this.element.find('div.text_cell_input').hide();
238 this.element.find("div.text_cell_render").show();
247 this.element.find("div.text_cell_render").show();
239 var code_snippets = this.element.find("pre > code");
248 var code_snippets = this.element.find("pre > code");
240 code_snippets.replaceWith(function () {
249 code_snippets.replaceWith(function () {
241 var code = $(this).html();
250 var code = $(this).html();
242 /* Substitute br for newlines and &nbsp; for spaces
251 /* Substitute br for newlines and &nbsp; for spaces
243 before highlighting, since prettify doesn't
252 before highlighting, since prettify doesn't
244 preserve those on all browsers */
253 preserve those on all browsers */
245 code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
254 code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
246 code = code.replace(/ /gm, '&nbsp;');
255 code = code.replace(/ /gm, '&nbsp;');
247 code = prettyPrintOne(code);
256 code = prettyPrintOne(code);
248
257
249 return '<code class="prettyprint">' + code + '</code>';
258 return '<code class="prettyprint">' + code + '</code>';
250 });
259 });
251
260 this.typeset()
252 IPython.mathjaxutils.queue_render()
253 }
261 }
254 this.rendered = true;
262 this.rendered = true;
255 }
263 }
256 };
264 };
257
265
258
266
259 // RawCell
267 // RawCell
260
268
261 var RawCell = function () {
269 var RawCell = function () {
262 this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
270 this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
263 this.code_mirror_mode = 'rst';
271 this.code_mirror_mode = 'rst';
264 IPython.TextCell.apply(this, arguments);
272 IPython.TextCell.apply(this, arguments);
265 this.cell_type = 'raw';
273 this.cell_type = 'raw';
266 var that = this
274 var that = this
267
275
268 this.element.focusout(
276 this.element.focusout(
269 function() { that.auto_highlight(); }
277 function() { that.auto_highlight(); }
270 );
278 );
271 };
279 };
272
280
273
281
274 RawCell.prototype = new TextCell();
282 RawCell.prototype = new TextCell();
275
283
276 RawCell.prototype.auto_highlight = function () {
284 RawCell.prototype.auto_highlight = function () {
277 this._auto_highlight(IPython.config.raw_cell_highlight);
285 this._auto_highlight(IPython.config.raw_cell_highlight);
278 };
286 };
279
287
280 RawCell.prototype.render = function () {
288 RawCell.prototype.render = function () {
281 this.rendered = true;
289 this.rendered = true;
282 this.edit();
290 this.edit();
283 };
291 };
284
292
285
293
286 RawCell.prototype.handle_codemirror_keyevent = function (editor, event) {
294 RawCell.prototype.handle_codemirror_keyevent = function (editor, event) {
287 // This method gets called in CodeMirror's onKeyDown/onKeyPress
295 // This method gets called in CodeMirror's onKeyDown/onKeyPress
288 // handlers and is used to provide custom key handling. Its return
296 // handlers and is used to provide custom key handling. Its return
289 // value is used to determine if CodeMirror should ignore the event:
297 // value is used to determine if CodeMirror should ignore the event:
290 // true = ignore, false = don't ignore.
298 // true = ignore, false = don't ignore.
291
299
292 var that = this;
300 var that = this;
293 if (event.which === key.UPARROW && event.type === 'keydown') {
301 if (event.which === key.UPARROW && event.type === 'keydown') {
294 // If we are not at the top, let CM handle the up arrow and
302 // If we are not at the top, let CM handle the up arrow and
295 // prevent the global keydown handler from handling it.
303 // prevent the global keydown handler from handling it.
296 if (!that.at_top()) {
304 if (!that.at_top()) {
297 event.stop();
305 event.stop();
298 return false;
306 return false;
299 } else {
307 } else {
300 return true;
308 return true;
301 };
309 };
302 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
310 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
303 // If we are not at the bottom, let CM handle the down arrow and
311 // If we are not at the bottom, let CM handle the down arrow and
304 // prevent the global keydown handler from handling it.
312 // prevent the global keydown handler from handling it.
305 if (!that.at_bottom()) {
313 if (!that.at_bottom()) {
306 event.stop();
314 event.stop();
307 return false;
315 return false;
308 } else {
316 } else {
309 return true;
317 return true;
310 };
318 };
311 };
319 };
312 return false;
320 return false;
313 };
321 };
314
322
315
323
316 RawCell.prototype.select = function () {
324 RawCell.prototype.select = function () {
317 IPython.Cell.prototype.select.apply(this);
325 IPython.Cell.prototype.select.apply(this);
318 this.code_mirror.refresh();
326 this.code_mirror.refresh();
319 this.code_mirror.focus();
327 this.code_mirror.focus();
320 };
328 };
321
329
322
330
323 RawCell.prototype.at_top = function () {
331 RawCell.prototype.at_top = function () {
324 var cursor = this.code_mirror.getCursor();
332 var cursor = this.code_mirror.getCursor();
325 if (cursor.line === 0 && cursor.ch === 0) {
333 if (cursor.line === 0 && cursor.ch === 0) {
326 return true;
334 return true;
327 } else {
335 } else {
328 return false;
336 return false;
329 }
337 }
330 };
338 };
331
339
332
340
333 RawCell.prototype.at_bottom = function () {
341 RawCell.prototype.at_bottom = function () {
334 var cursor = this.code_mirror.getCursor();
342 var cursor = this.code_mirror.getCursor();
335 if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
343 if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
336 return true;
344 return true;
337 } else {
345 } else {
338 return false;
346 return false;
339 }
347 }
340 };
348 };
341
349
342
350
343 // HTMLCell
351 // HTMLCell
344
352
345 var HeadingCell = function () {
353 var HeadingCell = function () {
346 this.placeholder = "Type Heading Here";
354 this.placeholder = "Type Heading Here";
347 IPython.TextCell.apply(this, arguments);
355 IPython.TextCell.apply(this, arguments);
348 this.cell_type = 'heading';
356 this.cell_type = 'heading';
349 this.level = 1;
357 this.level = 1;
350 };
358 };
351
359
352
360
353 HeadingCell.prototype = new TextCell();
361 HeadingCell.prototype = new TextCell();
354
362
355
363
356 HeadingCell.prototype.fromJSON = function (data) {
364 HeadingCell.prototype.fromJSON = function (data) {
357 if (data.level != undefined){
365 if (data.level != undefined){
358 this.level = data.level;
366 this.level = data.level;
359 }
367 }
360 IPython.TextCell.prototype.fromJSON.apply(this, arguments);
368 IPython.TextCell.prototype.fromJSON.apply(this, arguments);
361 };
369 };
362
370
363
371
364 HeadingCell.prototype.toJSON = function () {
372 HeadingCell.prototype.toJSON = function () {
365 var data = IPython.TextCell.prototype.toJSON.apply(this);
373 var data = IPython.TextCell.prototype.toJSON.apply(this);
366 data.level = this.get_level();
374 data.level = this.get_level();
367 return data;
375 return data;
368 };
376 };
369
377
370
378
371 HeadingCell.prototype.set_level = function (level) {
379 HeadingCell.prototype.set_level = function (level) {
372 this.level = level;
380 this.level = level;
373 if (this.rendered) {
381 if (this.rendered) {
374 this.rendered = false;
382 this.rendered = false;
375 this.render();
383 this.render();
376 };
384 };
377 };
385 };
378
386
379
387
380 HeadingCell.prototype.get_level = function () {
388 HeadingCell.prototype.get_level = function () {
381 return this.level;
389 return this.level;
382 };
390 };
383
391
384
392
385 HeadingCell.prototype.set_rendered = function (text) {
393 HeadingCell.prototype.set_rendered = function (text) {
386 var r = this.element.find("div.text_cell_render");
394 var r = this.element.find("div.text_cell_render");
387 r.empty();
395 r.empty();
388 r.append($('<h'+this.level+'/>').html(text));
396 r.append($('<h'+this.level+'/>').html(text));
389 };
397 };
390
398
391
399
392 HeadingCell.prototype.get_rendered = function () {
400 HeadingCell.prototype.get_rendered = function () {
393 var r = this.element.find("div.text_cell_render");
401 var r = this.element.find("div.text_cell_render");
394 return r.children().first().html();
402 return r.children().first().html();
395 };
403 };
396
404
397
405
398 HeadingCell.prototype.render = function () {
406 HeadingCell.prototype.render = function () {
399 if (this.rendered === false) {
407 if (this.rendered === false) {
400 var text = this.get_text();
408 var text = this.get_text();
401 if (text === "") { text = this.placeholder; }
409 if (text === "") { text = this.placeholder; }
402 this.set_rendered(text);
410 this.set_rendered(text);
403 this.typeset();
411 this.typeset();
404 this.element.find('div.text_cell_input').hide();
412 this.element.find('div.text_cell_input').hide();
405 this.element.find("div.text_cell_render").show();
413 this.element.find("div.text_cell_render").show();
406 this.rendered = true;
414 this.rendered = true;
407 };
415 };
408 };
416 };
409
417
410 IPython.TextCell = TextCell;
418 IPython.TextCell = TextCell;
411 IPython.HTMLCell = HTMLCell;
419 IPython.HTMLCell = HTMLCell;
412 IPython.MarkdownCell = MarkdownCell;
420 IPython.MarkdownCell = MarkdownCell;
413 IPython.RawCell = RawCell;
421 IPython.RawCell = RawCell;
414 IPython.HeadingCell = HeadingCell;
422 IPython.HeadingCell = HeadingCell;
415
423
416
424
417 return IPython;
425 return IPython;
418
426
419 }(IPython));
427 }(IPython));
420
428
@@ -1,241 +1,240 b''
1 {% extends page.html %}
1 {% extends page.html %}
2 {% block stylesheet %}
2 {% block stylesheet %}
3
3
4 {% if mathjax_url %}
4 {% if mathjax_url %}
5 <script type="text/x-mathjax-config">
5 <script type="text/x-mathjax-config">
6 MathJax.Hub.Config({
6 MathJax.Hub.Config({
7 TeX: { equationNumbers: { autoNumber: "AMS", useLabelIds: true } },
8 tex2jax: {
7 tex2jax: {
9 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
8 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
10 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
9 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
11 processEnvironments: true
10 processEnvironments: true
12 },
11 },
13 displayAlign: 'left', // Change this to 'center' to center equations.
12 displayAlign: 'left', // Change this to 'center' to center equations.
14 "HTML-CSS": {
13 "HTML-CSS": {
15 styles: {'.MathJax_Display': {"margin": 0}}
14 styles: {'.MathJax_Display': {"margin": 0}}
16 }
15 }
17 });
16 });
18 </script>
17 </script>
19
18
20 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
19 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML-full" charset="utf-8"></script>
21 {% end %}
20 {% end %}
22 <script type="text/javascript">
21 <script type="text/javascript">
23 // MathJax disabled, set as null to distingish from *missing* MathJax,
22 // MathJax disabled, set as null to distingish from *missing* MathJax,
24 // where it will be undefined, and should prompt a dialog later.
23 // where it will be undefined, and should prompt a dialog later.
25 window.mathjax_url = "{{mathjax_url}}";
24 window.mathjax_url = "{{mathjax_url}}";
26 </script>
25 </script>
27
26
28 <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}">
27 <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}">
29 <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}">
28 <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}">
30
29
31 <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/>
30 <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/>
32
31
33 <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" />
32 <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" />
34 <link rel="stylesheet" href="{{ static_url("css/tooltip.css") }}" type="text/css" />
33 <link rel="stylesheet" href="{{ static_url("css/tooltip.css") }}" type="text/css" />
35 <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" />
34 <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" />
36
35
37 <link rel="stylesheet" href="{{ static_url("css/printnotebook.css") }}" type="text/css" media="print"/>
36 <link rel="stylesheet" href="{{ static_url("css/printnotebook.css") }}" type="text/css" media="print"/>
38
37
39 {% end %}
38 {% end %}
40
39
41
40
42 {% block params %}
41 {% block params %}
43
42
44 data-project={{project}}
43 data-project={{project}}
45 data-base-project-url={{base_project_url}}
44 data-base-project-url={{base_project_url}}
46 data-base-kernel-url={{base_kernel_url}}
45 data-base-kernel-url={{base_kernel_url}}
47 data-read-only={{read_only and not logged_in}}
46 data-read-only={{read_only and not logged_in}}
48 data-notebook-id={{notebook_id}}
47 data-notebook-id={{notebook_id}}
49
48
50 {% end %}
49 {% end %}
51
50
52
51
53 {% block header %}
52 {% block header %}
54
53
55 <span id="save_widget">
54 <span id="save_widget">
56 <span id="notebook_name"></span>
55 <span id="notebook_name"></span>
57 <span id="save_status"></span>
56 <span id="save_status"></span>
58 </span>
57 </span>
59
58
60 {% end %}
59 {% end %}
61
60
62
61
63 {% block site %}
62 {% block site %}
64
63
65 <div id="menubar_container">
64 <div id="menubar_container">
66 <div id="menubar">
65 <div id="menubar">
67 <ul id="menus">
66 <ul id="menus">
68 <li><a href="#">File</a>
67 <li><a href="#">File</a>
69 <ul>
68 <ul>
70 <li id="new_notebook"><a href="#">New</a></li>
69 <li id="new_notebook"><a href="#">New</a></li>
71 <li id="open_notebook"><a href="#">Open...</a></li>
70 <li id="open_notebook"><a href="#">Open...</a></li>
72 <hr/>
71 <hr/>
73 <li id="copy_notebook"><a href="#">Make a Copy...</a></li>
72 <li id="copy_notebook"><a href="#">Make a Copy...</a></li>
74 <li id="rename_notebook"><a href="#">Rename...</a></li>
73 <li id="rename_notebook"><a href="#">Rename...</a></li>
75 <li id="save_notebook"><a href="#">Save</a></li>
74 <li id="save_notebook"><a href="#">Save</a></li>
76 <hr/>
75 <hr/>
77 <li><a href="#">Download as</a>
76 <li><a href="#">Download as</a>
78 <ul>
77 <ul>
79 <li id="download_ipynb"><a href="#">IPython (.ipynb)</a></li>
78 <li id="download_ipynb"><a href="#">IPython (.ipynb)</a></li>
80 <li id="download_py"><a href="#">Python (.py)</a></li>
79 <li id="download_py"><a href="#">Python (.py)</a></li>
81 </ul>
80 </ul>
82 </li>
81 </li>
83 <hr/>
82 <hr/>
84 <li id="print_notebook"><a href="/{{notebook_id}}/print" target="_blank">Print View</a></li>
83 <li id="print_notebook"><a href="/{{notebook_id}}/print" target="_blank">Print View</a></li>
85 <hr/>
84 <hr/>
86 <li id="kill_and_exit"><a href="#" >Close and halt</a></li>
85 <li id="kill_and_exit"><a href="#" >Close and halt</a></li>
87 </ul>
86 </ul>
88 </li>
87 </li>
89 <li><a href="#">Edit</a>
88 <li><a href="#">Edit</a>
90 <ul>
89 <ul>
91 <li id="cut_cell"><a href="#">Cut Cell</a></li>
90 <li id="cut_cell"><a href="#">Cut Cell</a></li>
92 <li id="copy_cell"><a href="#">Copy Cell</a></li>
91 <li id="copy_cell"><a href="#">Copy Cell</a></li>
93 <li id="paste_cell" class="ui-state-disabled"><a href="#">Paste Cell</a></li>
92 <li id="paste_cell" class="ui-state-disabled"><a href="#">Paste Cell</a></li>
94 <li id="paste_cell_above" class="ui-state-disabled"><a href="#">Paste Cell Above</a></li>
93 <li id="paste_cell_above" class="ui-state-disabled"><a href="#">Paste Cell Above</a></li>
95 <li id="paste_cell_below" class="ui-state-disabled"><a href="#">Paste Cell Below</a></li>
94 <li id="paste_cell_below" class="ui-state-disabled"><a href="#">Paste Cell Below</a></li>
96 <li id="delete_cell"><a href="#">Delete</a></li>
95 <li id="delete_cell"><a href="#">Delete</a></li>
97 <hr/>
96 <hr/>
98 <li id="split_cell"><a href="#">Split Cell</a></li>
97 <li id="split_cell"><a href="#">Split Cell</a></li>
99 <li id="merge_cell_above"><a href="#">Merge Cell Above</a></li>
98 <li id="merge_cell_above"><a href="#">Merge Cell Above</a></li>
100 <li id="merge_cell_below"><a href="#">Merge Cell Below</a></li>
99 <li id="merge_cell_below"><a href="#">Merge Cell Below</a></li>
101 <hr/>
100 <hr/>
102 <li id="move_cell_up"><a href="#">Move Cell Up</a></li>
101 <li id="move_cell_up"><a href="#">Move Cell Up</a></li>
103 <li id="move_cell_down"><a href="#">Move Cell Down</a></li>
102 <li id="move_cell_down"><a href="#">Move Cell Down</a></li>
104 <hr/>
103 <hr/>
105 <li id="select_previous"><a href="#">Select Previous Cell</a></li>
104 <li id="select_previous"><a href="#">Select Previous Cell</a></li>
106 <li id="select_next"><a href="#">Select Next Cell</a></li>
105 <li id="select_next"><a href="#">Select Next Cell</a></li>
107 </ul>
106 </ul>
108 </li>
107 </li>
109 <li><a href="#">View</a>
108 <li><a href="#">View</a>
110 <ul>
109 <ul>
111 <li id="toggle_header"><a href="#">Toggle Header</a></li>
110 <li id="toggle_header"><a href="#">Toggle Header</a></li>
112 <li id="toggle_toolbar"><a href="#">Toggle Toolbar</a></li>
111 <li id="toggle_toolbar"><a href="#">Toggle Toolbar</a></li>
113 </ul>
112 </ul>
114 </li>
113 </li>
115 <li><a href="#">Insert</a>
114 <li><a href="#">Insert</a>
116 <ul>
115 <ul>
117 <li id="insert_cell_above"><a href="#">Insert Cell Above</a></li>
116 <li id="insert_cell_above"><a href="#">Insert Cell Above</a></li>
118 <li id="insert_cell_below"><a href="#">Insert Cell Below</a></li>
117 <li id="insert_cell_below"><a href="#">Insert Cell Below</a></li>
119 </ul>
118 </ul>
120 </li>
119 </li>
121 <li><a href="#">Cell</a>
120 <li><a href="#">Cell</a>
122 <ul>
121 <ul>
123 <li id="run_cell"><a href="#">Run</a></li>
122 <li id="run_cell"><a href="#">Run</a></li>
124 <li id="run_cell_in_place"><a href="#">Run in Place</a></li>
123 <li id="run_cell_in_place"><a href="#">Run in Place</a></li>
125 <li id="run_all_cells"><a href="#">Run All</a></li>
124 <li id="run_all_cells"><a href="#">Run All</a></li>
126 <li id="run_all_cells_above"><a href="#">Run All Above</a></li>
125 <li id="run_all_cells_above"><a href="#">Run All Above</a></li>
127 <li id="run_all_cells_below"><a href="#">Run All Below</a></li>
126 <li id="run_all_cells_below"><a href="#">Run All Below</a></li>
128 <hr/>
127 <hr/>
129 <li id="to_code"><a href="#">Code</a></li>
128 <li id="to_code"><a href="#">Code</a></li>
130 <li id="to_markdown"><a href="#">Markdown </a></li>
129 <li id="to_markdown"><a href="#">Markdown </a></li>
131 <li id="to_raw"><a href="#">Raw Text</a></li>
130 <li id="to_raw"><a href="#">Raw Text</a></li>
132 <li id="to_heading1"><a href="#">Heading 1</a></li>
131 <li id="to_heading1"><a href="#">Heading 1</a></li>
133 <li id="to_heading2"><a href="#">Heading 2</a></li>
132 <li id="to_heading2"><a href="#">Heading 2</a></li>
134 <li id="to_heading3"><a href="#">Heading 3</a></li>
133 <li id="to_heading3"><a href="#">Heading 3</a></li>
135 <li id="to_heading4"><a href="#">Heading 4</a></li>
134 <li id="to_heading4"><a href="#">Heading 4</a></li>
136 <li id="to_heading5"><a href="#">Heading 5</a></li>
135 <li id="to_heading5"><a href="#">Heading 5</a></li>
137 <li id="to_heading6"><a href="#">Heading 6</a></li>
136 <li id="to_heading6"><a href="#">Heading 6</a></li>
138 <hr/>
137 <hr/>
139 <li id="toggle_output"><a href="#">Toggle Current Output</a></li>
138 <li id="toggle_output"><a href="#">Toggle Current Output</a></li>
140 <li id="all_outputs"><a href="#">All Output</a>
139 <li id="all_outputs"><a href="#">All Output</a>
141 <ul>
140 <ul>
142 <li id="expand_all_output"><a href="#">Expand</a></li>
141 <li id="expand_all_output"><a href="#">Expand</a></li>
143 <li id="scroll_all_output"><a href="#">Scroll Long</a></li>
142 <li id="scroll_all_output"><a href="#">Scroll Long</a></li>
144 <li id="collapse_all_output"><a href="#">Collapse</a></li>
143 <li id="collapse_all_output"><a href="#">Collapse</a></li>
145 <li id="clear_all_output"><a href="#">Clear</a></li>
144 <li id="clear_all_output"><a href="#">Clear</a></li>
146 </ul>
145 </ul>
147 </li>
146 </li>
148 </ul>
147 </ul>
149 </li>
148 </li>
150 <li><a href="#">Kernel</a>
149 <li><a href="#">Kernel</a>
151 <ul>
150 <ul>
152 <li id="int_kernel"><a href="#">Interrupt</a></li>
151 <li id="int_kernel"><a href="#">Interrupt</a></li>
153 <li id="restart_kernel"><a href="#">Restart</a></li>
152 <li id="restart_kernel"><a href="#">Restart</a></li>
154 </ul>
153 </ul>
155 </li>
154 </li>
156 <li><a href="#">Help</a>
155 <li><a href="#">Help</a>
157 <ul>
156 <ul>
158 <li><a href="http://ipython.org/documentation.html" target="_blank">IPython Help</a></li>
157 <li><a href="http://ipython.org/documentation.html" target="_blank">IPython Help</a></li>
159 <li><a href="http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html" target="_blank">Notebook Help</a></li>
158 <li><a href="http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html" target="_blank">Notebook Help</a></li>
160 <li id="keyboard_shortcuts"><a href="#">Keyboard Shortcuts</a></li>
159 <li id="keyboard_shortcuts"><a href="#">Keyboard Shortcuts</a></li>
161 <hr/>
160 <hr/>
162 <li><a href="http://docs.python.org" target="_blank">Python</a></li>
161 <li><a href="http://docs.python.org" target="_blank">Python</a></li>
163 <li><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></li>
162 <li><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></li>
164 <li><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></li>
163 <li><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></li>
165 <li><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></li>
164 <li><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></li>
166 <li><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></li>
165 <li><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></li>
167 </ul>
166 </ul>
168 </li>
167 </li>
169 </ul>
168 </ul>
170
169
171 </div>
170 </div>
172 <div id="notification_area">
171 <div id="notification_area">
173 </div>
172 </div>
174 </div>
173 </div>
175
174
176
175
177 <div id="maintoolbar"></div>
176 <div id="maintoolbar"></div>
178
177
179 <div id="main_app">
178 <div id="main_app">
180
179
181 <div id="notebook_panel">
180 <div id="notebook_panel">
182 <div id="notebook"></div>
181 <div id="notebook"></div>
183 <div id="pager_splitter"></div>
182 <div id="pager_splitter"></div>
184 <div id="pager_container">
183 <div id="pager_container">
185 <div id='pager_button_area'>
184 <div id='pager_button_area'>
186 </div>
185 </div>
187 <div id="pager"></div>
186 <div id="pager"></div>
188 </div>
187 </div>
189 </div>
188 </div>
190
189
191 </div>
190 </div>
192 <div id='tooltip' class='ipython_tooltip ui-corner-all' style='display:none'></div>
191 <div id='tooltip' class='ipython_tooltip ui-corner-all' style='display:none'></div>
193
192
194
193
195 {% end %}
194 {% end %}
196
195
197
196
198 {% block script %}
197 {% block script %}
199
198
200 <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
199 <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
201 <script src="{{ static_url("codemirror/lib/util/loadmode.js") }}" charset="utf-8"></script>
200 <script src="{{ static_url("codemirror/lib/util/loadmode.js") }}" charset="utf-8"></script>
202 <script src="{{ static_url("codemirror/lib/util/multiplex.js") }}" charset="utf-8"></script>
201 <script src="{{ static_url("codemirror/lib/util/multiplex.js") }}" charset="utf-8"></script>
203 <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script>
202 <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script>
204 <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
203 <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
205 <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
204 <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
206 <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
205 <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
207 <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script>
206 <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script>
208 <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
207 <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
209 <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
208 <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
210
209
211 <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script>
210 <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script>
212
211
213 <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script>
212 <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script>
214 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
213 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
215
214
216 <script src="{{ static_url("js/events.js") }}" type="text/javascript" charset="utf-8"></script>
215 <script src="{{ static_url("js/events.js") }}" type="text/javascript" charset="utf-8"></script>
217 <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
216 <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
218 <script src="{{ static_url("js/layoutmanager.js") }}" type="text/javascript" charset="utf-8"></script>
217 <script src="{{ static_url("js/layoutmanager.js") }}" type="text/javascript" charset="utf-8"></script>
219 <script src="{{ static_url("js/mathjaxutils.js") }}" type="text/javascript" charset="utf-8"></script>
218 <script src="{{ static_url("js/mathjaxutils.js") }}" type="text/javascript" charset="utf-8"></script>
220 <script src="{{ static_url("js/outputarea.js") }}" type="text/javascript" charset="utf-8"></script>
219 <script src="{{ static_url("js/outputarea.js") }}" type="text/javascript" charset="utf-8"></script>
221 <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
220 <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
222 <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
221 <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
223 <script src="{{ static_url("js/completer.js") }}" type="text/javascript" charset="utf-8"></script>
222 <script src="{{ static_url("js/completer.js") }}" type="text/javascript" charset="utf-8"></script>
224 <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
223 <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
225 <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
224 <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
226 <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script>
225 <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script>
227 <script src="{{ static_url("js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script>
226 <script src="{{ static_url("js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script>
228 <script src="{{ static_url("js/pager.js") }}" type="text/javascript" charset="utf-8"></script>
227 <script src="{{ static_url("js/pager.js") }}" type="text/javascript" charset="utf-8"></script>
229 <script src="{{ static_url("js/menubar.js") }}" type="text/javascript" charset="utf-8"></script>
228 <script src="{{ static_url("js/menubar.js") }}" type="text/javascript" charset="utf-8"></script>
230 <script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script>
229 <script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script>
231 <script src="{{ static_url("js/maintoolbar.js") }}" type="text/javascript" charset="utf-8"></script>
230 <script src="{{ static_url("js/maintoolbar.js") }}" type="text/javascript" charset="utf-8"></script>
232 <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
231 <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
233 <script src="{{ static_url("js/notificationwidget.js") }}" type="text/javascript" charset="utf-8"></script>
232 <script src="{{ static_url("js/notificationwidget.js") }}" type="text/javascript" charset="utf-8"></script>
234 <script src="{{ static_url("js/notificationarea.js") }}" type="text/javascript" charset="utf-8"></script>
233 <script src="{{ static_url("js/notificationarea.js") }}" type="text/javascript" charset="utf-8"></script>
235 <script src="{{ static_url("js/tooltip.js") }}" type="text/javascript" charset="utf-8"></script>
234 <script src="{{ static_url("js/tooltip.js") }}" type="text/javascript" charset="utf-8"></script>
236 <script src="{{ static_url("js/config.js") }}" type="text/javascript" charset="utf-8"></script>
235 <script src="{{ static_url("js/config.js") }}" type="text/javascript" charset="utf-8"></script>
237 <script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script>
236 <script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script>
238
237
239 <script src="{{ static_url("js/contexthint.js") }}" charset="utf-8"></script>
238 <script src="{{ static_url("js/contexthint.js") }}" charset="utf-8"></script>
240
239
241 {% end %}
240 {% end %}
@@ -1,96 +1,95 b''
1 {% extends page.html %}
1 {% extends page.html %}
2
2
3 {% block stylesheet %}
3 {% block stylesheet %}
4
4
5 {% if mathjax_url %}
5 {% if mathjax_url %}
6 <script type="text/x-mathjax-config">
6 <script type="text/x-mathjax-config">
7 MathJax.Hub.Config({
7 MathJax.Hub.Config({
8 TeX: { equationNumbers: { autoNumber: "AMS", useLabelIds: true } },
9 tex2jax: {
8 tex2jax: {
10 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
9 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
11 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
10 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
12 processEnvironments: true
11 processEnvironments: true
13 },
12 },
14 displayAlign: 'left', // Change this to 'center' to center equations.
13 displayAlign: 'left', // Change this to 'center' to center equations.
15 "HTML-CSS": {
14 "HTML-CSS": {
16 styles: {'.MathJax_Display': {"margin": 0}}
15 styles: {'.MathJax_Display': {"margin": 0}}
17 }
16 }
18 });
17 });
19 </script>
18 </script>
20
19
21 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
20 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML-full" charset="utf-8"></script>
22 {% end %}
21 {% end %}
23 <script type="text/javascript">
22 <script type="text/javascript">
24 // MathJax disabled, set as null to distingish from *missing* MathJax,
23 // MathJax disabled, set as null to distingish from *missing* MathJax,
25 // where it will be undefined, and should prompt a dialog later.
24 // where it will be undefined, and should prompt a dialog later.
26 window.mathjax_url = "{{mathjax_url}}";
25 window.mathjax_url = "{{mathjax_url}}";
27 </script>
26 </script>
28
27
29 <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}">
28 <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}">
30 <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}">
29 <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}">
31
30
32 <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/>
31 <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/>
33
32
34 <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" />
33 <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" />
35 <link rel="stylesheet" href="{{ static_url("css/printnotebook.css") }}" type="text/css" />
34 <link rel="stylesheet" href="{{ static_url("css/printnotebook.css") }}" type="text/css" />
36 <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" />
35 <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" />
37
36
38 {% end %}
37 {% end %}
39
38
40
39
41 {% block params %}
40 {% block params %}
42
41
43 data-project={{project}}
42 data-project={{project}}
44 data-base-project-url={{base_project_url}}
43 data-base-project-url={{base_project_url}}
45 data-base-kernel-url={{base_kernel_url}}
44 data-base-kernel-url={{base_kernel_url}}
46 data-read-only={{read_only and not logged_in}}
45 data-read-only={{read_only and not logged_in}}
47 data-notebook-id={{notebook_id}}
46 data-notebook-id={{notebook_id}}
48
47
49 {% end %}
48 {% end %}
50
49
51
50
52 {% block header %}
51 {% block header %}
53 {% end %}
52 {% end %}
54
53
55
54
56 {% block site %}
55 {% block site %}
57
56
58 <div id="main_app">
57 <div id="main_app">
59
58
60 <div id="notebook_panel">
59 <div id="notebook_panel">
61 <div id="notebook"></div>
60 <div id="notebook"></div>
62 </div>
61 </div>
63
62
64 </div>
63 </div>
65
64
66 {% end %}
65 {% end %}
67
66
68
67
69 {% block script %}
68 {% block script %}
70
69
71 <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
70 <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
72 <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script>
71 <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script>
73 <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
72 <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
74 <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
73 <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
75 <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
74 <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
76 <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script>
75 <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script>
77 <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
76 <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
78 <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
77 <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
79
78
80 <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script>
79 <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script>
81
80
82 <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script>
81 <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script>
83 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
82 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
84
83
85 <script src="{{ static_url("js/events.js") }}" type="text/javascript" charset="utf-8"></script>
84 <script src="{{ static_url("js/events.js") }}" type="text/javascript" charset="utf-8"></script>
86 <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
85 <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
87 <script src="{{ static_url("js/mathjaxutils.js") }}" type="text/javascript" charset="utf-8"></script>
86 <script src="{{ static_url("js/mathjaxutils.js") }}" type="text/javascript" charset="utf-8"></script>
88 <script src="{{ static_url("js/outputarea.js") }}" type="text/javascript" charset="utf-8"></script>
87 <script src="{{ static_url("js/outputarea.js") }}" type="text/javascript" charset="utf-8"></script>
89 <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
88 <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
90 <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
89 <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
91 <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
90 <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
92 <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
91 <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
93 <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
92 <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
94 <script src="{{ static_url("js/printnotebookmain.js") }}" type="text/javascript" charset="utf-8"></script>
93 <script src="{{ static_url("js/printnotebookmain.js") }}" type="text/javascript" charset="utf-8"></script>
95
94
96 {% end %}
95 {% end %}
@@ -1,339 +1,259 b''
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "name": "Typesetting Math Using MathJax"
3 "name": "Typesetting Math Using MathJax"
4 },
4 },
5 "nbformat": 3,
5 "nbformat": 3,
6 "nbformat_minor": 0,
6 "nbformat_minor": 0,
7 "worksheets": [
7 "worksheets": [
8 {
8 {
9 "cells": [
9 "cells": [
10 {
10 {
11 "cell_type": "markdown",
11 "cell_type": "markdown",
12 "metadata": {},
12 "metadata": {},
13 "source": [
13 "source": [
14 "The Markdown parser included in IPython is MathJax-aware. This means that you can freely mix in mathematical expressions using the [MathJax subset of Tex and LaTeX](http://docs.mathjax.org/en/latest/tex.html#tex-support). [Some examples from the MathJax site](http://www.mathjax.org/demos/tex-samples/) are reproduced below, as well as the Markdown+TeX source."
14 "The Markdown parser included in IPython is MathJax-aware. This means that you can freely mix in mathematical expressions using the [MathJax subset of Tex and LaTeX](http://docs.mathjax.org/en/latest/tex.html#tex-support). [Some examples from the MathJax site](http://www.mathjax.org/demos/tex-samples/) are reproduced below, as well as the Markdown+TeX source."
15 ]
15 ]
16 },
16 },
17 {
17 {
18 "cell_type": "markdown",
18 "cell_type": "markdown",
19 "metadata": {},
19 "metadata": {},
20 "source": [
20 "source": [
21 "# Motivating Examples\n",
21 "# Motivating Examples\n",
22 "\n",
22 "\n",
23 "---\n",
23 "---\n",
24 "\n",
24 "\n",
25 "## The Lorenz Equations\n",
25 "## The Lorenz Equations\n",
26 "### Source\n",
26 "### Source\n",
27 "```\\begin{aligned}\n",
27 "```\\begin{aligned}\n",
28 "\\dot{x} & = \\sigma(y-x) \\\\\n",
28 "\\dot{x} & = \\sigma(y-x) \\\\\n",
29 "\\dot{y} & = \\rho x - y - xz \\\\\n",
29 "\\dot{y} & = \\rho x - y - xz \\\\\n",
30 "\\dot{z} & = -\\beta z + xy\n",
30 "\\dot{z} & = -\\beta z + xy\n",
31 "\\end{aligned}\n",
31 "\\end{aligned}\n",
32 "```\n",
32 "```\n",
33 "### Display\n",
33 "### Display\n",
34 "\\begin{aligned}\n",
34 "\\begin{aligned}\n",
35 "\\dot{x} & = \\sigma(y-x) \\\\\n",
35 "\\dot{x} & = \\sigma(y-x) \\\\\n",
36 "\\dot{y} & = \\rho x - y - xz \\\\\n",
36 "\\dot{y} & = \\rho x - y - xz \\\\\n",
37 "\\dot{z} & = -\\beta z + xy\n",
37 "\\dot{z} & = -\\beta z + xy\n",
38 "\\end{aligned}"
38 "\\end{aligned}"
39 ]
39 ]
40 },
40 },
41 {
41 {
42 "cell_type": "markdown",
42 "cell_type": "markdown",
43 "metadata": {},
43 "metadata": {},
44 "source": [
44 "source": [
45 "## The Cauchy-Schwarz Inequality\n",
45 "## The Cauchy-Schwarz Inequality\n",
46 "### Source\n",
46 "### Source\n",
47 "```\\begin{equation*}\n",
47 "```\\begin{equation*}\n",
48 "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n",
48 "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n",
49 "\\end{equation*}\n",
49 "\\end{equation*}\n",
50 "```\n",
50 "```\n",
51 "### Display\n",
51 "### Display\n",
52 "\\begin{equation*}\n",
52 "\\begin{equation*}\n",
53 "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n",
53 "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n",
54 "\\end{equation*}"
54 "\\end{equation*}"
55 ]
55 ]
56 },
56 },
57 {
57 {
58 "cell_type": "markdown",
58 "cell_type": "markdown",
59 "metadata": {},
59 "metadata": {},
60 "source": [
60 "source": [
61 "## A Cross Product Formula\n",
61 "## A Cross Product Formula\n",
62 "### Source\n",
62 "### Source\n",
63 "```\\begin{equation*}\n",
63 "```\\begin{equation*}\n",
64 "\\mathbf{V}_1 \\times \\mathbf{V}_2 = \\begin{vmatrix}\n",
64 "\\mathbf{V}_1 \\times \\mathbf{V}_2 = \\begin{vmatrix}\n",
65 "\\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\\n",
65 "\\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\\n",
66 "\\frac{\\partial X}{\\partial u} & \\frac{\\partial Y}{\\partial u} & 0 \\\\\n",
66 "\\frac{\\partial X}{\\partial u} & \\frac{\\partial Y}{\\partial u} & 0 \\\\\n",
67 "\\frac{\\partial X}{\\partial v} & \\frac{\\partial Y}{\\partial v} & 0\n",
67 "\\frac{\\partial X}{\\partial v} & \\frac{\\partial Y}{\\partial v} & 0\n",
68 "\\end{vmatrix} \n",
68 "\\end{vmatrix} \n",
69 "\\end{equation*}\n",
69 "\\end{equation*}\n",
70 "```\n",
70 "```\n",
71 "### Display\n",
71 "### Display\n",
72 "\\begin{equation*}\n",
72 "\\begin{equation*}\n",
73 "\\mathbf{V}_1 \\times \\mathbf{V}_2 = \\begin{vmatrix}\n",
73 "\\mathbf{V}_1 \\times \\mathbf{V}_2 = \\begin{vmatrix}\n",
74 "\\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\\n",
74 "\\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\\n",
75 "\\frac{\\partial X}{\\partial u} & \\frac{\\partial Y}{\\partial u} & 0 \\\\\n",
75 "\\frac{\\partial X}{\\partial u} & \\frac{\\partial Y}{\\partial u} & 0 \\\\\n",
76 "\\frac{\\partial X}{\\partial v} & \\frac{\\partial Y}{\\partial v} & 0\n",
76 "\\frac{\\partial X}{\\partial v} & \\frac{\\partial Y}{\\partial v} & 0\n",
77 "\\end{vmatrix} \n",
77 "\\end{vmatrix} \n",
78 "\\end{equation*}"
78 "\\end{equation*}"
79 ]
79 ]
80 },
80 },
81 {
81 {
82 "cell_type": "markdown",
82 "cell_type": "markdown",
83 "metadata": {},
83 "metadata": {},
84 "source": [
84 "source": [
85 "## The probability of getting \\(k\\) heads when flipping \\(n\\) coins is\n",
85 "## The probability of getting \\(k\\) heads when flipping \\(n\\) coins is\n",
86 "### Source\n",
86 "### Source\n",
87 "```\\begin{equation*}\n",
87 "```\\begin{equation*}\n",
88 "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n",
88 "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n",
89 "\\end{equation*}\n",
89 "\\end{equation*}\n",
90 "```\n",
90 "```\n",
91 "### Display\n",
91 "### Display\n",
92 "\\begin{equation*}\n",
92 "\\begin{equation*}\n",
93 "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n",
93 "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n",
94 "\\end{equation*}"
94 "\\end{equation*}"
95 ]
95 ]
96 },
96 },
97 {
97 {
98 "cell_type": "markdown",
98 "cell_type": "markdown",
99 "metadata": {},
99 "metadata": {},
100 "source": [
100 "source": [
101 "## An Identity of Ramanujan\n",
101 "## An Identity of Ramanujan\n",
102 "### Source\n",
102 "### Source\n",
103 "```\\begin{equation*}\n",
103 "```\\begin{equation*}\n",
104 "\\frac{1}{\\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\\frac25 \\pi}} =\n",
104 "\\frac{1}{\\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\\frac25 \\pi}} =\n",
105 "1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}\n",
105 "1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}\n",
106 "{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } } \n",
106 "{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } } \n",
107 "\\end{equation*}\n",
107 "\\end{equation*}\n",
108 "```\n",
108 "```\n",
109 "### Display\n",
109 "### Display\n",
110 "\\begin{equation*}\n",
110 "\\begin{equation*}\n",
111 "\\frac{1}{\\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\\frac25 \\pi}} =\n",
111 "\\frac{1}{\\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\\frac25 \\pi}} =\n",
112 "1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}\n",
112 "1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}\n",
113 "{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } } \n",
113 "{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } } \n",
114 "\\end{equation*}"
114 "\\end{equation*}"
115 ]
115 ]
116 },
116 },
117 {
117 {
118 "cell_type": "markdown",
118 "cell_type": "markdown",
119 "metadata": {},
119 "metadata": {},
120 "source": [
120 "source": [
121 "## A Rogers-Ramanujan Identity\n",
121 "## A Rogers-Ramanujan Identity\n",
122 "### Source\n",
122 "### Source\n",
123 "```\\begin{equation*}\n",
123 "```\\begin{equation*}\n",
124 "1 + \\frac{q^2}{(1-q)}+\\frac{q^6}{(1-q)(1-q^2)}+\\cdots =\n",
124 "1 + \\frac{q^2}{(1-q)}+\\frac{q^6}{(1-q)(1-q^2)}+\\cdots =\n",
125 "\\prod_{j=0}^{\\infty}\\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},\n",
125 "\\prod_{j=0}^{\\infty}\\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},\n",
126 "\\quad\\quad \\text{for $|q|<1$}. \n",
126 "\\quad\\quad \\text{for $|q|<1$}. \n",
127 "\\end{equation*}\n",
127 "\\end{equation*}\n",
128 "```\n",
128 "```\n",
129 "### Display\n",
129 "### Display\n",
130 "\\begin{equation*}\n",
130 "\\begin{equation*}\n",
131 "1 + \\frac{q^2}{(1-q)}+\\frac{q^6}{(1-q)(1-q^2)}+\\cdots =\n",
131 "1 + \\frac{q^2}{(1-q)}+\\frac{q^6}{(1-q)(1-q^2)}+\\cdots =\n",
132 "\\prod_{j=0}^{\\infty}\\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},\n",
132 "\\prod_{j=0}^{\\infty}\\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},\n",
133 "\\quad\\quad \\text{for $|q|<1$}. \n",
133 "\\quad\\quad \\text{for $|q|<1$}. \n",
134 "\\end{equation*}"
134 "\\end{equation*}"
135 ]
135 ]
136 },
136 },
137 {
137 {
138 "cell_type": "markdown",
138 "cell_type": "markdown",
139 "metadata": {},
139 "metadata": {},
140 "source": [
140 "source": [
141 "## Maxwell's Equations\n",
141 "## Maxwell's Equations\n",
142 "### Source\n",
142 "### Source\n",
143 "```\\begin{aligned}\n",
143 "```\\begin{aligned}\n",
144 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
144 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
145 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
145 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
146 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \n",
146 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \n",
147 "\\end{aligned}\n",
147 "\\end{aligned}\n",
148 "```\n",
148 "```\n",
149 "### Display\n",
149 "### Display\n",
150 "\\begin{aligned}\n",
150 "\\begin{aligned}\n",
151 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
151 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
152 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
152 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
153 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \n",
153 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \n",
154 "\\end{aligned}"
154 "\\end{aligned}"
155 ]
155 ]
156 },
156 },
157 {
157 {
158 "cell_type": "markdown",
158 "cell_type": "markdown",
159 "metadata": {},
159 "metadata": {},
160 "source": [
160 "source": [
161 "# Equation Numbering and References\n",
161 "# Equation Numbering and References\n",
162 "\n",
162 "\n",
163 "---\n",
163 "---\n",
164 "\n",
164 "\n",
165 "These equation reference examples are adapted from an [example page in the MathJax documentation](http://cdn.mathjax.org/mathjax/latest/test/sample-eqrefs.html). Note that it's okay to reference equations across cells. Click inside this cell to see the source.\n",
165 "Equation numbering and referencing will be available in a future version of IPython."
166 "\n",
167 "## Labeled equations and references\n",
168 "\n",
169 "Here is a labeled equation:\n",
170 "\\begin{equation}\n",
171 "x+1\\over\\sqrt{1-x^2}\\label{ref1}\n",
172 "\\end{equation}\n",
173 "\n",
174 "with a reference to ref1: \\ref{ref1},\n",
175 "and another numbered one with no label:\n",
176 "\\begin{equation}\n",
177 "x+1\\over\\sqrt{1-x^2}\n",
178 "\\end{equation}"
179 ]
180 },
181 {
182 "cell_type": "markdown",
183 "metadata": {},
184 "source": [
185 "## \\nonumber and equation*\n",
186 "\n",
187 "This one uses \\nonumber:\n",
188 "\\begin{equation}\n",
189 "x+1\\over\\sqrt{1-x^2}\\nonumber\n",
190 "\\end{equation}\n",
191 "\n",
192 "Here's one with the equation* environment:\n",
193 "\\begin{equation*}\n",
194 "x+1\\over\\sqrt{1-x^2}\n",
195 "\\end{equation*}"
196 ]
197 },
198 {
199 "cell_type": "markdown",
200 "metadata": {},
201 "source": [
202 "## Forward references\n",
203 "\n",
204 "This is a forward reference [\\ref{ref2}] and another \\eqref{ref2} for the \n",
205 "following equation:\n",
206 "\n",
207 "\\begin{equation}\n",
208 "x+1\\over\\sqrt{1-x^2}\\label{ref2}\n",
209 "\\end{equation}\n",
210 "\n",
211 "More math:\n",
212 "\\begin{equation}\n",
213 "x+1\\over\\sqrt{1-x^2}\n",
214 "\\end{equation}"
215 ]
216 },
217 {
218 "cell_type": "markdown",
219 "metadata": {},
220 "source": [
221 "### References inline and in environments\n",
222 "\n",
223 "Here is a ref inside math: $\\ref{ref2}+1$ and text after it.\n",
224 "\n",
225 "\\begin{align} \n",
226 "x& = y_1-y_2+y_3-y_5+y_8-\\dots \n",
227 "&& \\text{by \\eqref{ref1}}\\\\ \n",
228 "& = y'\\circ y^* && \\text{(by \\eqref{ref3})}\\\\ \n",
229 "& = y(0) y' && \\text {by Axiom 1.} \n",
230 "\\end{align} \n",
231 "\n",
232 "### Missing references\n",
233 "Here's a bad ref [\\ref{ref4}] to a nonexistent label.\n",
234 "\n",
235 "### Numbering align environments\n",
236 "An alignment:\n",
237 "\\begin{align}\n",
238 "a&=b\\label{ref3}\\cr\n",
239 "&=c+d\n",
240 "\\end{align}\n",
241 "and a starred one:\n",
242 "\\begin{align*}\n",
243 "a&=b\\cr\n",
244 "&=c+d\n",
245 "\\end{align*}"
246 ]
166 ]
247 },
167 },
248 {
168 {
249 "cell_type": "markdown",
169 "cell_type": "markdown",
250 "metadata": {},
170 "metadata": {},
251 "source": [
171 "source": [
252 "# Inline Typesetting (Mixing Markdown and TeX)\n",
172 "# Inline Typesetting (Mixing Markdown and TeX)\n",
253 "\n",
173 "\n",
254 "---\n",
174 "---\n",
255 "\n",
175 "\n",
256 "While display equations look good for a page of samples, the ability to mix math and *formatted* **text** in a paragraph is also important.\n",
176 "While display equations look good for a page of samples, the ability to mix math and *formatted* **text** in a paragraph is also important.\n",
257 "\n",
177 "\n",
258 "## Source\n",
178 "## Source\n",
259 "``` This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. \n",
179 "``` This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. \n",
260 "```\n",
180 "```\n",
261 "## Display\n",
181 "## Display\n",
262 "This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. "
182 "This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. "
263 ]
183 ]
264 },
184 },
265 {
185 {
266 "cell_type": "markdown",
186 "cell_type": "markdown",
267 "metadata": {},
187 "metadata": {},
268 "source": [
188 "source": [
269 "# Other Syntax\n",
189 "# Other Syntax\n",
270 "\n",
190 "\n",
271 "---\n",
191 "---\n",
272 "\n",
192 "\n",
273 "You will notice in other places on the web that `$$` are needed explicitly to begin and end MathJax typesetting. This is **not** required if you will be using TeX environments, but the IPython notebook will accept this syntax on legacy notebooks. \n",
193 "You will notice in other places on the web that `$$` are needed explicitly to begin and end MathJax typesetting. This is **not** required if you will be using TeX environments, but the IPython notebook will accept this syntax on legacy notebooks. \n",
274 "\n",
194 "\n",
275 "### Source\n",
195 "### Source\n",
276 "```$$\n",
196 "```$$\n",
277 "\\begin{array}{c}\n",
197 "\\begin{array}{c}\n",
278 "y_1 \\\\\\\n",
198 "y_1 \\\\\\\n",
279 "y_2 \\mathtt{t}_i \\\\\\\n",
199 "y_2 \\mathtt{t}_i \\\\\\\n",
280 "z_{3,4}\n",
200 "z_{3,4}\n",
281 "\\end{array}\n",
201 "\\end{array}\n",
282 "$$\n",
202 "$$\n",
283 "```\n",
203 "```\n",
284 "\n",
204 "\n",
285 "```\n",
205 "```\n",
286 "$$\n",
206 "$$\n",
287 "\\begin{array}{c}\n",
207 "\\begin{array}{c}\n",
288 "y_1 \\cr\n",
208 "y_1 \\cr\n",
289 "y_2 \\mathtt{t}_i \\cr\n",
209 "y_2 \\mathtt{t}_i \\cr\n",
290 "y_{3}\n",
210 "y_{3}\n",
291 "\\end{array}\n",
211 "\\end{array}\n",
292 "$$\n",
212 "$$\n",
293 "```\n",
213 "```\n",
294 "\n",
214 "\n",
295 "```\n",
215 "```\n",
296 "$$\\begin{eqnarray} \n",
216 "$$\\begin{eqnarray} \n",
297 "x' &=& &x \\sin\\phi &+& z \\cos\\phi \\\\\n",
217 "x' &=& &x \\sin\\phi &+& z \\cos\\phi \\\\\n",
298 "z' &=& - &x \\cos\\phi &+& z \\sin\\phi \\\\\n",
218 "z' &=& - &x \\cos\\phi &+& z \\sin\\phi \\\\\n",
299 "\\end{eqnarray}$$\n",
219 "\\end{eqnarray}$$\n",
300 "```\n",
220 "```\n",
301 "\n",
221 "\n",
302 "```\n",
222 "```\n",
303 "$$\n",
223 "$$\n",
304 "x=4\n",
224 "x=4\n",
305 "$$\n",
225 "$$\n",
306 "```\n",
226 "```\n",
307 "\n",
227 "\n",
308 "### Display\n",
228 "### Display\n",
309 "$$\n",
229 "$$\n",
310 "\\begin{array}{c}\n",
230 "\\begin{array}{c}\n",
311 "y_1 \\\\\\\n",
231 "y_1 \\\\\\\n",
312 "y_2 \\mathtt{t}_i \\\\\\\n",
232 "y_2 \\mathtt{t}_i \\\\\\\n",
313 "z_{3,4}\n",
233 "z_{3,4}\n",
314 "\\end{array}\n",
234 "\\end{array}\n",
315 "$$\n",
235 "$$\n",
316 "\n",
236 "\n",
317 "$$\n",
237 "$$\n",
318 "\\begin{array}{c}\n",
238 "\\begin{array}{c}\n",
319 "y_1 \\cr\n",
239 "y_1 \\cr\n",
320 "y_2 \\mathtt{t}_i \\cr\n",
240 "y_2 \\mathtt{t}_i \\cr\n",
321 "y_{3}\n",
241 "y_{3}\n",
322 "\\end{array}\n",
242 "\\end{array}\n",
323 "$$\n",
243 "$$\n",
324 "\n",
244 "\n",
325 "$$\\begin{eqnarray} \n",
245 "$$\\begin{eqnarray} \n",
326 "x' &=& &x \\sin\\phi &+& z \\cos\\phi \\\\\n",
246 "x' &=& &x \\sin\\phi &+& z \\cos\\phi \\\\\n",
327 "z' &=& - &x \\cos\\phi &+& z \\sin\\phi \\\\\n",
247 "z' &=& - &x \\cos\\phi &+& z \\sin\\phi \\\\\n",
328 "\\end{eqnarray}$$\n",
248 "\\end{eqnarray}$$\n",
329 "\n",
249 "\n",
330 "$$\n",
250 "$$\n",
331 "x=4\n",
251 "x=4\n",
332 "$$"
252 "$$"
333 ]
253 ]
334 }
254 }
335 ],
255 ],
336 "metadata": {}
256 "metadata": {}
337 }
257 }
338 ]
258 ]
339 } No newline at end of file
259 }
General Comments 0
You need to be logged in to leave comments. Login now