##// END OF EJS Templates
add %%javascript, %%svg, and %%latex display magics...
MinRK -
Show More
@@ -0,0 +1,47 b''
1 """Simple magics for display formats"""
2 #-----------------------------------------------------------------------------
3 # Copyright (c) 2012 The IPython Development Team.
4 #
5 # Distributed under the terms of the Modified BSD License.
6 #
7 # The full license is in the file COPYING.txt, distributed with this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
13
14 # Our own packages
15 from IPython.core.display import display, Javascript, Latex, SVG
16 from IPython.core.magic import (
17 Magics, magics_class, line_magic, cell_magic
18 )
19
20 #-----------------------------------------------------------------------------
21 # Magic implementation classes
22 #-----------------------------------------------------------------------------
23
24
25 @magics_class
26 class DisplayMagics(Magics):
27 """Magics for displaying various output types with literals
28
29 Defines javascript/latex cell magics for writing blocks in those languages,
30 to be rendered in the frontend.
31 """
32
33 @cell_magic
34 def javascript(self, line, cell):
35 """Run the cell block of Javascript code"""
36 display(Javascript(cell))
37
38
39 @cell_magic
40 def latex(self, line, cell):
41 """Render the cell as a block of latex"""
42 display(Latex(cell))
43
44 @cell_magic
45 def svg(self, line, cell):
46 """Render the cell as an SVG literal"""
47 display(SVG(cell))
@@ -2040,7 +2040,7 b' class InteractiveShell(SingletonConfigurable):'
2040 self.define_magic = self.magics_manager.define_magic
2040 self.define_magic = self.magics_manager.define_magic
2041
2041
2042 self.register_magics(m.AutoMagics, m.BasicMagics, m.CodeMagics,
2042 self.register_magics(m.AutoMagics, m.BasicMagics, m.CodeMagics,
2043 m.ConfigMagics, m.DeprecatedMagics, m.ExecutionMagics,
2043 m.ConfigMagics, m.DeprecatedMagics, m.DisplayMagics, m.ExecutionMagics,
2044 m.ExtensionMagics, m.HistoryMagics, m.LoggingMagics,
2044 m.ExtensionMagics, m.HistoryMagics, m.LoggingMagics,
2045 m.NamespaceMagics, m.OSMagics, m.PylabMagics, m.ScriptMagics,
2045 m.NamespaceMagics, m.OSMagics, m.PylabMagics, m.ScriptMagics,
2046 )
2046 )
@@ -18,6 +18,7 b' from .basic import BasicMagics'
18 from .code import CodeMagics, MacroToEdit
18 from .code import CodeMagics, MacroToEdit
19 from .config import ConfigMagics
19 from .config import ConfigMagics
20 from .deprecated import DeprecatedMagics
20 from .deprecated import DeprecatedMagics
21 from .display import DisplayMagics
21 from .execution import ExecutionMagics
22 from .execution import ExecutionMagics
22 from .extension import ExtensionMagics
23 from .extension import ExtensionMagics
23 from .history import HistoryMagics
24 from .history import HistoryMagics
@@ -1092,6 +1092,53 b''
1092 "cell_type": "markdown",
1092 "cell_type": "markdown",
1093 "metadata": {},
1093 "metadata": {},
1094 "source": [
1094 "source": [
1095 "Or you can enter latex directly with the `%%latex` cell magic:"
1096 ]
1097 },
1098 {
1099 "cell_type": "code",
1100 "collapsed": false,
1101 "input": [
1102 "%%latex\n",
1103 "\\begin{aligned}\n",
1104 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n",
1105 "\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
1106 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
1107 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n",
1108 "\\end{aligned}"
1109 ],
1110 "language": "python",
1111 "metadata": {},
1112 "outputs": [
1113 {
1114 "latex": [
1115 "\\begin{aligned}\n",
1116 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n",
1117 "\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n",
1118 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n",
1119 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n",
1120 "\\end{aligned}"
1121 ],
1122 "output_type": "display_data",
1123 "text": [
1124 "<IPython.core.display.Latex at 0x10a617c90>"
1125 ]
1126 }
1127 ],
1128 "prompt_number": 12
1129 },
1130 {
1131 "cell_type": "markdown",
1132 "metadata": {},
1133 "source": [
1134 "There is also a `%%javascript` cell magic for running javascript directly,\n",
1135 "and `%%svg` for manually entering SVG content."
1136 ]
1137 },
1138 {
1139 "cell_type": "markdown",
1140 "metadata": {},
1141 "source": [
1095 "# Loading external codes\n",
1142 "# Loading external codes\n",
1096 "* Drag and drop a ``.py`` in the dashboard\n",
1143 "* Drag and drop a ``.py`` in the dashboard\n",
1097 "* Use ``%load`` with any local or remote url: [the Matplotlib Gallery!](http://matplotlib.sourceforge.net/gallery.html)\n",
1144 "* Use ``%load`` with any local or remote url: [the Matplotlib Gallery!](http://matplotlib.sourceforge.net/gallery.html)\n",
@@ -1192,4 +1239,4 b''
1192 "metadata": {}
1239 "metadata": {}
1193 }
1240 }
1194 ]
1241 ]
1195 }
1242 } No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now