##// END OF EJS Templates
Merge branch 'mathjax' of https://github.com/minrk/ipython into minrk-mathjax
Brian E. Granger -
r4664:2213211c merge
parent child Browse files
Show More
@@ -0,0 +1,82
1 """Utility function for installing MathJax javascript library into
2 the notebook's 'static' directory, for offline use.
3
4 Authors:
5
6 * Min RK
7 """
8
9 #-----------------------------------------------------------------------------
10 # Copyright (C) 2008-2011 The IPython Development Team
11 #
12 # Distributed under the terms of the BSD License. The full license is in
13 # the file COPYING, distributed as part of this software.
14 #-----------------------------------------------------------------------------
15
16 #-----------------------------------------------------------------------------
17 # Imports
18 #-----------------------------------------------------------------------------
19
20 import os
21 import shutil
22 import urllib2
23 import tempfile
24 import tarfile
25
26 from IPython.frontend.html import notebook as nbmod
27
28 #-----------------------------------------------------------------------------
29 # Imports
30 #-----------------------------------------------------------------------------
31
32 def install_mathjax(tag='v1.1', replace=False):
33 """Download and install MathJax for offline use.
34
35 This will install mathjax to the 'static' dir in the IPython notebook
36 package, so it will fail if the caller does not have write access
37 to that location.
38
39 MathJax is a ~15MB download, and ~150MB installed.
40
41 Parameters
42 ----------
43
44 replace : bool [False]
45 Whether to remove and replace an existing install.
46 tag : str ['v1.1']
47 Which tag to download. Default is 'v1.1', the current stable release,
48 but alternatives include 'v1.1a' and 'master'.
49 """
50 mathjax_url = "https://github.com/mathjax/MathJax/tarball/%s"%tag
51
52 nbdir = os.path.dirname(os.path.abspath(nbmod.__file__))
53 static = os.path.join(nbdir, 'static')
54 dest = os.path.join(static, 'mathjax')
55
56 # check for existence and permissions
57 if not os.access(static, os.W_OK):
58 raise IOError("Need have write access to %s"%static)
59 if os.path.exists(dest):
60 if replace:
61 if not os.access(dest, os.W_OK):
62 raise IOError("Need have write access to %s"%dest)
63 print "removing previous MathJax install"
64 shutil.rmtree(dest)
65 else:
66 print "offline MathJax apparently already installed"
67 return
68
69 # download mathjax
70 print "Downloading mathjax source..."
71 response = urllib2.urlopen(mathjax_url)
72 print "done"
73 # use 'r|gz' stream mode, because socket file-like objects can't seek:
74 tar = tarfile.open(fileobj=response.fp, mode='r|gz')
75 topdir = tar.firstmember.path
76 print "Extracting to %s"%dest
77 tar.extractall(static)
78 # it will be mathjax-MathJax-<sha>, rename to just mathjax
79 os.rename(os.path.join(static, topdir), dest)
80
81
82 __all__ = ['install_mathjax']
@@ -1,11 +1,12
1 1 build
2 2 dist
3 3 _build
4 4 docs/man/*.gz
5 5 docs/source/api/generated
6 6 docs/gh-pages
7 IPython/frontend/html/notebook/static/mathjax
7 8 *.py[co]
8 9 build
9 10 *.egg-info
10 11 *~
11 12 *.bak
@@ -1,242 +1,244
1 1 <!DOCTYPE HTML>
2 2 <html>
3 3
4 4 <head>
5 5 <meta charset="utf-8">
6 6
7 7 <title>IPython Notebook</title>
8 8
9 9 <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" />
10 10 <!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
11 11 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.14.custom.css" type="text/css" />-->
12 12
13 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script>
14 <!-- <script type='text/javascript' src='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script> -->
13 <!-- <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script> -->
14 <script type='text/javascript' src='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script>
15 15 <script type="text/javascript">
16 16 if (typeof MathJax == 'undefined') {
17 console.log("Trying to load local copy of MathJax");
18 document.write(unescape("%3Cscript type='text/javascript' src='static/mathjax/MathJax.js%3Fconfig=TeX-AMS_HTML' charset='utf-8'%3E%3C/script%3E"));
17 console.log("No local MathJax, loading from CDN");
18 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"));
19 }else{
20 console.log("Using local MathJax");
19 21 }
20 22 </script>
21 23
22 24 <link rel="stylesheet" href="static/codemirror-2.12/lib/codemirror.css">
23 25 <link rel="stylesheet" href="static/codemirror-2.12/mode/rst/rst.css">
24 26 <link rel="stylesheet" href="static/codemirror-2.12/theme/ipython.css">
25 27 <link rel="stylesheet" href="static/codemirror-2.12/theme/default.css">
26 28
27 29 <link rel="stylesheet" href="static/prettify/prettify.css"/>
28 30
29 31 <link rel="stylesheet" href="static/css/boilerplate.css" type="text/css" />
30 32 <link rel="stylesheet" href="static/css/layout.css" type="text/css" />
31 33 <link rel="stylesheet" href="static/css/base.css" type="text/css" />
32 34 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
33 35 <link rel="stylesheet" href="static/css/renderedhtml.css" type="text/css" />
34 36
35 37
36 38 </head>
37 39
38 40 <body>
39 41
40 42 <div id="header">
41 43 <span id="ipython_notebook"><h1>IPython Notebook</h1></span>
42 44 <span id="save_widget">
43 45 <input type="text" id="notebook_name" size="20"></textarea>
44 46 <span id="notebook_id" style="display:none">{{notebook_id}}</span>
45 47 <button id="save_notebook"><u>S</u>ave</button>
46 48 </span>
47 49 <span id="kernel_status">Idle</span>
48 50 </div>
49 51
50 52 <div id="main_app">
51 53
52 54 <div id="left_panel">
53 55
54 56 <div id="notebook_section">
55 57 <h3 class="section_header">Notebook</h3>
56 58 <div class="section_content">
57 59 <div class="section_row">
58 60 <span id="new_open" class="section_row_buttons">
59 61 <button id="new_notebook">New</button>
60 62 <button id="open_notebook">Open</button>
61 63 </span>
62 64 <span class="section_row_header">Actions</span>
63 65 </div>
64 66 <div class="section_row">
65 67 <span>
66 68 <select id="download_format">
67 69 <option value="json">ipynb</option>
68 70 <option value="py">py</option>
69 71 </select>
70 72 </span>
71 73 <span class="section_row_buttons">
72 74 <button id="download_notebook">Download</button>
73 75 </span>
74 76 </div>
75 77 <div class="section_row">
76 78 <span class="section_row_buttons">
77 79 <span id="print_widget">
78 80 <button id="print_notebook">Print</button>
79 81 </span>
80 82 </span>
81 83 </div>
82 84 </div>
83 85 </div>
84 86
85 87 <div id="cell_section">
86 88 <h3 class="section_header">Cell</h3>
87 89 <div class="section_content">
88 90 <div class="section_row">
89 91 <span class="section_row_buttons">
90 92 <button id="delete_cell"><u>D</u>elete</button>
91 93 </span>
92 94 <span class="section_row_header">Actions</span>
93 95 </div>
94 96 <div class="section_row">
95 97 <span id="cell_type" class="section_row_buttons">
96 98 <button id="to_code"><u>C</u>ode</button>
97 99 <!-- <button id="to_html">HTML</button>-->
98 100 <button id="to_markdown"><u>M</u>arkdown</button>
99 101 </span>
100 102 <span class="button_label">Format</span>
101 103 </div>
102 104 <div class="section_row">
103 105 <span id="cell_output" class="section_row_buttons">
104 106 <button id="toggle_output"><u>T</u>oggle</button>
105 107 <button id="clear_all_output">ClearAll</button>
106 108 </span>
107 109 <span class="button_label">Output</span>
108 110 </div>
109 111 <div class="section_row">
110 112 <span id="insert" class="section_row_buttons">
111 113 <button id="insert_cell_above"><u>A</u>bove</button>
112 114 <button id="insert_cell_below"><u>B</u>elow</button>
113 115 </span>
114 116 <span class="button_label">Insert</span>
115 117 </div>
116 118 <div class="section_row">
117 119 <span id="move" class="section_row_buttons">
118 120 <button id="move_cell_up">Up</button>
119 121 <button id="move_cell_down">Down</button>
120 122 </span>
121 123 <span class="button_label">Move</span>
122 124 </div>
123 125 <div class="section_row">
124 126 <span id="run_cells" class="section_row_buttons">
125 127 <button id="run_selected_cell">Selected</button>
126 128 <button id="run_all_cells">All</button>
127 129 </span>
128 130 <span class="button_label">Run</span>
129 131 </div>
130 132 <div class="section_row">
131 133 <span id="autoindent_span">
132 134 <input type="checkbox" id="autoindent" checked="true"></input>
133 135 </span>
134 136 <span class="checkbox_label">Autoindent:</span>
135 137 </div>
136 138 </div>
137 139 </div>
138 140
139 141 <div id="kernel_section">
140 142 <h3 class="section_header">Kernel</h3>
141 143 <div class="section_content">
142 144 <div class="section_row">
143 145 <span id="int_restart" class="section_row_buttons">
144 146 <button id="int_kernel">Interrupt</button>
145 147 <button id="restart_kernel">Restart</button>
146 148 </span>
147 149 <span class="section_row_header">Actions</span>
148 150 </div>
149 151 <div class="section_row">
150 152 <span id="kernel_persist">
151 153 <input type="checkbox" id="kill_kernel"></input>
152 154 </span>
153 155 <span class="checkbox_label">Kill kernel upon exit:</span>
154 156 </div>
155 157 </div>
156 158 </div>
157 159
158 160 <div id="help_section">
159 161 <h3 class="section_header">Help</h3>
160 162 <div class="section_content">
161 163 <div class="section_row">
162 164 <span id="help_buttons0" class="section_row_buttons">
163 165 <a id="python_help" href="http://docs.python.org" target="_blank">Python</a>
164 166 <a id="ipython_help" href="http://ipython.org/documentation.html" target="_blank">IPython</a>
165 167 </span>
166 168 <span class="section_row_header">Links</span>
167 169 </div>
168 170 <div class="section_row">
169 171 <span id="help_buttons1" class="section_row_buttons">
170 172 <a id="numpy_help" href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a>
171 173 <a id="scipy_help" href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a>
172 174 </span>
173 175 </div>
174 176 <div class="section_row">
175 177 <span id="help_buttons2" class="section_row_buttons">
176 178 <a id="matplotlib_help" href="http://matplotlib.sourceforge.net/" target="_blank">MPL</a>
177 179 <a id="sympy_help" href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a>
178 180 </span>
179 181 </div>
180 182 <div class="section_row">
181 183 <span class="help_string">run selected cell</span>
182 184 <span class="help_string_label">Shift-Enter :</span>
183 185 </div>
184 186 <div class="section_row">
185 187 <span class="help_string">run in terminal mode</span>
186 188 <span class="help_string_label">Ctrl-Enter :</span>
187 189 </div>
188 190 <div class="section_row">
189 191 <span class="help_string">show keyboard shortcuts</span>
190 192 <span class="help_string_label">Ctrl-m h :</span>
191 193 </div>
192 194 </div>
193 195 </div>
194 196
195 197 </div>
196 198 <div id="left_panel_splitter"></div>
197 199 <div id="notebook_panel">
198 200 <div id="notebook"></div>
199 201 <div id="pager_splitter"></div>
200 202 <div id="pager"></div>
201 203 </div>
202 204
203 205 </div>
204 206
205 207 <script src="static/jquery/js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
206 208 <script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
207 209 <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script>
208 210
209 211 <script src="static/codemirror-2.12/lib/codemirror.js" charset="utf-8"></script>
210 212 <script src="static/codemirror-2.12/mode/python/python.js" charset="utf-8"></script>
211 213 <script src="static/codemirror-2.12/mode/htmlmixed/htmlmixed.js" charset="utf-8"></script>
212 214 <script src="static/codemirror-2.12/mode/xml/xml.js" charset="utf-8"></script>
213 215 <script src="static/codemirror-2.12/mode/javascript/javascript.js" charset="utf-8"></script>
214 216 <script src="static/codemirror-2.12/mode/css/css.js" charset="utf-8"></script>
215 217 <script src="static/codemirror-2.12/mode/rst/rst.js" charset="utf-8"></script>
216 218
217 219 <script src="static/pagedown/Markdown.Converter.js" charset="utf-8"></script>
218 220
219 221 <script src="static/prettify/prettify.js" charset="utf-8"></script>
220 222
221 223 <script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
222 224 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
223 225 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
224 226 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
225 227 <script src="static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
226 228 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
227 229 <script src="static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
228 230 <script src="static/js/layout.js" type="text/javascript" charset="utf-8"></script>
229 231 <script src="static/js/savewidget.js" type="text/javascript" charset="utf-8"></script>
230 232 <script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script>
231 233 <script src="static/js/panelsection.js" type="text/javascript" charset="utf-8"></script>
232 234 <script src="static/js/printwidget.js" type="text/javascript" charset="utf-8"></script>
233 235 <script src="static/js/leftpanel.js" type="text/javascript" charset="utf-8"></script>
234 236 <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
235 237 <script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script>
236 238
237 239
238 240 </body>
239 241
240 242 </html>
241 243
242 244
General Comments 0
You need to be logged in to leave comments. Login now