
Custom Functions
How to define and use custom functions in MathMatize
Custom Functions
MathMatize lets instructors define their own named functions in the variable form. Once defined, a custom function can be called in any math expression field — including other variable definitions, blank answers, and directly in question content.
Custom functions come in two varieties: defined functions, which have an explicit body, and template functions, which are symbolic placeholders.
Defining a Function
In the exercise editor, open the variable form and add a new variable of type Function.
Give the variable a name (e.g. f). In the Definition field, enter the function equation using standard function call notation on the left-hand side and the function body on the right-hand side:
f(x) = x^2 + 1
Multi-parameter functions are supported:
g(x, y) = 3x + sin(y)
Functions can reference other previously defined custom functions and random variables:
h(x) = g(x, [[a]]) + f(x)
The preview shown next to the variable displays the reduced form of the definition with any referenced variables substituted.
Template Functions
A Template Function is a function that has no explicit body — it is defined by its name and the number of parameters only. Add a variable of type Template Function from the variable form. Instead of a Definition field, a Number of parameters field is shown.
Template functions are useful when the exercise is about the function itself rather than a specific expression:
- Questions like "Given that
$\operatorname{f}$is a differentiable function…" wherefis not assigned a concrete formula. - Answer checking where the student's response should be expressed in terms of
fand its derivatives, without the engine expandingfto a concrete expression.
When a template function appears in a blank answer constraint, the engine checks whether both sides are symbolically equal without substituting the function's body (because there is no body to substitute).
Inserting a Custom Function in a Math Expression
Once a function variable is defined, it becomes available throughout the exercise wherever a math expression can be entered. There are three convenient ways to insert it:
1. Keyboard panel — Open the Functions tab on the virtual keyboard. Defined and template custom functions appear in a Custom Functions section at the top. Click a function key to insert a call.
2. Typing shortcut — In any math input field, typing the function name followed by ( e.g. f( auto-expands to a function call with placeholder arguments for each parameter.
3. Direct LaTeX — Type the full LaTeX call explicitly, e.g. \operatorname{f}\left(x\right).
The parser recognizes custom functions by their \operatorname{name} form. A bare unescaped name such as f typed in normal math mode is treated as an implicitly multiplied product of single-letter variables, not a function call — see the math engine conventions.
Inserting a Custom Function in Question Content
Custom functions are embedded in question content as part of a math expression, not using the [[variableName]] variable insertion syntax (that syntax is for scalar/expression variables only — see Variables & Simplification).
To display a function call in the question text, write it inside a math environment, for example:
Consider the function $\operatorname{f}\left(x\right) = x^2 + 1$.
Find $\operatorname{f}\left([[a]]\right)$.
See also: