{ "cell_id": 7261669791396587189, "cells": [ { "cell_id": 1335784694978485978, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 13774751629423835658, "cell_origin": "client", "cell_type": "latex_view", "source": "\\section*{Printing expressions in various formats}\n\\subsection*{Basic usage}\n\nWith basic use of Cadabra, you will typically display your expressions by postfixing them with a semi-colon,\nas in" } ], "hidden": true, "source": "\\section*{Printing expressions in various formats}\n\\subsection*{Basic usage}\n\nWith basic use of Cadabra, you will typically display your expressions by postfixing them with a semi-colon,\nas in" }, { "cell_id": 4599574666662704559, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 7976412321546991870, "cell_origin": "server", "cell_type": "latex_view", "cells": [ { "cell_id": 13420704756796341992, "cell_origin": "server", "cell_type": "input_form", "source": "A_{m n} (B^{n} + 3C^{n})" } ], "source": "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" } ], "source": "ex:=A_{m n} ( B^{n} + 3 C^{n} );" }, { "cell_id": 11217211748193580653, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 16995084653280955185, "cell_origin": "client", "cell_type": "latex_view", "source": "What happens behind the scenes is that the semi-colon gets translated to a call of \\verb|display| on the \nlast-entered expression. It is therefore equivalent to " } ], "hidden": true, "source": "What happens behind the scenes is that the semi-colon gets translated to a call of \\verb|display| on the \nlast-entered expression. It is therefore equivalent to " }, { "cell_id": 3194216578733920776, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 8711371366818187662, "cell_origin": "server", "cell_type": "latex_view", "cells": [ { "cell_id": 15759111152906086906, "cell_origin": "server", "cell_type": "input_form", "source": "A_{m n} (B^{n} + 3C^{n})" } ], "source": "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" } ], "source": "display(ex)" }, { "cell_id": 1576921483409930500, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 17726338938474972989, "cell_origin": "client", "cell_type": "latex_view", "source": "If you do not want to display the expression, post-fix with a colon, as in" } ], "hidden": true, "source": "If you do not want to display the expression, post-fix with a colon, as in" }, { "cell_id": 14523255289624488569, "cell_origin": "client", "cell_type": "input", "source": "ex:=A_{m n} ( B^{n} + 3 C^{n} ):" }, { "cell_id": 11294718848976823186, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 14337180194863693573, "cell_origin": "client", "cell_type": "latex_view", "source": "If you want to display an expression again later, you can just write the name of the expression followed\nby a semi-colon, or use the \\verb|display| function again," } ], "hidden": true, "source": "If you want to display an expression again later, you can just write the name of the expression followed\nby a semi-colon, or use the \\verb|display| function again," }, { "cell_id": 6496143034130397257, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 6581067180774934363, "cell_origin": "server", "cell_type": "latex_view", "cells": [ { "cell_id": 851282864835364026, "cell_origin": "server", "cell_type": "input_form", "source": "A_{m n} (B^{n} + 3C^{n})" } ], "source": "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" }, { "cell_id": 2901413102110827379, "cell_origin": "server", "cell_type": "latex_view", "cells": [ { "cell_id": 12388802728969897063, "cell_origin": "server", "cell_type": "input_form", "source": "A_{m n} (B^{n} + 3C^{n})" } ], "source": "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" } ], "source": "ex;\ndisplay(ex)" }, { "cell_id": 7456309133359305085, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 16939468648029991255, "cell_origin": "client", "cell_type": "latex_view", "source": "Note that while it may be tempting to use \\verb|print(ex)|, the \\verb|display| function is better because\nit knows about the capabilities of the interface used, and it will automatically select a text output when\nyou use Cadabra from the terminal, or \\LaTeX{} output when you use it in the graphical notebook." } ], "hidden": true, "source": "Note that while it may be tempting to use \\verb|print(ex)|, the \\verb|display| function is better because\nit knows about the capabilities of the interface used, and it will automatically select a text output when\nyou use Cadabra from the terminal, or \\LaTeX{} output when you use it in the graphical notebook." }, { "cell_id": 18063100663122690440, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 14453290597389549787, "cell_origin": "client", "cell_type": "latex_view", "source": "\\subsection*{Other output formats}\n\nCadabra expressions are standard Python objects, and as such they have a \\verb|__str__| method which\nconverts them into a printable expression, and a \\verb|__repr__| method to produce a machine readable form.\nThese are called by the standard \\verb|str| and \\verb|repr| Python functions, as the examples below show." } ], "hidden": true, "source": "\\subsection*{Other output formats}\n\nCadabra expressions are standard Python objects, and as such they have a \\verb|__str__| method which\nconverts them into a printable expression, and a \\verb|__repr__| method to produce a machine readable form.\nThese are called by the standard \\verb|str| and \\verb|repr| Python functions, as the examples below show." }, { "cell_id": 8738598843828149956, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 5848166511316712933, "cell_origin": "server", "cell_type": "output", "source": "\\begin{verbatim}A_{m n} (B^{n} + 3C^{n})\n\\end{verbatim}" } ], "source": "print(str(ex))" }, { "cell_id": 5497430364262302497, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 10342375366145359860, "cell_origin": "server", "cell_type": "output", "source": "\\begin{verbatim}\\prod(A_{m n})(\\sum(B^{n})(3C^{n}))\n\\end{verbatim}" } ], "source": "print(repr(ex))" }, { "cell_id": 5790729180904443240, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 17965245563481981014, "cell_origin": "client", "cell_type": "latex_view", "source": "In addition there are some methods to obtain output useful in other software: Mathematica, \\LaTeX{} and Sympy:" } ], "hidden": true, "source": "In addition there are some methods to obtain output useful in other software: Mathematica, \\LaTeX{} and Sympy:" }, { "cell_id": 3952585365066537497, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 10790437579665738397, "cell_origin": "server", "cell_type": "output", "source": "\\begin{verbatim}A[DNm, DNn]*(B[UPn]+3*C[UPn])\n\\end{verbatim}" } ], "source": "print(ex.mma_form())" }, { "cell_id": 11925500088449724665, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 16001190812359436598, "cell_origin": "server", "cell_type": "output", "source": "\\begin{verbatim}A_{m n} \\left(B^{n}+3C^{n}\\right)\n\\end{verbatim}" } ], "source": "print(ex._latex_())" }, { "cell_id": 14583738995864140787, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 10144197596267121994, "cell_origin": "server", "cell_type": "output", "source": "\\begin{verbatim}A(DNm, DNn)*(B(UPn)+3*C(UPn))\n\\end{verbatim}" } ], "source": "print(ex.sympy_form())" }, { "cell_id": 13609528241788494400, "cell_origin": "client", "cell_type": "latex", "cells": [ { "cell_id": 1104115635541465770, "cell_origin": "client", "cell_type": "latex_view", "source": "\\subsection*{Printing custom LaTeX}\n\nIf you want to make sure that a string which you have created \"by hand\" will be processed by LaTeX\nand display in typeset form, use the `\\verb|LaTeXString|` object. This is essentially a normal \nstring, but \"tagged\" with the information that it contains LaTeX code." } ], "hidden": true, "source": "\\subsection*{Printing custom LaTeX}\n\nIf you want to make sure that a string which you have created \"by hand\" will be processed by LaTeX\nand display in typeset form, use the `\\verb|LaTeXString|` object. This is essentially a normal \nstring, but \"tagged\" with the information that it contains LaTeX code." }, { "cell_id": 13166633816324467370, "cell_origin": "client", "cell_type": "input", "cells": [ { "cell_id": 8306092681814010685, "cell_origin": "server", "cell_type": "latex_view", "source": "\\begin{dmath*}{}\\int_{-\\infty}^\\infty \\exp\\left[ -a x^2 \\right] {\\rm d} x\\end{dmath*}" } ], "source": "s = LaTeXString(r\"\\int_{-\\infty}^\\infty \\exp\\left[ -a x^2 \\right] {\\rm d} x\");" }, { "cell_id": 1025447284169640934, "cell_origin": "client", "cell_type": "input", "source": "" } ], "description": "Cadabra JSON notebook format", "version": 1.0 }