modelparameters.sympy.interactive package¶
Submodules¶
modelparameters.sympy.interactive.ipythonprinting module¶
A print function that pretty prints SymPy objects.
- moduleauthor:
Brian Granger
Usage¶
To use this extension, execute:
%load_ext sympy.interactive.ipythonprinting
Once the extension is loaded, SymPy Basic objects are automatically pretty-printed in the terminal and rendered in LaTeX in the Qt console and notebook.
modelparameters.sympy.interactive.printing module¶
Tools for setting up printing in interactive sessions.
- modelparameters.sympy.interactive.printing.init_printing(pretty_print=True, order=None, use_unicode=None, use_latex=None, wrap_line=None, num_columns=None, no_global=False, ip=None, euler=False, forecolor='Black', backcolor='Transparent', fontsize='10pt', latex_mode='equation*', print_builtin=True, str_printer=None, pretty_printer=None, latex_printer=None, **settings)[source]¶
Initializes pretty-printer depending on the environment.
- Parameters:
pretty_print (boolean) – If True, use pretty_print to stringify or the provided pretty printer; if False, use sstrrepr to stringify or the provided string printer.
order (string or None) – There are a few different settings for this parameter: lex (default), which is lexographic order; grlex, which is graded lexographic order; grevlex, which is reversed graded lexographic order; old, which is used for compatibility reasons and for long expressions; None, which sets it to lex.
use_unicode (boolean or None) – If True, use unicode characters; if False, do not use unicode characters.
use_latex (string, boolean, or None) – If True, use default latex rendering in GUI interfaces (png and mathjax); if False, do not use latex rendering; if ‘png’, enable latex rendering with an external latex compiler, falling back to matplotlib if external compilation fails; if ‘matplotlib’, enable latex rendering with matplotlib; if ‘mathjax’, enable latex text generation, for example MathJax rendering in IPython notebook or text rendering in LaTeX documents
wrap_line (boolean) – If True, lines will wrap at the end; if False, they will not wrap but continue as one line. This is only relevant if pretty_print is True.
num_columns (int or None) – If int, number of columns before wrapping is set to num_columns; if None, number of columns before wrapping is set to terminal width. This is only relevant if pretty_print is True.
no_global (boolean) – If True, the settings become system wide; if False, use just for this console/session.
ip (An interactive console) – This can either be an instance of IPython, or a class that derives from code.InteractiveConsole.
euler (boolean, optional, default=False) – Loads the euler package in the LaTeX preamble for handwritten style fonts (http://www.ctan.org/pkg/euler).
forecolor (string, optional, default='Black') – DVI setting for foreground color.
backcolor (string, optional, default='Transparent') – DVI setting for background color.
fontsize (string, optional, default='10pt') – A font size to pass to the LaTeX documentclass function in the preamble.
latex_mode (string, optional, default='equation*') – The mode used in the LaTeX printer. Can be one of: {‘inline’|’plain’|’equation’|’equation*’}.
print_builtin (boolean, optional, default=True) – If true then floats and integers will be printed. If false the printer will only print SymPy types.
str_printer (function, optional, default=None) – A custom string printer function. This should mimic sympy.printing.sstrrepr().
pretty_printer (function, optional, default=None) – A custom pretty printer. This should mimic sympy.printing.pretty().
latex_printer (function, optional, default=None) – A custom LaTeX printer. This should mimic sympy.printing.latex().
Examples
>>> from ..interactive import init_printing >>> from .. import Symbol, sqrt >>> from ..abc import x, y >>> sqrt(5) sqrt(5) >>> init_printing(pretty_print=True) >>> sqrt(5) ___ \/ 5 >>> theta = Symbol('theta') >>> init_printing(use_unicode=True) >>> theta \u03b8 >>> init_printing(use_unicode=False) >>> theta theta >>> init_printing(order='lex') >>> str(y + x + y**2 + x**2) x**2 + x + y**2 + y >>> init_printing(order='grlex') >>> str(y + x + y**2 + x**2) x**2 + x + y**2 + y >>> init_printing(order='grevlex') >>> str(y * x**2 + x * y**2) x**2*y + x*y**2 >>> init_printing(order='old') >>> str(x**2 + y**2 + x + y) x**2 + x + y**2 + y >>> init_printing(num_columns=10) >>> x**2 + x + y**2 + y x + y + x**2 + y**2
modelparameters.sympy.interactive.session module¶
Tools for setting up interactive sessions.
- modelparameters.sympy.interactive.session.enable_automatic_int_sympification(app)[source]¶
Allow IPython to automatically convert integer literals to Integer.
- modelparameters.sympy.interactive.session.enable_automatic_symbols(app)[source]¶
Allow IPython to automatially create symbols (
isympy -a
).
- modelparameters.sympy.interactive.session.init_ipython_session(argv=[], auto_symbols=False, auto_int_to_Integer=False)[source]¶
Construct new IPython session.
- modelparameters.sympy.interactive.session.init_python_session()[source]¶
Construct new Python session.
- modelparameters.sympy.interactive.session.init_session(ipython=None, pretty_print=True, order=None, use_unicode=None, use_latex=None, quiet=False, auto_symbols=False, auto_int_to_Integer=False, str_printer=None, pretty_printer=None, latex_printer=None, argv=[])[source]¶
Initialize an embedded IPython or Python session. The IPython session is initiated with the –pylab option, without the numpy imports, so that matplotlib plotting can be interactive.
- Parameters:
pretty_print (boolean) – If True, use pretty_print to stringify; if False, use sstrrepr to stringify.
order (string or None) – There are a few different settings for this parameter: lex (default), which is lexographic order; grlex, which is graded lexographic order; grevlex, which is reversed graded lexographic order; old, which is used for compatibility reasons and for long expressions; None, which sets it to lex.
use_unicode (boolean or None) – If True, use unicode characters; if False, do not use unicode characters.
use_latex (boolean or None) – If True, use latex rendering if IPython GUI’s; if False, do not use latex rendering.
quiet (boolean) – If True, init_session will not print messages regarding its status; if False, init_session will print messages regarding its status.
auto_symbols (boolean) – If True, IPython will automatically create symbols for you. If False, it will not. The default is False.
auto_int_to_Integer (boolean) – If True, IPython will automatically wrap int literals with Integer, so that things like 1/2 give Rational(1, 2). If False, it will not. The default is False.
ipython (boolean or None) – If True, printing will initialize for an IPython console; if False, printing will initialize for a normal console; The default is None, which automatically determines whether we are in an ipython instance or not.
str_printer (function, optional, default=None) – A custom string printer function. This should mimic sympy.printing.sstrrepr().
pretty_printer (function, optional, default=None) – A custom pretty printer. This should mimic sympy.printing.pretty().
latex_printer (function, optional, default=None) – A custom LaTeX printer. This should mimic sympy.printing.latex() This should mimic sympy.printing.latex().
argv (list of arguments for IPython) – See sympy.bin.isympy for options that can be used to initialize IPython.
See also
sympy.interactive.printing.init_printing
for examples and the rest of the parameters.
Examples
>>> from .. import init_session, Symbol, sin, sqrt >>> sin(x) NameError: name 'x' is not defined >>> init_session() >>> sin(x) sin(x) >>> sqrt(5) ___ \/ 5 >>> init_session(pretty_print=False) >>> sqrt(5) sqrt(5) >>> y + x + y**2 + x**2 x**2 + x + y**2 + y >>> init_session(order='grlex') >>> y + x + y**2 + x**2 x**2 + y**2 + x + y >>> init_session(order='grevlex') >>> y * x**2 + x * y**2 x**2*y + x*y**2 >>> init_session(order='old') >>> x**2 + y**2 + x + y x + y + x**2 + y**2 >>> theta = Symbol('theta') >>> theta theta >>> init_session(use_unicode=True) >>> theta θ
- modelparameters.sympy.interactive.session.int_to_Integer(s)[source]¶
Wrap integer literals with Integer.
This is based on the decistmt example from http://docs.python.org/library/tokenize.html.
Only integer literals are converted. Float literals are left alone. .. rubric:: Examples
>>> from __future__ import division >>> from .session import int_to_Integer >>> from .. import Integer >>> s = '1.2 + 1/2 - 0x12 + a1' >>> int_to_Integer(s) '1.2 +Integer (1 )/Integer (2 )-Integer (0x12 )+a1 ' >>> s = 'print (1/2)' >>> int_to_Integer(s) 'print (Integer (1 )/Integer (2 ))' >>> exec(s) 0.5 >>> exec(int_to_Integer(s)) 1/2
Module contents¶
Helper module for setting up interactive SymPy sessions.