Show More
@@ -219,6 +219,7 b' class NewHandler(AuthenticatedHandler):' | |||
|
219 | 219 | base_project_url=u'/', base_kernel_url=u'/', |
|
220 | 220 | kill_kernel=False, |
|
221 | 221 | read_only=False, |
|
222 | mathjax_url=self.application.ipython_app.mathjax_url, | |
|
222 | 223 | ) |
|
223 | 224 | |
|
224 | 225 | |
@@ -237,6 +238,7 b' class NamedNotebookHandler(AuthenticatedHandler):' | |||
|
237 | 238 | base_project_url=u'/', base_kernel_url=u'/', |
|
238 | 239 | kill_kernel=False, |
|
239 | 240 | read_only=self.read_only, |
|
241 | mathjax_url=self.application.ipython_app.mathjax_url, | |
|
240 | 242 | ) |
|
241 | 243 | |
|
242 | 244 |
@@ -128,6 +128,17 b" flags['no-browser']=(" | |||
|
128 | 128 | {'NotebookApp' : {'open_browser' : False}}, |
|
129 | 129 | "Don't open the notebook in a browser after startup." |
|
130 | 130 | ) |
|
131 | flags['no-mathjax']=( | |
|
132 | {'NotebookApp' : {'enable_mathjax' : False}}, | |
|
133 | """Disable MathJax | |
|
134 | ||
|
135 | MathJax is the javascript library IPython uses to render math/LaTeX. It is | |
|
136 | very large, so you may want to disable it if you have a slow internet | |
|
137 | connection, or for offline use of the notebook. | |
|
138 | ||
|
139 | When disabled, equations etc. will appear as their untransformed TeX source. | |
|
140 | """ | |
|
141 | ) | |
|
131 | 142 | flags['read-only'] = ( |
|
132 | 143 | {'NotebookApp' : {'read_only' : True}}, |
|
133 | 144 | """Allow read-only access to notebooks. |
@@ -144,7 +155,7 b" flags['read-only'] = (" | |||
|
144 | 155 | # the flags that are specific to the frontend |
|
145 | 156 | # these must be scrubbed before being passed to the kernel, |
|
146 | 157 | # or it will raise an error on unrecognized flags |
|
147 | notebook_flags = ['no-browser', 'read-only'] | |
|
158 | notebook_flags = ['no-browser', 'no-mathjax', 'read-only'] | |
|
148 | 159 | |
|
149 | 160 | aliases = dict(ipkernel_aliases) |
|
150 | 161 | |
@@ -230,6 +241,42 b' class NotebookApp(BaseIPythonApplication):' | |||
|
230 | 241 | read_only = Bool(False, config=True, |
|
231 | 242 | help="Whether to prevent editing/execution of notebooks." |
|
232 | 243 | ) |
|
244 | ||
|
245 | enable_mathjax = Bool(True, config=True, | |
|
246 | help="""Whether to enable MathJax for typesetting math/TeX | |
|
247 | ||
|
248 | MathJax is the javascript library IPython uses to render math/LaTeX. It is | |
|
249 | very large, so you may want to disable it if you have a slow internet | |
|
250 | connection, or for offline use of the notebook. | |
|
251 | ||
|
252 | When disabled, equations etc. will appear as their untransformed TeX source. | |
|
253 | """ | |
|
254 | ) | |
|
255 | def _enable_mathjax_changed(self, name, old, new): | |
|
256 | """set mathjax url to empty if mathjax is disabled""" | |
|
257 | if not new: | |
|
258 | self.mathjax_url = u'' | |
|
259 | ||
|
260 | mathjax_url = Unicode("", config=True, | |
|
261 | help="""The url for MathJax.js.""" | |
|
262 | ) | |
|
263 | def _mathjax_url_default(self): | |
|
264 | if not self.enable_mathjax: | |
|
265 | return u'' | |
|
266 | static_path = os.path.join(os.path.dirname(__file__), "static") | |
|
267 | if os.path.exists(os.path.join(static_path, 'mathjax', "MathJax.js")): | |
|
268 | self.log.info("Using local MathJax") | |
|
269 | return u"static/mathjax/MathJax.js" | |
|
270 | else: | |
|
271 | self.log.info("Using MathJax from CDN") | |
|
272 | return u"http://cdn.mathjax.org/mathjax/latest/MathJax.js" | |
|
273 | ||
|
274 | def _mathjax_url_changed(self, name, old, new): | |
|
275 | if new and not self.enable_mathjax: | |
|
276 | # enable_mathjax=False overrides mathjax_url | |
|
277 | self.mathjax_url = u'' | |
|
278 | else: | |
|
279 | self.log.info("Using MathJax: %s", new) | |
|
233 | 280 | |
|
234 | 281 | def parse_command_line(self, argv=None): |
|
235 | 282 | super(NotebookApp, self).parse_command_line(argv) |
@@ -428,6 +428,18 b' div.text_cell_render {' | |||
|
428 | 428 | font-family: monospace; |
|
429 | 429 | } |
|
430 | 430 | |
|
431 | pre.dialog { | |
|
432 | background-color: #f7f7f7; | |
|
433 | border: 1px solid #ddd; | |
|
434 | border-radius: 3px; | |
|
435 | padding: 0.4em; | |
|
436 | padding-left: 2em; | |
|
437 | } | |
|
438 | ||
|
439 | p.dialog{ | |
|
440 | padding : 0.2em; | |
|
441 | } | |
|
442 | ||
|
431 | 443 | @media print { |
|
432 | 444 | body { overflow: visible !important; } |
|
433 | 445 | .ui-widget-content { border: 0px; } |
@@ -88,6 +88,13 b' var IPython = (function (IPython) {' | |||
|
88 | 88 | // Subclasses must implement create_element. |
|
89 | 89 | Cell.prototype.create_element = function () {}; |
|
90 | 90 | |
|
91 | // typeset with MathJax if MathJax is available | |
|
92 | Cell.prototype.typeset = function () { | |
|
93 | if (window.MathJax){ | |
|
94 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |
|
95 | } | |
|
96 | }; | |
|
97 | ||
|
91 | 98 | IPython.Cell = Cell; |
|
92 | 99 | |
|
93 | 100 | return IPython; |
@@ -522,7 +522,7 b' var IPython = (function (IPython) {' | |||
|
522 | 522 | this.element.find('div.output').append(toinsert); |
|
523 | 523 | // If we just output latex, typeset it. |
|
524 | 524 | if ((json.latex !== undefined) || (json.html !== undefined)) { |
|
525 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |
|
525 | this.typeset(); | |
|
526 | 526 | }; |
|
527 | 527 | }; |
|
528 | 528 | |
@@ -574,7 +574,7 b' var IPython = (function (IPython) {' | |||
|
574 | 574 | this.element.find('div.output').append(toinsert); |
|
575 | 575 | // If we just output latex, typeset it. |
|
576 | 576 | if ( (json.latex !== undefined) || (json.html !== undefined) ) { |
|
577 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |
|
577 | this.typeset(); | |
|
578 | 578 | }; |
|
579 | 579 | }; |
|
580 | 580 |
@@ -59,7 +59,7 b' var IPython = (function (IPython) {' | |||
|
59 | 59 | var that = this; |
|
60 | 60 | $(document).keydown(function (event) { |
|
61 | 61 | // console.log(event); |
|
62 |
if (that.read_only) return |
|
|
62 | if (that.read_only) return true; | |
|
63 | 63 | if (event.which === 27) { |
|
64 | 64 | // Intercept escape at highest level to avoid closing |
|
65 | 65 | // websocket connection with firefox |
@@ -11,17 +11,67 b'' | |||
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | $(document).ready(function () { |
|
14 | ||
|
15 | MathJax.Hub.Config({ | |
|
16 | tex2jax: { | |
|
17 | inlineMath: [ ['$','$'], ["\\(","\\)"] ], | |
|
18 |
|
|
|
19 | }, | |
|
20 | displayAlign: 'left', // Change this to 'center' to center equations. | |
|
21 | "HTML-CSS": { | |
|
22 | styles: {'.MathJax_Display': {"margin": 0}} | |
|
23 | } | |
|
24 | }); | |
|
14 | if (window.MathJax){ | |
|
15 | // MathJax loaded | |
|
16 | MathJax.Hub.Config({ | |
|
17 | tex2jax: { | |
|
18 | inlineMath: [ ['$','$'], ["\\(","\\)"] ], | |
|
19 | displayMath: [ ['$$','$$'], ["\\[","\\]"] ] | |
|
20 | }, | |
|
21 | displayAlign: 'left', // Change this to 'center' to center equations. | |
|
22 | "HTML-CSS": { | |
|
23 | styles: {'.MathJax_Display': {"margin": 0}} | |
|
24 | } | |
|
25 | }); | |
|
26 | }else if (window.mathjax_url != ""){ | |
|
27 | // Don't have MathJax, but should. Show dialog. | |
|
28 | var dialog = $('<div></div>') | |
|
29 | .append( | |
|
30 | $("<p></p>").addClass('dialog').html( | |
|
31 | "Math/LaTeX rendering will be disabled." | |
|
32 | ) | |
|
33 | ).append( | |
|
34 | $("<p></p>").addClass('dialog').html( | |
|
35 | "If you have administrative access to the notebook server and" + | |
|
36 | " a working internet connection, you can install a local copy" + | |
|
37 | " of MathJax for offline use with the following command on the server" + | |
|
38 | " at a Python or IPython prompt:" | |
|
39 | ) | |
|
40 | ).append( | |
|
41 | $("<pre></pre>").addClass('dialog').html( | |
|
42 | ">>> from IPython.external import mathjax; mathjax.install_mathjax()" | |
|
43 | ) | |
|
44 | ).append( | |
|
45 | $("<p></p>").addClass('dialog').html( | |
|
46 | "This will try to install MathJax into the IPython source directory." | |
|
47 | ) | |
|
48 | ).append( | |
|
49 | $("<p></p>").addClass('dialog').html( | |
|
50 | "If IPython is installed to a location that requires" + | |
|
51 | " administrative privileges to write, you will need to make this call as" + | |
|
52 | " an administrator, via 'sudo'." | |
|
53 | ) | |
|
54 | ).append( | |
|
55 | $("<p></p>").addClass('dialog').html( | |
|
56 | "When you start the notebook server, you can instruct it to disable MathJax support altogether:" | |
|
57 | ) | |
|
58 | ).append( | |
|
59 | $("<pre></pre>").addClass('dialog').html( | |
|
60 | "$ ipython notebook --no-mathjax" | |
|
61 | ) | |
|
62 | ).append( | |
|
63 | $("<p></p>").addClass('dialog').html( | |
|
64 | "which will prevent this dialog from appearing." | |
|
65 | ) | |
|
66 | ).dialog({ | |
|
67 | title: "Failed to retrieve MathJax from '" + window.mathjax_url + "'", | |
|
68 | width: "70%", | |
|
69 | modal: true, | |
|
70 | }) | |
|
71 | }else{ | |
|
72 | // No MathJax, but none expected. No dialog. | |
|
73 | } | |
|
74 | ||
|
25 | 75 | IPython.markdown_converter = new Markdown.Converter(); |
|
26 | 76 | IPython.read_only = $('meta[name=read_only]').attr("content") == 'True'; |
|
27 | 77 |
@@ -175,7 +175,7 b' var IPython = (function (IPython) {' | |||
|
175 | 175 | var text = this.get_source(); |
|
176 | 176 | if (text === "") { text = this.placeholder; } |
|
177 | 177 | this.set_rendered(text); |
|
178 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |
|
178 | this.typeset(); | |
|
179 | 179 | this.element.find('div.text_cell_input').hide(); |
|
180 | 180 | this.element.find("div.text_cell_render").show(); |
|
181 | 181 | this.rendered = true; |
@@ -201,7 +201,7 b' var IPython = (function (IPython) {' | |||
|
201 | 201 | if (text === "") { text = this.placeholder; } |
|
202 | 202 | var html = IPython.markdown_converter.makeHtml(text); |
|
203 | 203 | this.set_rendered(html); |
|
204 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |
|
204 | this.typeset() | |
|
205 | 205 | this.element.find('div.text_cell_input').hide(); |
|
206 | 206 | this.element.find("div.text_cell_render").show(); |
|
207 | 207 | var code_snippets = this.element.find("pre > code"); |
@@ -255,7 +255,7 b' var IPython = (function (IPython) {' | |||
|
255 | 255 | |
|
256 | 256 | RSTCell.prototype.handle_render = function (data, status, xhr) { |
|
257 | 257 | this.set_rendered(data); |
|
258 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |
|
258 | this.typeset(); | |
|
259 | 259 | this.rendered = true; |
|
260 | 260 | }; |
|
261 | 261 |
@@ -6,24 +6,13 b'' | |||
|
6 | 6 | |
|
7 | 7 | <title>IPython Notebook</title> |
|
8 | 8 | |
|
9 | <!-- <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script> --> | |
|
10 |
<script type= |
|
|
9 | {% if mathjax_url %} | |
|
10 | <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script> | |
|
11 | {% end %} | |
|
11 | 12 | <script type="text/javascript"> |
|
12 | function CheckMathJax(){ | |
|
13 | var div=document.getElementById("MathJaxFetchingWarning") | |
|
14 | if(window.MathJax){ | |
|
15 | document.body.removeChild(div) | |
|
16 | } | |
|
17 | else{ | |
|
18 | div.style.display = "block"; | |
|
19 | } | |
|
20 | } | |
|
21 | if (typeof MathJax == 'undefined') { | |
|
22 | console.log("No local MathJax, loading from CDN"); | |
|
23 | document.write(unescape("%3Cscript type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js%3Fconfig=TeX-AMS_HTML' charset='utf-8'%3E%3C/script%3E")); | |
|
24 | }else{ | |
|
25 | console.log("Using local MathJax"); | |
|
26 | } | |
|
13 | // MathJax disabled, set as null to distingish from *missing* MathJax, | |
|
14 | // where it will be undefined, and should prompt a dialog later. | |
|
15 | window.mathjax_url = "{{mathjax_url}}"; | |
|
27 | 16 | </script> |
|
28 | 17 | |
|
29 | 18 | <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" /> |
@@ -45,7 +34,7 b'' | |||
|
45 | 34 | |
|
46 | 35 | </head> |
|
47 | 36 | |
|
48 | <body onload='CheckMathJax();' | |
|
37 | <body | |
|
49 | 38 | data-project={{project}} data-notebook-id={{notebook_id}} |
|
50 | 39 | data-base-project-url={{base_project_url}} data-base-kernel-url={{base_kernel_url}} |
|
51 | 40 | > |
@@ -71,29 +60,6 b'' | |||
|
71 | 60 | <span id="kernel_status">Idle</span> |
|
72 | 61 | </div> |
|
73 | 62 | |
|
74 | <div id="MathJaxFetchingWarning" | |
|
75 | style="width:80%; margin:auto;padding-top:20%;text-align: justify; display:none"> | |
|
76 | <p style="font-size:26px;">There was an issue trying to fetch MathJax.js | |
|
77 | from the internet.</p> | |
|
78 | ||
|
79 | <p style="padding:0.2em"> With a working internet connection, you can run | |
|
80 | the following at a Python or IPython prompt, which will install a local | |
|
81 | copy of MathJax:</p> | |
|
82 | ||
|
83 | <pre style="background-color:lightblue;border:thin silver solid;padding:0.4em"> | |
|
84 | from IPython.external import mathjax; mathjax.install_mathjax() | |
|
85 | </pre> | |
|
86 | This will try to install MathJax into the directory where you installed | |
|
87 | IPython. If you installed IPython to a location that requires | |
|
88 | administrative privileges to write, you will need to make this call as | |
|
89 | an administrator. On OSX/Linux/Unix, this can be done at the | |
|
90 | command-line via: | |
|
91 | <pre style="background-color:lightblue;border:thin silver solid;padding:0.4em"> | |
|
92 | sudo python -c "from IPython.external import mathjax; mathjax.install_mathjax()" | |
|
93 | </pre> | |
|
94 | </p> | |
|
95 | </div> | |
|
96 | ||
|
97 | 63 | <div id="main_app"> |
|
98 | 64 | |
|
99 | 65 | <div id="left_panel"> |
General Comments 0
You need to be logged in to leave comments.
Login now