Printing
- sympy_equation.printing.interactive.init_latex_printing(*, full_prec=False, fold_frac_powers=False, fold_func_brackets=False, fold_short_frac=None, inv_trig_style='abbreviated', itex=False, ln_notation=False, long_frac_ratio=None, mat_delim='[', mat_str=None, mode='plain', mul_symbol=None, order=None, symbol_names={}, root_notation=True, mat_symbol_style='plain', imaginary_unit='i', gothic_re_im=False, decimal_separator='period', perm_cyclic=True, parenthesize_super=True, min=None, max=None, diff_operator='d', adjoint_style='dagger', disable_split_super_sub=False)
Initialize an
ExtendedLatexPrinteron this interactive shell.- Parameters:
- applied_undef_argsSelector
- default:
‘all’
- options:
[None, True, False, ‘all’, ‘first-level’]
Strategy to represent the arguments of applied undefined functions. It can be:
"all"orTrue: all arguments will be shown."first-level": consider f(x, g(x, y)). When this option is set,the rendered function will look like f(x, g).
FalseorNone: no arguments will be shown.
- base_scalar_styleSelector
- default:
‘normal’
- options:
[‘legacy’, ‘normal’, ‘normal-ns’, ‘bold’, ‘bold-ns’]
Controls how to render base scalars from the sympy.vector module. It can be:
"legacy": use standard SymPy’s latex printer. Base scalars are rendered in bold font."normal"(default): rendered as ‘symbol_{system}’. No bold font."normal-ns": rendered as ‘symbol’. No bold font, no system."bold": rendered as ‘symbol_{system}’ using bold font."bold-ns": rendered as ‘symbol’ using bold font.
- base_vector_styleSelector
- default:
‘auto’
- options:
[‘legacy’, ‘ijk’, ‘ijk-ns’, ‘e’, ‘e-ns’, ‘system’, ‘auto’]
Controls how to render base vectors and vectors from the sympy.vector module, when the option
vector="legacy". It can be:"auto": uses ‘ijk’ for Cartesian systems and ‘e’ for the other systems."legacy": use standard SymPy’s latex printer. Base vectors are rendered as ‘hat{i}_{system}, hat{j}_{system}, hat{k}_{system}’. Any coefficient to these base vectors are wrapped in parenthesis."ijk": similar to"legacy", but the coefficients won’t be wrapped in parenthesis, unless strictly required."ijk-ns": no system is shown, ‘hat{i}, hat{j}, hat{k}’. This is useful if we are working with only one cartesian system."e": ‘hat{e}_{system, base scalar}’."e-ns": no system is shown, ‘hat{e}_{base scalar}’. This is useful if we are working with only one curvilinear system."system": hat{system}_{base scalar}.
- derivativeSelector
- default:
None
- options:
[None, ‘subscript’, ‘prime-arabic’, ‘prime-roman’, ‘dot’, ‘d-notation’]
Stategy to represent derivatives of applied undefined functions. It can be:
None (default value): standard notation, for example df/dx.
"prime-arabic": Lagrange’s notation for derivatives, which only works for functions with one argument. For example:\(\frac{d f}{d x} \rightarrow f'\)
\(\frac{d^{2} f}{d x^2} \rightarrow f''\)
\(\frac{d^{3} f}{d x^3} \rightarrow f'''\)
\(\frac{d^{4} f}{d x^4} \rightarrow f^{(4)}\)
"prime-roman": Lagrange’s notation for derivatives, which only works for functions with one argument. For example:\(\frac{d f}{d x} \rightarrow f'\)
\(\frac{d^{2} f}{d x^2} \rightarrow f''\)
\(\frac{d^{3} f}{d x^3} \rightarrow f'''\)
\(\frac{d^{4} f}{d x^4} \rightarrow f^{iv}\)
"dot": Newton’s notation for time derivatives using dots, for example \(\frac{d f}{d t} \rightarrow \dot{f}\). It only works if the time symbol is constructed with no assumptions."subscript": add subscripts on the right side of the function name. For example:\(\frac{d f}{d x} \rightarrow (f)_{x}\)
\(\frac{d^{2} f}{d x^2} \rightarrow (f)_{xx}\)
\(\frac{\partial^{2} f}{\partial x \partial y} \rightarrow (f)_{xy}\)
"d-notation": add subscripts on the right side of derivative short syntax. For example:\(\frac{d f(x)}{d x} \rightarrow D_{x} f\)
\(\frac{d^{2} f(x)}{d x^2} \rightarrow D_{x}^{2} f\)
\(\frac{\partial^{2} f(x, y)}{\partial x \partial y} \rightarrow \partial_{xy} f\)
- full_precBoolean
- default:
False
If set to True, a floating point number is printed with full precision.
- fold_frac_powersBoolean
- default:
False
Emit
^{p/q}instead of^{\frac{p}{q}}for fractional powers.- fold_func_bracketsBoolean
- default:
False
Fold function brackets where applicable.
- fold_short_fracBoolean
- default:
False
Emit
p / qinstead of\frac{p}{q}when the denominator is simple enough (at most two terms and no powers). The default value isTruefor inline mode,Falseotherwise.- inv_trig_styleSelector
- default:
‘abbreviated’
- options:
[‘abbreviated’, ‘full’, ‘power’]
How inverse trig functions should be displayed.
- itexBoolean
- default:
False
Specifies if itex-specific syntax is used, including emitting
$$...$$.- ln_notationBoolean
- default:
False
If set to
True,\lnis used instead of default\log.- long_frac_ratioInteger
- allow_None:
True
- bounds:
long_frac_ratio >= 0
The allowed ratio of the width of the numerator to the width of the denominator before the printer breaks off long fractions. If
None(the default value), long fractions are not broken up.- mat_delimSelector
- default:
‘[’
- options:
[‘[’, ‘(’, ‘’, None]
The delimiter to wrap around matrices.
- mat_strSelector
- default:
None
- options:
[‘smallmatrix’, ‘matrix’, ‘bmatrix’, ‘array’]
Which matrix environment string to emit. Defaults to
'smallmatrix'for inline mode,'matrix'for matrices of no more than 10 columns, and'array'otherwise.- modeSelector
- default:
‘plain’
- options:
[‘plain’, ‘inline’, ‘equation’, ‘equation*’]
Specifies how the generated code will be delimited. If
mode='plain', then the resulting code will not be delimited at all (this is the default). Ifmode='inline'then inline LaTeX$...$will be used. Ifmode='equation'ormode='equation*', the resulting code will be enclosed in theequationorequation*environment (remember to importamsmathforequation*), unless theitexoption is set. In the latter case, the$$...$$syntax is used.- mul_symbolString
- allow_None:
True
The symbol to use for multiplication. Possible options are: None, ‘ldot’, ‘dot’, ‘times’.
- orderSelector
- default:
None
- options:
[None, ‘lex’, ‘grlex’, ‘grevlex’, ‘rev-lex’, ‘old’, ‘none’]
This parameter does nothing for ~.Mul objects, but it reorders monomials in ~.Add. Setting
order='old'uses the compatibility ordering for~.Adddefined in Printer. For very large expressions, set theorderkeyword to'none'if speed is a concern.- symbol_namesDict
- default:
{}
Dictionary of symbols and the custom strings they should be emitted as.
- root_notationBoolean
- default:
True
If set to
False, exponents of the form 1/n are printed in fractonal form. Default isTrue, to print exponent in root form.- mat_symbol_styleSelector
- default:
‘plain’
- options:
[‘plain’, ‘bold’]
Can be either
'plain'(default) or'bold'. If set to'bold', a ~.MatrixSymbol A will be printed as\mathbf{A}, otherwise asA.- imaginary_unitString
- default:
i
String to use for the imaginary unit. Defined options are
'i'(default) and'j'. Addingrortin front gives\mathrmor\text, so'ri'leads to\mathrm{i}.- gothic_re_imBoolean
- default:
False
If set to
True, Re and Im is used forreandim, respectively. The default isFalseleading to operatorname{re} and operatorname{im}.- decimal_separatorSelector
- default:
‘period’
- options:
[‘period’, ‘comma’]
Specifies what separator to use to separate the whole and fractional parts of a floating point number as in 2.5 for the default,
periodor 2{,}5 whencommais specified. Lists, sets, and tuple are printed with semicolon separating the elements whencommais chosen. For example, [1; 2; 3] whencommais chosen and [1,2,3] for whenperiodis chosen.- perm_cyclicBoolean
- default:
True
- minInteger
- allow_None:
True
Sets the lower bound for the exponent to print floating point numbers in fixed-point format.
- maxInteger
- allow_None:
True
Sets the upper bound for the exponent to print floating point numbers in fixed-point format.
- diff_operatorSelector
- default:
‘d’
- options:
[‘d’, ‘rd’, ‘td’]
String to use for differential operator. Default is
'd', to print in italic form.'rd','td'are shortcuts for\mathrm{d}and\text{d}.- adjoint_styleSelector
- default:
‘dagger’
- options:
[‘dagger’, ‘star’, ‘hermitian’]
String to use for the adjoint symbol.
- disable_split_super_subBoolean
- default:
False
- vectorSelector
- default:
‘legacy’
- options:
[‘legacy’, ‘matrix’, ‘matrix-ns’]
Controls how to render vectors from the sympy.vector module. It can be:
"legacy": vectors are rendered as linear combination between terms and base vectors."matrix": vectors are rendered as 3x1 matrices."matrix-ns": vectors are rendered as 3x1 matrices without the label indicating the system.
- dyadic_styleSelector
- default:
‘otimes’
- options:
[‘none’, ‘vline’, ‘otimes’]
The symbol denoting a dyadic.
- colorizeDict
- default:
{}
Map sub-expressions to specific latex colors.
- print_builtinBoolean
- default:
True
If
Truethen floats and integers will be printed. IfFalsethe printer will only print SymPy types.- idx_breaklineString
- default:
Latex command to insert between the start and end indices of an Idx object. Default to empty string (for nice rendering on interactive environments). For applications where indices must not be broken into multiple lines, it can be set to ‘nobreak ‘.
- Returns:
- latex_printerExtendedLatexPrinter
Examples
>>> from sympy import * >>> from sympy_equation import init_latex_printing >>> x, y, z, t = symbols("x:z t") >>> f = Function("f")(x, y, z) >>> g = Function("g")(t) >>> expr = f.diff(x, 2) + g.diff(t) >>> printer = init_latex_printing()
Use the
doprintmethod in order to generate Latex code of a symbolic expressions:>>> print(printer.doprint(expr)) \frac{\partial^{2}}{\partial x^{2}} f{\left(x,y,z \right)} + \frac{d}{d t} g{\left(t \right)}
Adding a rule to print derivatives of
fusing shorter partial notation:>>> printer.add_rule(f, derivative="d-notation") >>> print(printer.doprint(expr)) \partial_{xx}f{\left(x,y,z \right)} + \frac{d}{d t} g{\left(t \right)}
Adding a rule to print derivates of
gusing dot notation, while hiding the arguments ofg:>>> printer.add_rule(g, derivative="dot", applied_undef_args=None) >>> print(printer.doprint(expr)) \partial_{xx}f{\left(x,y,z \right)} + \dot{g}
Customizing vectors from the sympy.vector module. For a Cartesian system the default output looks like:
>>> from sympy.vector import CoordSys3D >>> C = CoordSys3D("C") >>> x, y, z = C.base_scalars() >>> i, j, k = C.base_vectors() >>> f1, f2, f3 = [Function(k)(x, y, z) for k in ["f1", "f2", "f3"]] >>> v1 = f1 * i + f2 * j + f3 * k >>> print(printer.doprint(v1)) f_{1}{\left(x_{\text{C}},y_{\text{C}},z_{\text{C}} \right)}\,\mathbf{\hat{i}_{C}} + f_{2}{\left(x_{\text{C}},y_{\text{C}},z_{\text{C}} \right)}\,\mathbf{\hat{j}_{C}} + f_{3}{\left(x_{\text{C}},y_{\text{C}},z_{\text{C}} \right)}\,\mathbf{\hat{k}_{C}}
Hide arguments of applied undefined functions:
>>> for f in [f1, f2, f3]: ... printer.add_rule(f, applied_undef_args=None) >>> print(printer.doprint(v1)) f_{1}\,\mathbf{\hat{i}_{C}} + f_{2}\,\mathbf{\hat{j}_{C}} + f_{3}\,\mathbf{\hat{k}_{C}}
By default, base vectors uses the i, j, k notation (for curvilinear systems too), and base scalars shows the systems they are associated to:
>>> S = C.create_new("S", transformation="spherical") >>> r, theta, phi = S.base_scalars() >>> e_r, e_theta, e_phi = S.base_vectors() >>> f4, f5, f6 = [Function(k)(r, theta, phi) for k in ["f4", "f5", "f6"]] >>> v2 = f4 * e_r + f5 * e_theta + f6 * e_phi >>> print(printer.doprint(v2)) f_{4}{\left(r_{\text{S}},\theta_{\text{S}},\phi_{\text{S}} \right)}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{r}} + f_{5}{\left(r_{\text{S}},\theta_{\text{S}},\phi_{\text{S}} \right)}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{\theta}} + f_{6}{\left(r_{\text{S}},\theta_{\text{S}},\phi_{\text{S}} \right)}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{\phi}}
Set base vectors to be rendered with the ‘hat{e}_{direction}’ notation, and base scalars to hide the system they are associated to:
>>> printer.add_rule(S, base_vector_style="e", base_scalar_style="normal-ns") >>> print(printer.doprint(v2)) f_{4}{\left(r,\theta,\phi \right)}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{r}} + f_{5}{\left(r,\theta,\phi \right)}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{\theta}} + f_{6}{\left(r,\theta,\phi \right)}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{\phi}}
Hide arguments of applied undefined functions:
>>> for f in [f4, f5, f6]: ... printer.add_rule(f, applied_undef_args=None) >>> print(printer.doprint(v2)) f_{4}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{r}} + f_{5}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{\theta}} + f_{6}\,\mathbf{\hat{e}}^{\left(\text{S}\right)}_{\boldsymbol{\phi}}
Apply colors to specified sub-expressions:
>>> printer.colorize[f4] = "red" >>> printer.colorize[f5] = "green" >>> print(printer.doprint(f4 + f5 + f6)) \textcolor{red}{f_{4}} + \textcolor{green}{f_{5}} + f_{6}
- sympy_equation.printing.extended_latex.extended_latex(expr, *, adjoint_style='dagger', applied_undef_args='all', base_scalar_style='normal', base_vector_style='auto', colorize={}, decimal_separator='period', derivative=None, diff_operator='d', disable_split_super_sub=False, dyadic_style='otimes', fold_frac_powers=False, fold_func_brackets=False, fold_short_frac=False, full_prec=False, gothic_re_im=False, idx_breakline='', imaginary_unit='i', inv_trig_style='abbreviated', itex=False, ln_notation=False, long_frac_ratio=None, mat_delim='[', mat_str=None, mat_symbol_style='plain', max=None, min=None, mode='plain', mul_symbol=None, name='ExtendedLatexPrinter', order=None, perm_cyclic=True, print_builtin=True, root_notation=True, symbol_names={}, vector='legacy')
Wrapper function to
ExtendedLatexPrinter.- Parameters:
- applied_undef_argsSelector
- default:
‘all’
- options:
[None, True, False, ‘all’, ‘first-level’]
Strategy to represent the arguments of applied undefined functions. It can be:
"all"orTrue: all arguments will be shown."first-level": consider f(x, g(x, y)). When this option is set,the rendered function will look like f(x, g).
FalseorNone: no arguments will be shown.
- base_scalar_styleSelector
- default:
‘normal’
- options:
[‘legacy’, ‘normal’, ‘normal-ns’, ‘bold’, ‘bold-ns’]
Controls how to render base scalars from the sympy.vector module. It can be:
"legacy": use standard SymPy’s latex printer. Base scalars are rendered in bold font."normal"(default): rendered as ‘symbol_{system}’. No bold font."normal-ns": rendered as ‘symbol’. No bold font, no system."bold": rendered as ‘symbol_{system}’ using bold font."bold-ns": rendered as ‘symbol’ using bold font.
- base_vector_styleSelector
- default:
‘auto’
- options:
[‘legacy’, ‘ijk’, ‘ijk-ns’, ‘e’, ‘e-ns’, ‘system’, ‘auto’]
Controls how to render base vectors and vectors from the sympy.vector module, when the option
vector="legacy". It can be:"auto": uses ‘ijk’ for Cartesian systems and ‘e’ for the other systems."legacy": use standard SymPy’s latex printer. Base vectors are rendered as ‘hat{i}_{system}, hat{j}_{system}, hat{k}_{system}’. Any coefficient to these base vectors are wrapped in parenthesis."ijk": similar to"legacy", but the coefficients won’t be wrapped in parenthesis, unless strictly required."ijk-ns": no system is shown, ‘hat{i}, hat{j}, hat{k}’. This is useful if we are working with only one cartesian system."e": ‘hat{e}_{system, base scalar}’."e-ns": no system is shown, ‘hat{e}_{base scalar}’. This is useful if we are working with only one curvilinear system."system": hat{system}_{base scalar}.
- derivativeSelector
- default:
None
- options:
[None, ‘subscript’, ‘prime-arabic’, ‘prime-roman’, ‘dot’, ‘d-notation’]
Stategy to represent derivatives of applied undefined functions. It can be:
None (default value): standard notation, for example df/dx.
"prime-arabic": Lagrange’s notation for derivatives, which only works for functions with one argument. For example:\(\frac{d f}{d x} \rightarrow f'\)
\(\frac{d^{2} f}{d x^2} \rightarrow f''\)
\(\frac{d^{3} f}{d x^3} \rightarrow f'''\)
\(\frac{d^{4} f}{d x^4} \rightarrow f^{(4)}\)
"prime-roman": Lagrange’s notation for derivatives, which only works for functions with one argument. For example:\(\frac{d f}{d x} \rightarrow f'\)
\(\frac{d^{2} f}{d x^2} \rightarrow f''\)
\(\frac{d^{3} f}{d x^3} \rightarrow f'''\)
\(\frac{d^{4} f}{d x^4} \rightarrow f^{iv}\)
"dot": Newton’s notation for time derivatives using dots, for example \(\frac{d f}{d t} \rightarrow \dot{f}\). It only works if the time symbol is constructed with no assumptions."subscript": add subscripts on the right side of the function name. For example:\(\frac{d f}{d x} \rightarrow (f)_{x}\)
\(\frac{d^{2} f}{d x^2} \rightarrow (f)_{xx}\)
\(\frac{\partial^{2} f}{\partial x \partial y} \rightarrow (f)_{xy}\)
"d-notation": add subscripts on the right side of derivative short syntax. For example:\(\frac{d f(x)}{d x} \rightarrow D_{x} f\)
\(\frac{d^{2} f(x)}{d x^2} \rightarrow D_{x}^{2} f\)
\(\frac{\partial^{2} f(x, y)}{\partial x \partial y} \rightarrow \partial_{xy} f\)
- full_precBoolean
- default:
False
If set to True, a floating point number is printed with full precision.
- fold_frac_powersBoolean
- default:
False
Emit
^{p/q}instead of^{\frac{p}{q}}for fractional powers.- fold_func_bracketsBoolean
- default:
False
Fold function brackets where applicable.
- fold_short_fracBoolean
- default:
False
Emit
p / qinstead of\frac{p}{q}when the denominator is simple enough (at most two terms and no powers). The default value isTruefor inline mode,Falseotherwise.- inv_trig_styleSelector
- default:
‘abbreviated’
- options:
[‘abbreviated’, ‘full’, ‘power’]
How inverse trig functions should be displayed.
- itexBoolean
- default:
False
Specifies if itex-specific syntax is used, including emitting
$$...$$.- ln_notationBoolean
- default:
False
If set to
True,\lnis used instead of default\log.- long_frac_ratioInteger
- allow_None:
True
- bounds:
long_frac_ratio >= 0
The allowed ratio of the width of the numerator to the width of the denominator before the printer breaks off long fractions. If
None(the default value), long fractions are not broken up.- mat_delimSelector
- default:
‘[’
- options:
[‘[’, ‘(’, ‘’, None]
The delimiter to wrap around matrices.
- mat_strSelector
- default:
None
- options:
[‘smallmatrix’, ‘matrix’, ‘bmatrix’, ‘array’]
Which matrix environment string to emit. Defaults to
'smallmatrix'for inline mode,'matrix'for matrices of no more than 10 columns, and'array'otherwise.- modeSelector
- default:
‘plain’
- options:
[‘plain’, ‘inline’, ‘equation’, ‘equation*’]
Specifies how the generated code will be delimited. If
mode='plain', then the resulting code will not be delimited at all (this is the default). Ifmode='inline'then inline LaTeX$...$will be used. Ifmode='equation'ormode='equation*', the resulting code will be enclosed in theequationorequation*environment (remember to importamsmathforequation*), unless theitexoption is set. In the latter case, the$$...$$syntax is used.- mul_symbolString
- allow_None:
True
The symbol to use for multiplication. Possible options are: None, ‘ldot’, ‘dot’, ‘times’.
- orderSelector
- default:
None
- options:
[None, ‘lex’, ‘grlex’, ‘grevlex’, ‘rev-lex’, ‘old’, ‘none’]
This parameter does nothing for ~.Mul objects, but it reorders monomials in ~.Add. Setting
order='old'uses the compatibility ordering for~.Adddefined in Printer. For very large expressions, set theorderkeyword to'none'if speed is a concern.- symbol_namesDict
- default:
{}
Dictionary of symbols and the custom strings they should be emitted as.
- root_notationBoolean
- default:
True
If set to
False, exponents of the form 1/n are printed in fractonal form. Default isTrue, to print exponent in root form.- mat_symbol_styleSelector
- default:
‘plain’
- options:
[‘plain’, ‘bold’]
Can be either
'plain'(default) or'bold'. If set to'bold', a ~.MatrixSymbol A will be printed as\mathbf{A}, otherwise asA.- imaginary_unitString
- default:
i
String to use for the imaginary unit. Defined options are
'i'(default) and'j'. Addingrortin front gives\mathrmor\text, so'ri'leads to\mathrm{i}.- gothic_re_imBoolean
- default:
False
If set to
True, Re and Im is used forreandim, respectively. The default isFalseleading to operatorname{re} and operatorname{im}.- decimal_separatorSelector
- default:
‘period’
- options:
[‘period’, ‘comma’]
Specifies what separator to use to separate the whole and fractional parts of a floating point number as in 2.5 for the default,
periodor 2{,}5 whencommais specified. Lists, sets, and tuple are printed with semicolon separating the elements whencommais chosen. For example, [1; 2; 3] whencommais chosen and [1,2,3] for whenperiodis chosen.- perm_cyclicBoolean
- default:
True
- minInteger
- allow_None:
True
Sets the lower bound for the exponent to print floating point numbers in fixed-point format.
- maxInteger
- allow_None:
True
Sets the upper bound for the exponent to print floating point numbers in fixed-point format.
- diff_operatorSelector
- default:
‘d’
- options:
[‘d’, ‘rd’, ‘td’]
String to use for differential operator. Default is
'd', to print in italic form.'rd','td'are shortcuts for\mathrm{d}and\text{d}.- adjoint_styleSelector
- default:
‘dagger’
- options:
[‘dagger’, ‘star’, ‘hermitian’]
String to use for the adjoint symbol.
- disable_split_super_subBoolean
- default:
False
- vectorSelector
- default:
‘legacy’
- options:
[‘legacy’, ‘matrix’, ‘matrix-ns’]
Controls how to render vectors from the sympy.vector module. It can be:
"legacy": vectors are rendered as linear combination between terms and base vectors."matrix": vectors are rendered as 3x1 matrices."matrix-ns": vectors are rendered as 3x1 matrices without the label indicating the system.
- dyadic_styleSelector
- default:
‘otimes’
- options:
[‘none’, ‘vline’, ‘otimes’]
The symbol denoting a dyadic.
- colorizeDict
- default:
{}
Map sub-expressions to specific latex colors.
- print_builtinBoolean
- default:
True
If
Truethen floats and integers will be printed. IfFalsethe printer will only print SymPy types.- idx_breaklineString
- default:
Latex command to insert between the start and end indices of an Idx object. Default to empty string (for nice rendering on interactive environments). For applications where indices must not be broken into multiple lines, it can be set to ‘nobreak ‘.
- Returns:
- printerExtendedLatexPrinter
- class sympy_equation.printing.extended_latex.ExtendedLatexPrinter(*, adjoint_style, applied_undef_args, base_scalar_style, base_vector_style, colorize, decimal_separator, derivative, diff_operator, disable_split_super_sub, dyadic_style, fold_frac_powers, fold_func_brackets, fold_short_frac, full_prec, gothic_re_im, idx_breakline, imaginary_unit, inv_trig_style, itex, ln_notation, long_frac_ratio, mat_delim, mat_str, mat_symbol_style, max, min, mode, mul_symbol, order, perm_cyclic, print_builtin, root_notation, symbol_names, vector, name)
Extended Latex printer with new options and ability to set customization rules for selected types of symbolic expressions.
- Attributes:
- applied_undef_argsSelector
- default:
‘all’
- options:
[None, True, False, ‘all’, ‘first-level’]
Strategy to represent the arguments of applied undefined functions. It can be:
"all"orTrue: all arguments will be shown."first-level": consider f(x, g(x, y)). When this option is set,the rendered function will look like f(x, g).
FalseorNone: no arguments will be shown.
- base_scalar_styleSelector
- default:
‘normal’
- options:
[‘legacy’, ‘normal’, ‘normal-ns’, ‘bold’, ‘bold-ns’]
Controls how to render base scalars from the sympy.vector module. It can be:
"legacy": use standard SymPy’s latex printer. Base scalars are rendered in bold font."normal"(default): rendered as ‘symbol_{system}’. No bold font."normal-ns": rendered as ‘symbol’. No bold font, no system."bold": rendered as ‘symbol_{system}’ using bold font."bold-ns": rendered as ‘symbol’ using bold font.
- base_vector_styleSelector
- default:
‘auto’
- options:
[‘legacy’, ‘ijk’, ‘ijk-ns’, ‘e’, ‘e-ns’, ‘system’, ‘auto’]
Controls how to render base vectors and vectors from the sympy.vector module, when the option
vector="legacy". It can be:"auto": uses ‘ijk’ for Cartesian systems and ‘e’ for the other systems."legacy": use standard SymPy’s latex printer. Base vectors are rendered as ‘hat{i}_{system}, hat{j}_{system}, hat{k}_{system}’. Any coefficient to these base vectors are wrapped in parenthesis."ijk": similar to"legacy", but the coefficients won’t be wrapped in parenthesis, unless strictly required."ijk-ns": no system is shown, ‘hat{i}, hat{j}, hat{k}’. This is useful if we are working with only one cartesian system."e": ‘hat{e}_{system, base scalar}’."e-ns": no system is shown, ‘hat{e}_{base scalar}’. This is useful if we are working with only one curvilinear system."system": hat{system}_{base scalar}.
- derivativeSelector
- default:
None
- options:
[None, ‘subscript’, ‘prime-arabic’, ‘prime-roman’, ‘dot’, ‘d-notation’]
Stategy to represent derivatives of applied undefined functions. It can be:
None (default value): standard notation, for example df/dx.
"prime-arabic": Lagrange’s notation for derivatives, which only works for functions with one argument. For example:\(\frac{d f}{d x} \rightarrow f'\)
\(\frac{d^{2} f}{d x^2} \rightarrow f''\)
\(\frac{d^{3} f}{d x^3} \rightarrow f'''\)
\(\frac{d^{4} f}{d x^4} \rightarrow f^{(4)}\)
"prime-roman": Lagrange’s notation for derivatives, which only works for functions with one argument. For example:\(\frac{d f}{d x} \rightarrow f'\)
\(\frac{d^{2} f}{d x^2} \rightarrow f''\)
\(\frac{d^{3} f}{d x^3} \rightarrow f'''\)
\(\frac{d^{4} f}{d x^4} \rightarrow f^{iv}\)
"dot": Newton’s notation for time derivatives using dots, for example \(\frac{d f}{d t} \rightarrow \dot{f}\). It only works if the time symbol is constructed with no assumptions."subscript": add subscripts on the right side of the function name. For example:\(\frac{d f}{d x} \rightarrow (f)_{x}\)
\(\frac{d^{2} f}{d x^2} \rightarrow (f)_{xx}\)
\(\frac{\partial^{2} f}{\partial x \partial y} \rightarrow (f)_{xy}\)
"d-notation": add subscripts on the right side of derivative short syntax. For example:\(\frac{d f(x)}{d x} \rightarrow D_{x} f\)
\(\frac{d^{2} f(x)}{d x^2} \rightarrow D_{x}^{2} f\)
\(\frac{\partial^{2} f(x, y)}{\partial x \partial y} \rightarrow \partial_{xy} f\)
- full_precBoolean
- default:
False
If set to True, a floating point number is printed with full precision.
- fold_frac_powersBoolean
- default:
False
Emit
^{p/q}instead of^{\frac{p}{q}}for fractional powers.
- fold_func_bracketsBoolean
- default:
False
Fold function brackets where applicable.
- fold_short_fracBoolean
- default:
False
Emit
p / qinstead of\frac{p}{q}when the denominator is simple enough (at most two terms and no powers). The default value isTruefor inline mode,Falseotherwise.
- inv_trig_styleSelector
- default:
‘abbreviated’
- options:
[‘abbreviated’, ‘full’, ‘power’]
How inverse trig functions should be displayed.
- itexBoolean
- default:
False
Specifies if itex-specific syntax is used, including emitting
$$...$$.
- ln_notationBoolean
- default:
False
If set to
True,\lnis used instead of default\log.
- long_frac_ratioInteger
- allow_None:
True
- bounds:
long_frac_ratio >= 0
The allowed ratio of the width of the numerator to the width of the denominator before the printer breaks off long fractions. If
None(the default value), long fractions are not broken up.
- mat_delimSelector
- default:
‘[’
- options:
[‘[’, ‘(’, ‘’, None]
The delimiter to wrap around matrices.
- mat_strSelector
- default:
None
- options:
[‘smallmatrix’, ‘matrix’, ‘bmatrix’, ‘array’]
Which matrix environment string to emit. Defaults to
'smallmatrix'for inline mode,'matrix'for matrices of no more than 10 columns, and'array'otherwise.
- modeSelector
- default:
‘plain’
- options:
[‘plain’, ‘inline’, ‘equation’, ‘equation*’]
Specifies how the generated code will be delimited. If
mode='plain', then the resulting code will not be delimited at all (this is the default). Ifmode='inline'then inline LaTeX$...$will be used. Ifmode='equation'ormode='equation*', the resulting code will be enclosed in theequationorequation*environment (remember to importamsmathforequation*), unless theitexoption is set. In the latter case, the$$...$$syntax is used.
- mul_symbolString
- allow_None:
True
The symbol to use for multiplication. Possible options are: None, ‘ldot’, ‘dot’, ‘times’.
- orderSelector
- default:
None
- options:
[None, ‘lex’, ‘grlex’, ‘grevlex’, ‘rev-lex’, ‘old’, ‘none’]
This parameter does nothing for ~.Mul objects, but it reorders monomials in ~.Add. Setting
order='old'uses the compatibility ordering for~.Adddefined in Printer. For very large expressions, set theorderkeyword to'none'if speed is a concern.
- symbol_namesDict
- default:
{}
Dictionary of symbols and the custom strings they should be emitted as.
- root_notationBoolean
- default:
True
If set to
False, exponents of the form 1/n are printed in fractonal form. Default isTrue, to print exponent in root form.
- mat_symbol_styleSelector
- default:
‘plain’
- options:
[‘plain’, ‘bold’]
Can be either
'plain'(default) or'bold'. If set to'bold', a ~.MatrixSymbol A will be printed as\mathbf{A}, otherwise asA.
- imaginary_unitString
- default:
i
String to use for the imaginary unit. Defined options are
'i'(default) and'j'. Addingrortin front gives\mathrmor\text, so'ri'leads to\mathrm{i}.
- gothic_re_imBoolean
- default:
False
If set to
True, Re and Im is used forreandim, respectively. The default isFalseleading to operatorname{re} and operatorname{im}.
- decimal_separatorSelector
- default:
‘period’
- options:
[‘period’, ‘comma’]
Specifies what separator to use to separate the whole and fractional parts of a floating point number as in 2.5 for the default,
periodor 2{,}5 whencommais specified. Lists, sets, and tuple are printed with semicolon separating the elements whencommais chosen. For example, [1; 2; 3] whencommais chosen and [1,2,3] for whenperiodis chosen.
- perm_cyclicBoolean
- default:
True
- minInteger
- allow_None:
True
Sets the lower bound for the exponent to print floating point numbers in fixed-point format.
- maxInteger
- allow_None:
True
Sets the upper bound for the exponent to print floating point numbers in fixed-point format.
- diff_operatorSelector
- default:
‘d’
- options:
[‘d’, ‘rd’, ‘td’]
String to use for differential operator. Default is
'd', to print in italic form.'rd','td'are shortcuts for\mathrm{d}and\text{d}.
- adjoint_styleSelector
- default:
‘dagger’
- options:
[‘dagger’, ‘star’, ‘hermitian’]
String to use for the adjoint symbol.
- disable_split_super_subBoolean
- default:
False
- vectorSelector
- default:
‘legacy’
- options:
[‘legacy’, ‘matrix’, ‘matrix-ns’]
Controls how to render vectors from the sympy.vector module. It can be:
"legacy": vectors are rendered as linear combination between terms and base vectors."matrix": vectors are rendered as 3x1 matrices."matrix-ns": vectors are rendered as 3x1 matrices without the label indicating the system.
- dyadic_styleSelector
- default:
‘otimes’
- options:
[‘none’, ‘vline’, ‘otimes’]
The symbol denoting a dyadic.
- colorizeDict
- default:
{}
Map sub-expressions to specific latex colors.
- print_builtinBoolean
- default:
True
If
Truethen floats and integers will be printed. IfFalsethe printer will only print SymPy types.
- idx_breaklineString
- default:
Latex command to insert between the start and end indices of an Idx object. Default to empty string (for nice rendering on interactive environments). For applications where indices must not be broken into multiple lines, it can be set to ‘nobreak ‘.
References
- add_rule(expr, **settings)
Add a customization rule acting on the provided symbolic expression.
See also
Examples
>>> from sympy import * >>> from sympy_equation.printing.extended_latex import ExtendedLatexPrinter >>> x, y, t = symbols("x y t") >>> f = Function("f")(x, y) >>> g = Function("g")(t) >>> expr = f.diff(x, 2) + g.diff(t) >>> printer = ExtendedLatexPrinter() >>> print(printer.doprint(expr)) \frac{\partial^{2}}{\partial x^{2}} f{\left(x,y \right)} + \frac{d}{d t} g{\left(t \right)}
gis a function of time. Let’s hide the argument, and set the time derivative to be shown with dot notation:>>> printer.add_rule(g, derivative="dot", applied_undef_args=None) >>> print(printer.doprint(expr)) \frac{\partial^{2}}{\partial x^{2}} f{\left(x,y \right)} + \dot{g}
>>> printer.show_rules() [0] g(t) {'derivative': 'dot'} [1] g(t) {'applied_undef_args': None}
- remove_rule(rule)
Remove a customization rule, specified by an index.
See also
- show_rules()
Show all customization rules applied to target symbolic expressions.
See also