##// END OF EJS Templates
Changes to Math class and added Latex class....
Brian Granger -
Show More
@@ -298,6 +298,13 b' class HTML(DisplayObject):'
298 298 class Math(DisplayObject):
299 299
300 300 def _repr_latex_(self):
301 s = self.data.strip('$')
302 return "$$%s$$" % s
303
304
305 class Latex(DisplayObject):
306
307 def _repr_latex_(self):
301 308 return self.data
302 309
303 310
@@ -524,7 +524,8 b' class LatexFormatter(BaseFormatter):'
524 524 this.
525 525
526 526 The return value of this formatter should be a valid LaTeX equation,
527 enclosed in either ```$``` or ```$$```.
527 enclosed in either ```$```, ```$$``` or another LaTeX equation
528 environment.
528 529 """
529 530 format_type = Unicode('text/latex')
530 531
@@ -855,7 +855,7 b''
855 855 "Note that this is *different* from the above examples. Above we were typing mathematical expressions",
856 856 "in Markdown cells (along with normal text) and letting the browser render them; now we are displaying",
857 857 "the output of a Python computation as a LaTeX expression wrapped by the `Math()` object so the browser",
858 "renders it:"
858 "renders it. The `Math` object will add the needed LaTeX delimiters (`$$`) if they are not provided:"
859 859 ]
860 860 },
861 861 {
@@ -863,22 +863,59 b''
863 863 "collapsed": false,
864 864 "input": [
865 865 "from IPython.core.display import Math",
866 "Math(r'$F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx$')"
866 "Math(r'F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx')"
867 867 ],
868 868 "language": "python",
869 869 "outputs": [
870 870 {
871 871 "latex": [
872 "$F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx$"
872 "$$F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx$$"
873 873 ],
874 874 "output_type": "pyout",
875 "prompt_number": 8,
875 "prompt_number": 1,
876 876 "text": [
877 "<IPython.core.display.Math at 0x45840d0>"
877 "<IPython.core.display.Math object at 0x10ad35e90>"
878 878 ]
879 879 }
880 880 ],
881 "prompt_number": 8
881 "prompt_number": 1
882 },
883 {
884 "cell_type": "markdown",
885 "source": [
886 "With the `Latex` class, you have to include the delimiters yourself. This allows you to use other LaTeX modes such as `eqnarray`:"
887 ]
888 },
889 {
890 "cell_type": "code",
891 "collapsed": false,
892 "input": [
893 "from IPython.core.display import Latex",
894 "Latex(r\"\"\"\\begin{eqnarray}",
895 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\",
896 "\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\",
897 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\",
898 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 ",
899 "\\end{eqnarray}\"\"\")"
900 ],
901 "language": "python",
902 "outputs": [
903 {
904 "latex": [
905 "\\begin{eqnarray}",
906 "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\",
907 "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\",
908 "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 ",
909 "\\end{eqnarray}"
910 ],
911 "output_type": "pyout",
912 "prompt_number": 5,
913 "text": [
914 "<IPython.core.display.Latex object at 0x109a38790>"
915 ]
916 }
917 ],
918 "prompt_number": 5
882 919 },
883 920 {
884 921 "cell_type": "markdown",
General Comments 0
You need to be logged in to leave comments. Login now