from kamodo.kamodo import Kamodo
LaTeX support¶
Kamodo supports both python and LaTex-formatted expressions as input. For LaTeX, you must wrap your expression in $ $
:
Kamodo(f = 'x**2 + y**2', g = '$2x^2 + 3y^2$')
Conventions¶
Kamodo's variable names have to follow python's naming conventions - only numbers, letters, and underscores, which are too restrictive for mathematical symbols. Therefore, Kamodo uses sympy's conventions when generating LaTeX from variable names, which provide a means to write mathematical symbols in a way ammenable to python. More details of sympy's conventions may be found here. Kamodo also adds some additional features not covered by sympy.
Superscripts/Subscripts¶
Subscripts are encoded with single underscores. Superscripts are encoded with double underscores. Combinations are possible.
Kamodo('x_i = a', 'y__j = b', 'z_oxygen__2 = c')
Greek letters¶
Most greek letters are supported using their corresponding english name. Use capitalization if the greek letter should also be capitalized.
Kamodo(rho = 'ALPHA+BETA+Gamma')
Warning
Some greek letters (e.g. pi, zeta) may conflict with Sympy's namespace. In that case, use all caps (e.g. PI, ZETA)
plus/minus operators¶
In Python we cannot have variables embedded with +
or -
, but we may still need these symbols to represent, say ionization or simulation time step. The table below shows how we map from (part of) a variable name to its corresponding latex output.
variable | to latex |
---|---|
plus | + |
minus | - |
comma | , |
LEFT | \\left ( |
RIGHT | \\right ) |
prime | ' |
Here is how you would use these in your functions:
Kamodo(x_iplus1 = 'x_i*.9', O__minus = 'e**-h', OLEFT3PRIGHT = 't', fprime = 'x')
Variable reuse¶
Variables may only have one function representing their evaluation. If you try to define a variable twice, the second version will override the first. However, if you want to represent that variable in a different context but keep using its name, there are two options:
- Annotation - add superscripts/subscripts to distinguish between the different implentations.
- Mimicry - use a new name that produces the same LaTeX output.
Kamodo(rho = 'x + y + z', RHO = 'r*sin(theta)*cos(phi)', rho_2D = 'x + y')
Warning
Mimicry can cause confusion if the signature of the left-hand-side does not change, as in the example below:
Kamodo(rho = 'x + y', RHO = '3*x + y')