##// END OF EJS Templates
a few fixes...
Matthias BUSSONNIER -
Show More
@@ -1,6 +1,12 b''
1 1 """Utility function for installing MathJax javascript library into
2 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 10 To download and install MathJax:
5 11
6 12 From Python:
@@ -33,11 +39,6 b' To find the directory where IPython would like MathJax installed:'
33 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 44 # Imports
@@ -50,16 +51,13 b' import tarfile'
50 51 import urllib2
51 52 import zipfile
52 53
53 from IPython.frontend.html import notebook as nbmod
54
55 54 #-----------------------------------------------------------------------------
56 55 #
57 56 #-----------------------------------------------------------------------------
58 57
59 58 # Where mathjax will be installed.
60 59
61 static = os.path.join(os.path.dirname(os.path.abspath(nbmod.__file__)), 'static')
62 dest = os.path.join(static, 'mathjax')
60 dest = os.path.join(locate_profile('default'), 'static')
63 61
64 62 ##
65 63
@@ -67,11 +65,11 b" dest = os.path.join(static, 'mathjax')"
67 65
68 66 def check_perms(replace=False):
69 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 69 if os.path.exists(dest):
72 70 if replace:
73 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 73 print "removing previous MathJax install"
76 74 shutil.rmtree(dest)
77 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 ):
120 """Download and install MathJax for offline use.
117 def install_mathjax(tag='v2.0', replace=False, file=None, extractor=extract_tar ):
118 """Download and/or install MathJax for offline use.
121 119
122 120 This will install mathjax to the 'static' dir in the IPython notebook
123 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 129 replace : bool [False]
132 130 Whether to remove and replace an existing install.
133 tag : str ['v1.1']
131 tag : str ['v2.0']
134 132 Which tag to download. Default is 'v1.1', the current stable release,
135 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 140 if not check_perms(replace) :
139 141 return
140 142
141 if fd is None :
143 if file is None :
142 144 # download mathjax
143 145 mathjax_url = "https://github.com/mathjax/MathJax/tarball/%s"%tag
144 146 print "Downloading mathjax source from %s"%mathjax_url
145 147 response = urllib2.urlopen(mathjax_url)
146 fd = response.fp
148 file = response.fp
147 149
148 150 print "Extracting to %s"%dest
149 151 extractor( fd, dest )
@@ -161,7 +163,7 b' def test_func( remove ) :'
161 163 print "ok"
162 164 if remove :
163 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 192 if '-test' in args :
191 193 return test_func( replace )
192 194
193 # do it
195 # do it
194 196 if len(args) == 0 :
195 197 # This is compatible with the interface documented in ipython 0.13
196 198 install_mathjax( replace=replace )
@@ -230,7 +232,7 b' python -m IPython.external.mathjax -test -r'
230 232
231 233 # download and install mathjax from command line:
232 234
233 python -m IPython.external.mathjax
235 python -m IPython.external.mathjax
234 236 python -m IPython.external.mathjax -test -r
235 237
236 238 # download and install from within python
@@ -249,14 +251,14 b' python -m IPython.external.mathjax -test -r'
249 251 # (this is the url used internally by install_mathjax)
250 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 256 python -m IPython.external.mathjax -test
255 # note no -r
257 # note no -r
256 258
257 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 262 # says "offline MathJax apparently already installed"
261 263
262 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 358 python -m IPython.external.mathjax -d
359 359
360 All of these options require write access to the IPython install directory, so if
361 you have a system-wide Python install, it may need to be done with ``sudo``.
360 By default Mathjax will be installed in your ipython profile directory, but you
361 can make system wide install, please refere to the documentation and helper function
362 of IPython.external.mathjax
362 363
363 364 Browser Compatibility
364 365 ---------------------
General Comments 0
You need to be logged in to leave comments. Login now