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 |
@@ -1091,6 +1091,53 b'' | |||||
1091 | "cell_type": "markdown", |
|
1091 | "cell_type": "markdown", | |
1092 | "metadata": {}, |
|
1092 | "metadata": {}, | |
1093 | "source": [ |
|
1093 | "source": [ | |
|
1094 | "Or you can enter latex directly with the `%%latex` cell magic:" | |||
|
1095 | ] | |||
|
1096 | }, | |||
|
1097 | { | |||
|
1098 | "cell_type": "code", | |||
|
1099 | "collapsed": false, | |||
|
1100 | "input": [ | |||
|
1101 | "%%latex\n", | |||
|
1102 | "\\begin{aligned}\n", | |||
|
1103 | "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n", | |||
|
1104 | "\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n", | |||
|
1105 | "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n", | |||
|
1106 | "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n", | |||
|
1107 | "\\end{aligned}" | |||
|
1108 | ], | |||
|
1109 | "language": "python", | |||
|
1110 | "metadata": {}, | |||
|
1111 | "outputs": [ | |||
|
1112 | { | |||
|
1113 | "latex": [ | |||
|
1114 | "\\begin{aligned}\n", | |||
|
1115 | "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n", | |||
|
1116 | "\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n", | |||
|
1117 | "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n", | |||
|
1118 | "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n", | |||
|
1119 | "\\end{aligned}" | |||
|
1120 | ], | |||
|
1121 | "output_type": "display_data", | |||
|
1122 | "text": [ | |||
|
1123 | "<IPython.core.display.Latex at 0x10a617c90>" | |||
|
1124 | ] | |||
|
1125 | } | |||
|
1126 | ], | |||
|
1127 | "prompt_number": 12 | |||
|
1128 | }, | |||
|
1129 | { | |||
|
1130 | "cell_type": "markdown", | |||
|
1131 | "metadata": {}, | |||
|
1132 | "source": [ | |||
|
1133 | "There is also a `%%javascript` cell magic for running javascript directly,\n", | |||
|
1134 | "and `%%svg` for manually entering SVG content." | |||
|
1135 | ] | |||
|
1136 | }, | |||
|
1137 | { | |||
|
1138 | "cell_type": "markdown", | |||
|
1139 | "metadata": {}, | |||
|
1140 | "source": [ | |||
1094 | "# Loading external codes\n", |
|
1141 | "# Loading external codes\n", | |
1095 | "* Drag and drop a ``.py`` in the dashboard\n", |
|
1142 | "* Drag and drop a ``.py`` in the dashboard\n", | |
1096 | "* Use ``%load`` with any local or remote url: [the Matplotlib Gallery!](http://matplotlib.sourceforge.net/gallery.html)\n", |
|
1143 | "* Use ``%load`` with any local or remote url: [the Matplotlib Gallery!](http://matplotlib.sourceforge.net/gallery.html)\n", |
General Comments 0
You need to be logged in to leave comments.
Login now