def main(): """ The body of the script. """ # Initialise logging to print info to screen logging.basicConfig(level=logging.INFO) # Get locations ipython_dir = IPython.utils.path.get_ipython_dir() # Create the nbserver profile logging.info("Creating ipython profile for "+profile_name) profile_dir = os.path.join(ipython_dir, "profile_"+profile_name) run_cmd("ipython profile create "+profile_name) # Ask the user for a password; only store the hash logging.info("Configuring password") print "Enter a password to use for ipython notebook web access:" password_hash = IPython.lib.passwd() # Generate a self-signed certificate logging.info("Generating self-signed certificate for SSL encryption") certfile = os.path.join(profile_dir, "user_selfsigned_cert.pem") keyfile = os.path.join(profile_dir, "user_selfsigned_key.pem") run_cmd("yes '' | openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -keyout "+keyfile+" -out "+certfile) run_cmd("chmod 440 "+keyfile) # Install MathJax locally (into this profile) # Note that this import will fail if the default(?) profile isn't created beforehand from IPython.external.mathjax import install_mathjax mathjax_dest = os.path.join(profile_dir, 'static', 'mathjax' ) install_mathjax(dest = mathjax_dest) # Install the Table of Contents extension into this profile logging.info("Installing python notebook Table of Contents extension") extension_dir = os.path.join(profile_dir, 'static', 'nbextensions') custom_dir = os.path.join(profile_dir, 'static', 'custom') run_cmd("mkdir -p "+extension_dir) run_cmd("curl -L https://rawgithub.com/minrk/ipython_extensions/master/nbextensions/toc.js > "+os.path.join(extension_dir,"toc.js")) run_cmd("curl -L https://rawgithub.com/minrk/ipython_extensions/master/nbextensions/toc.css > "+os.path.join(extension_dir,"toc.css")) run_cmd("mkdir -p "+custom_dir) with open(os.path.join(custom_dir, "custom.js"),"wb") as f: f.write(extension_javascript) # Overwrite the default profile config with ours config_file = os.path.join(profile_dir, "ipython_notebook_config.py") logging.info("Writing nbserver config file "+config_file) with open(config_file, 'wb') as f: f.write(profile_config.format(hash = password_hash, port = ipython_port, location = ipython_location, certfile = certfile, keyfile = keyfile))
def jupyter_install_mathjax(): """ @FAQ(jupyter___Offline MathJax) By default, Jupyter uses an online version of MathJax which means the connection to internet must remain available. To import mathjax locally, you need to run the following: @code from IPython.external import mathjax mathjax.install_mathjax() @endcode @endFAQ """ from IPython.external import mathjax mathjax.install_mathjax()
warnings.filterwarnings("ignore") import numpy as NP from scipy import linalg as LA from IPython.display import display from sympy.interactive import printing import sympy as SYM from sympy import Matrix as MAT from sympy.mpmath import * printing.init_printing() from IPython.external import mathjax mathjax.install_mathjax() get_ipython().magic('matplotlib inline') from matplotlib import pyplot as PLT from matplotlib import cm as CM from mpl_toolkits import axes_grid1 as AG from mpl_toolkits.mplot3d import Axes3D as AX NP.set_printoptions(precision=3, suppress=True) PLT.rcParams['figure.figsize'] = (11.0, 7.5) my_font_config = { 'family': 'sans-serif', 'color': '#2A52BE', 'weight': 'normal', 'size': 14,
# __author__ = 'weij' # -*- coding: utf-8 -*- from IPython.external.mathjax import install_mathjax install_mathjax()
def install_mathjax(): """ install a local copy of mathjax """ from IPython.external import mathjax mathjax.install_mathjax()
from IPython.external import mathjax mathjax.install_mathjax()
#!/usr/bin/env python if __name__ == "__main__": from IPython.external import mathjax; mathjax.install_mathjax()
sympy.latex(x**2) sympy.latex(Integral(x**2, x)) preview(Integral(x**2, x)) #doctest:+SKIP from sympy import * init_printing() x, y = symbols("x,y") sqrt(x**2 + y**2) from IPython.display import Latex Latex(r"$\sqrt{x^2+y^2}$") import IPython from IPython.external.mathjax import install_mathjax install_mathjax() import sympy x = sympy.Symbol('x') f = sympy.E**x + 2 * x t = sympy.integrate(f, x) t = sympy.latex(t) sympy.latex(x**2) t = t.center(len(t) + 2, '$') # list_i = list(t) # str -> list # list_i.insert(0, '$') # 注意不用重新赋值 # list_i.insert(len(t)+1, '$') # str_i = ''.join(list_i) # list -> str