Skip to main content
Calcs Builder uses Math.js as the core engine for writing equations. You can use the full Math.js library for standard math, units, matrices, and more:
Do not use the math. prefix. Write gcd(6, 15), not math.gcd(6, 15).
On top of Math.js, Calcs Builder adds custom functions to help you reference other widgets, iterate over data, interpolate, format output, and run numerical solvers. The sections below cover those custom functions.
To reference another widget by its reference ID, use the ID directly (for example L, M_u, or `M*`). The older x() wrapper is deprecated. See Deprecated functions at the bottom.

Pulling data from other widgets

These functions let you read values from lookup widgets, tables, and other fields.

L(): Lookup reference

Use L() to read a value from a lookup or shared lookup widget.
  • columnIndex is 0-based (left-most column = 0)
  • The row comes from the user’s selection, or the lookup’s default row (also 0-based from the top)
Example: Read column 7 from a shared lookup called member, and multiply by elastic modulus E:

T(): Internal table reference

Use T() inside a table widget to reference cells in that same table, typically in a computed column.
  • Row and column indices are 0-based
  • rowIndex() and colIndex() are built-in properties of each cell and can be used on their own or inside T()
Examples:
Computed column example: allowable deflection is the minimum of span-ratio limit and a fixed mm limit:

matrixSubset(): Extract from a matrix

Extract one or more elements from a matrix (table or computed field).
  • rowIndex and columnIndex are 1-based (unlike L() and T())
Example: Read row 1, column 3 from a load-case matrix LC_str:

vectorSubset(): Extract from a vector

Extract a single element from a vector.
  • elementIndex is 1-based
Example: Read the 2nd element of a remote vector firstQuarterBM:

col(): Extract a column (as a row matrix)

Returns an entire column as a row matrix [[a, b, c]]. Useful for server-returned data.
  • columnIndex is 1-based
Math.js also has column() with the same syntax, but it returns a column matrix [[a], [b], [c]] instead. Example: Find the maximum value in column 6 of a remote result:

interpolate(): Interpolate from 2D or 3D data

Interpolate a value from tabulated data. X-coordinates (and Y-coordinates for 3D) must be in ascending order.

2D data

If xLoc is outside the range of xCoords, the function returns the value at the nearest edge. For example, with xCoords = [1, 2, 3] and xMatrix = [0, 5, 10], evaluating at xLoc = 4 returns 10.
Example:

3D data


Built-in Math.js matrix helpers

column()

Extracts a column as a column matrix.

row()

Extracts a row as a row matrix.

Iterating over a set of data

setSum(): Summation over a range

Sum an expression over an integer range, like Σ in mathematics.
  • from and to are inclusive
  • The last argument is the loop variable name (as a string)
Example: Sum column 2 of table PL across all rows:
Here vectorSubset(size(PL), 1) gives the number of rows, and j steps from 1 to that count.

iterate(): Build an array by looping

Like setSum, but returns an array of results instead of a single sum. You control the step size.
  • from and to are inclusive
Equivalent Python logic:
Number sequence example: list support numbers from 1 to the row count of matrix r:
Conditional string example:

deepReplace(): Find-and-replace inside a structure

Performs a string find-replace deep inside a matrix, object, or other nested structure. Commonly used in upgrade mappings.
Example: Rename key L to L_total inside a supports table:

mapObject(): Map over object entries

Works like Math.js map(), but iterates over object key-value pairs instead of matrix rows.
Example:

matrixFromFunction()

Generate a matrix by evaluating a function at each coordinate:
Similar to iterate(), but the loop variable i is a coordinate array, not a simple integer.

map()

Apply a function to every element of a matrix (same size in, same size out):

toArray()

Convert a matrix to a plain array:

Solvers

solveSecant(): Secant method root finder

Finds the root of a single-variable equation using the secant method. Provide two initial guesses and the solver iterates until convergence or until it hits the iteration limit.
Choose maxIters high enough to converge reliably, but low enough to avoid excessive computation.

Example 1: Neutral axis location

Find kd where force equilibrium equals zero:

Example 2: Shortest unbraced length

When moment capacity equals a target value, rearrange to f(x) = 0 and solve for x (representing unbraced length L_yr):
For a full walkthrough of solveSecant() applied to a demand-vs-capacity problem, see Example: Using solveSecant().

Sheet state

presetCode()

Returns the preset code used to open the sheet, as a string.

unitSystem()

Returns the current unit system as a string ("FPS" or "MKS").

Formatting strings

defaultFormat(): Standard number format

Applies the Calcs.com standard number format so templates round consistently.
Advanced options (use only when well justified):
Concatenate a formatted string with variable substitution. Useful for export labels and diagram text.

Miscellaneous

maxIndex() / minIndex()

Return the 1-based index of the maximum or minimum value in an array.

ln(): Natural logarithm

Math.js renders natural logs as ln() but does not provide an ln() function. Use either:
Never use log(x) without an explicit base. Always write log(x, base) to avoid ambiguity.

isIncluded()

Check whether a value exists in an array.

Conditional logic in equations

Math.js supports the ternary operator ? : for inline conditionals inside a single expression:
Examples:
You can nest ternaries to handle multiple cases in one line, but expressions get hard to read and maintain quickly.
We do not recommend relying on ? : for most equation widgets. Prefer the If interface in the equation widget instead: add separate rows with a condition and result, and use @default as the fallback. It keeps logic easier to read, debug, and update.See Equation Widget: Conditional Logic for the recommended pattern.
Recommended approach (If interface):
Inline alternative (works, but use sparingly):

Checks

I(): Indicator function

Returns 1 if the condition is true, 0 if false. Useful as an on/off switch inside equations.
Example: Conditionally add an angle leg height depending on a lookup selection:
When multiplied by a value, I() acts like a conditional gate. The term only contributes when its condition is true.

Deprecated functions

Do not use these in new templates.

x(): Field reference (deprecated)

Previously required to reference another widget. Now use the reference ID directly:
For string IDs with special characters, use backticks: `M*`

x(, true): Inputs-only table reference (deprecated)

Previously returned only input columns from a table to avoid circular references. Better reference patterns are now available.

isNumber() (deprecated)

Use Math.js isNumeric() instead.