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