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