from kamodo.kamodo import Kamodo
kj/filesystem-disk-unix.c++:1690: warning: PWD environment variable doesn't match current directory; pwd = /Users/asherp/git/ensemblegovservices/kamodo-core

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$')
\begin{equation}f{\left(x,y \right)} = x^{2} + y^{2}\end{equation} \begin{equation}g{\left(x,y \right)} = 2 x^{2} + 3 y^{2}\end{equation}

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 parsing 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')
\begin{equation}\operatorname{x_{i}}{\left(a \right)} = a\end{equation} \begin{equation}\operatorname{y^{j}}{\left(b \right)} = b\end{equation} \begin{equation}\operatorname{z^{2}_{oxygen}}{\left(c \right)} = c\end{equation}

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')
\begin{equation}\rho{\left(\alpha,\beta,\Gamma \right)} = \alpha + \beta + \Gamma\end{equation}

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')
\begin{equation}\operatorname{x_{i+1}}{\left(x_{i} \right)} = 0.9 x_{i}\end{equation} \begin{equation}\operatorname{O^{-}}{\left(e,h \right)} = e^{- h}\end{equation} \begin{equation}\operatorname{O\left (3P\right )}{\left(t \right)} = t\end{equation} \begin{equation}\operatorname{{f}'}{\left(x \right)} = x\end{equation}

Bold font

Use the bm suffix to make a variable bold face

Kamodo(Gbm='x', g='y')
\begin{equation}\boldsymbol{G}{\left(x \right)} = x\end{equation} \begin{equation}g{\left(y \right)} = y\end{equation}

Vectors

Use the vec suffix to place above the preceding symbol. The symbol works similarly.

Kamodo(fvec='-rvec', bhat='x')
\begin{equation}\vec{f}{\left(\vec{r} \right)} = - \vec{r}\end{equation} \begin{equation}\hat{b}{\left(x \right)} = x\end{equation}

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:

  1. Annotation - add superscripts/subscripts to distinguish between the different implentations.
  2. 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')
\begin{equation}\rho{\left(x,y,z \right)} = x + y + z\end{equation} \begin{equation}\rho{\left(\phi,r,\theta \right)} = r \sin{\left(\theta \right)} \cos{\left(\phi \right)}\end{equation} \begin{equation}\rho_{2D}{\left(x,y \right)} = x + y\end{equation}

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')
\begin{equation}\rho{\left(x,y \right)} = x + y\end{equation} \begin{equation}\rho{\left(x,y \right)} = 3 x + y\end{equation}