Use with ParameterizedFunctions

In the latexalign tutorial I mentioned that one can use latexalign directly on a ParameterizedFunction. Here, I make a somewhat more convoluted and hard-to-read example (you'll soon se why):

using Latexify
using ParameterizedFunctions
copy_to_clipboard(true)

ode = @ode_def positiveFeedback begin
    dx = y*y*y/(k_y_x + y) - x - x
    dy = x^n_x/(k_x^n_x + x^n_x) - y
end k_y k_x n_x

latexify(ode)

\[\begin{align} \frac{dx}{dt} =& \frac{y \cdot y \cdot y}{k_{y\_x} + y} - x - x \\ \frac{dy}{dt} =& \frac{x^{n_{x}}}{k_{x}^{n_{x}} + x^{n_{x}}} - y \\ \end{align}\]

This is pretty nice, but there are a few parts of the equation which could be reduced. Using a keyword argument, you can utilise the SymEngine.jl to reduce the expression before printing.

latexify(ode, field=:symfuncs)

\[\begin{align} \frac{dx}{dt} =& -2 \cdot x + \frac{y^{3}}{k_{y\_x} + y} \\ \frac{dy}{dt} =& - y + \frac{x^{n_{x}}}{k_{x}^{n_{x}} + x^{n_{x}}} \\ \end{align}\]

Side-by-side rendering of multiple system.

A vector of ParameterizedFunctions will be rendered side-by-side:

ode2 = @ode_def negativeFeedback begin
    dx = y/(k_y + y) - x
    dy = k_x^n_x/(k_x^n_x + x^n_x) - y
end k_y k_x n_x

latexify([ode, ode2])

\[\begin{align} \frac{dx}{dt} &= \frac{y \cdot y \cdot y}{k_{y\_x} + y} - x - x & \frac{dx}{dt} &= \frac{y}{k_{y} + y} - x & \\ \frac{dy}{dt} &= \frac{x^{n_{x}}}{k_{x}^{n_{x}} + x^{n_{x}}} - y & \frac{dy}{dt} &= \frac{k_{x}^{n_{x}}}{k_{x}^{n_{x}} + x^{n_{x}}} - y & \\ \end{align}\]

Visualise your parameters.

Another thing that I have found useful is to display the parameters of these functions. The parameters are usually in a vector, and if it is somewhat long, then it can be annoying to try to figure out which element belongs to which parameter. There are several ways to solve this. Here are two:

## lets say that we have some parameters
param = [3.4,5.2,1e-2]
latexify(ode.params, param)

\[\begin{align} k_{y} =& 3.4 \\ k_{x} =& 5.2 \\ n_{x} =& 0.01 \\ \end{align}\]

or

latexify([ode.params, param]; env=:array, transpose=true)

\[\begin{equation} \left[ \begin{array}{ccc} k_{y} & k_{x} & n_{x} \\ 3.4 & 5.2 & 0.01 \\ \end{array} \right] \end{equation}\]

signif.() is your friend if your parameters have more significant numbers than you want to see.

Get the jacobian, hessian, etc.

ParameterizedFunctions symbolically calculates the jacobian, inverse jacobian, hessian, and all kinds of goodness. Since they are available as arrays of symbolic expressions, which are latexifyable, you can render pretty much all of them.

latexify(ode.symjac)

\[\begin{equation} \left[ \begin{array}{cc} -2 & \frac{3 \cdot y^{2}}{k_{y\_x} + y} - \frac{y^{3}}{\left( k_{y\_x} + y \right)^{2}} \\ \frac{x^{-1 + n_{x}} \cdot n_{x}}{k_{x}^{n_{x}} + x^{n_{x}}} - \frac{x^{-1 + 2 \cdot n_{x}} \cdot n_{x}}{\left( k_{x}^{n_{x}} + x^{n_{x}} \right)^{2}} & -1 \\ \end{array} \right] \end{equation}\]

Available options

KeywordValuesDefaultDescription
:adjustment:c for centered, :l for left, :r for right, or a vector with one such symbol per column.:cSet the adjustment of text within the table cells.
:arraystyleSymbol, String, NTuple{3, String}:squareHow to style (brackets around) arrays. Symbols correspond to predefined styles: :square, :round, :curly, :bmatrix, :pmatrix. A string will be used as an environment, with no further brackets (e.g. "vmatrix"). Tuples should be (<starting bracket>, <ending bracket>, <environment>), for instance :square corresponds to ("\n\\left[", "\\right]\n", "array").
:booktabsBoolfalseAdd top, mid and bottom booktabs rule
:bracketBoolfalseSurround variables with square brackets.
:cdotBooltrueToggle between using \cdot or just a space to represent multiplication.
:convert_unicodeBooltrueConvert unicode characters to latex commands, for example α to \alpha
:double_linebreakBoolfalseAdd an extra \\ to the end of the line.
:escape_underscoresBoolfalsePrevent underscores from being interpreted as formatting.
:fmtformat string""Format number output in accordence with Printf. Example: "%.2e"
:headArray[]Add a header to the table. It will error if it is not of the right length (unless empty).
:imaginary_unitString"\\mathit{i}"The symbol to use to represent the imaginary unit
:indexSymb:bracketRepresent index specification with :bracket (u[1]) or :subscript (u_1).
:latexBooltrueToggle latexification of the table elements.
:rowsIterable or symol:allWhich rows to include in the output.
:safescriptsBoolfalsePut scripts inside brackets (a{_b}), sometimes making them uglier, but making alternating scripts possible.
:separatorString" =& "Specify how to separate the left hand side and the right.
:sideArray[]Add a leftmost column to the table. It will error if it is not of the right length (unless empty).
:snakecaseBoolfalseTreat underscores as literal underscores (if not, treat first underscore as subscript).
:starredBoolfalseStar the environment to prevent equation numbering.
:transposeBooltrueFlip rows for columns.