##// END OF EJS Templates
a few fixes...
Matthias BUSSONNIER -
Show More
@@ -1,6 +1,12 b''
1 """Utility function for installing MathJax javascript library into
1 """Utility function for installing MathJax javascript library into
2 the notebook's 'static' directory, for offline use.
2 the notebook's 'static' directory, for offline use.
3
3
4 Authors:
5
6 * Min RK
7 * Mark Sienkiewicz
8 * Matthias Bussonnier
9
4 To download and install MathJax:
10 To download and install MathJax:
5
11
6 From Python:
12 From Python:
@@ -33,11 +39,6 b' To find the directory where IPython would like MathJax installed:'
33 # the file COPYING, distributed as part of this software.
39 # the file COPYING, distributed as part of this software.
34 #-----------------------------------------------------------------------------
40 #-----------------------------------------------------------------------------
35
41
36 # Authors:
37 #
38 # * Min RK
39 # * Mark Sienkiewicz at Space Telescope Science Institute (command line invocation)
40 #
41
42
42 #-----------------------------------------------------------------------------
43 #-----------------------------------------------------------------------------
43 # Imports
44 # Imports
@@ -50,16 +51,13 b' import tarfile'
50 import urllib2
51 import urllib2
51 import zipfile
52 import zipfile
52
53
53 from IPython.frontend.html import notebook as nbmod
54
55 #-----------------------------------------------------------------------------
54 #-----------------------------------------------------------------------------
56 #
55 #
57 #-----------------------------------------------------------------------------
56 #-----------------------------------------------------------------------------
58
57
59 # Where mathjax will be installed.
58 # Where mathjax will be installed.
60
59
61 static = os.path.join(os.path.dirname(os.path.abspath(nbmod.__file__)), 'static')
60 dest = os.path.join(locate_profile('default'), 'static')
62 dest = os.path.join(static, 'mathjax')
63
61
64 ##
62 ##
65
63
@@ -67,11 +65,11 b" dest = os.path.join(static, 'mathjax')"
67
65
68 def check_perms(replace=False):
66 def check_perms(replace=False):
69 if not os.access(static, os.W_OK):
67 if not os.access(static, os.W_OK):
70 raise IOError("Need have write access to %s"%static)
68 raise IOError("Need have write access to %s" % static)
71 if os.path.exists(dest):
69 if os.path.exists(dest):
72 if replace:
70 if replace:
73 if not os.access(dest, os.W_OK):
71 if not os.access(dest, os.W_OK):
74 raise IOError("Need have write access to %s"%dest)
72 raise IOError("Need have write access to %s" % dest)
75 print "removing previous MathJax install"
73 print "removing previous MathJax install"
76 shutil.rmtree(dest)
74 shutil.rmtree(dest)
77 return True
75 return True
@@ -116,8 +114,8 b' def extract_zip( fd, dest ) :'
116
114
117 ##
115 ##
118
116
119 def install_mathjax(tag='v1.1', replace=False, fd=None, extractor=extract_tar ):
117 def install_mathjax(tag='v2.0', replace=False, file=None, extractor=extract_tar ):
120 """Download and install MathJax for offline use.
118 """Download and/or install MathJax for offline use.
121
119
122 This will install mathjax to the 'static' dir in the IPython notebook
120 This will install mathjax to the 'static' dir in the IPython notebook
123 package, so it will fail if the caller does not have write access
121 package, so it will fail if the caller does not have write access
@@ -130,20 +128,24 b" def install_mathjax(tag='v1.1', replace=False, fd=None, extractor=extract_tar ):"
130
128
131 replace : bool [False]
129 replace : bool [False]
132 Whether to remove and replace an existing install.
130 Whether to remove and replace an existing install.
133 tag : str ['v1.1']
131 tag : str ['v2.0']
134 Which tag to download. Default is 'v1.1', the current stable release,
132 Which tag to download. Default is 'v1.1', the current stable release,
135 but alternatives include 'v1.1a' and 'master'.
133 but alternatives include 'v1.1a' and 'master'.
134 file : file like object [ defualt to content of https://github.com/mathjax/MathJax/tarball/#{tag}]
135 File handle from which to untar/unzip/... mathjax
136 extractor : function
137 Method tu use to untar/unzip/... `file`
136 """
138 """
137
139
138 if not check_perms(replace) :
140 if not check_perms(replace) :
139 return
141 return
140
142
141 if fd is None :
143 if file is None :
142 # download mathjax
144 # download mathjax
143 mathjax_url = "https://github.com/mathjax/MathJax/tarball/%s"%tag
145 mathjax_url = "https://github.com/mathjax/MathJax/tarball/%s"%tag
144 print "Downloading mathjax source from %s"%mathjax_url
146 print "Downloading mathjax source from %s"%mathjax_url
145 response = urllib2.urlopen(mathjax_url)
147 response = urllib2.urlopen(mathjax_url)
146 fd = response.fp
148 file = response.fp
147
149
148 print "Extracting to %s"%dest
150 print "Extracting to %s"%dest
149 extractor( fd, dest )
151 extractor( fd, dest )
@@ -161,7 +163,7 b' def test_func( remove ) :'
161 print "ok"
163 print "ok"
162 if remove :
164 if remove :
163 shutil.rmtree( dest )
165 shutil.rmtree( dest )
164 return 0
166 return status
165
167
166 ##
168 ##
167
169
@@ -190,7 +192,7 b' def main( args ) :'
190 if '-test' in args :
192 if '-test' in args :
191 return test_func( replace )
193 return test_func( replace )
192
194
193 # do it
195 # do it
194 if len(args) == 0 :
196 if len(args) == 0 :
195 # This is compatible with the interface documented in ipython 0.13
197 # This is compatible with the interface documented in ipython 0.13
196 install_mathjax( replace=replace )
198 install_mathjax( replace=replace )
@@ -230,7 +232,7 b' python -m IPython.external.mathjax -test -r'
230
232
231 # download and install mathjax from command line:
233 # download and install mathjax from command line:
232
234
233 python -m IPython.external.mathjax
235 python -m IPython.external.mathjax
234 python -m IPython.external.mathjax -test -r
236 python -m IPython.external.mathjax -test -r
235
237
236 # download and install from within python
238 # download and install from within python
@@ -249,14 +251,14 b' python -m IPython.external.mathjax -test -r'
249 # (this is the url used internally by install_mathjax)
251 # (this is the url used internally by install_mathjax)
250 # The file it offers is mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
252 # The file it offers is mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
251
253
252 python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
254 python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
253
255
254 python -m IPython.external.mathjax -test
256 python -m IPython.external.mathjax -test
255 # note no -r
257 # note no -r
256
258
257 # install it again while it is already there
259 # install it again while it is already there
258
260
259 python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
261 python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
260 # says "offline MathJax apparently already installed"
262 # says "offline MathJax apparently already installed"
261
263
262 python -m IPython.external.mathjax ~/mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
264 python -m IPython.external.mathjax ~/mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz
@@ -357,8 +357,9 b' For unusual needs, IPython can tell you what directory it wants to find MathJax '
357
357
358 python -m IPython.external.mathjax -d
358 python -m IPython.external.mathjax -d
359
359
360 All of these options require write access to the IPython install directory, so if
360 By default Mathjax will be installed in your ipython profile directory, but you
361 you have a system-wide Python install, it may need to be done with ``sudo``.
361 can make system wide install, please refere to the documentation and helper function
362 of IPython.external.mathjax
362
363
363 Browser Compatibility
364 Browser Compatibility
364 ---------------------
365 ---------------------
General Comments 0
You need to be logged in to leave comments. Login now