Skip to content
Classroom

Macros Overview

Macros are built-in functions that handle common operations in question writing — math formatting, string manipulation, array processing, conditional logic, and feedback generation.

Macro Categories

Category Purpose Key Functions
Math Numeric computations, rounding round(), gcd(), lcm(), mod()
String Text processing and formatting stringlen(), stringclean(), stringpos()
Array Array creation and manipulation array(), sortarray(), sumarray()
Format Display formatting prettyreal(), makereducedfraction(), makescinot()
Conditional Branching and logic if/else, comparison operators, in_array()
Feedback Adaptive hints and messages getfeedbackbasic(), getfeedbacktxt()

Using Macros

Macros are called in the question's code, in the Common Control box. They look like function calls:

$formatted = prettyreal($ans, 2);             // format $ans to 2 decimal places
$simplified = makereducedfraction($num, $den); // reduce a fraction to lowest terms

You can chain macro calls and use their return values in variable assignments, conditional checks, or directly in the question text.

Macros vs. PHP Functions

Many macros parallel standard PHP or math library functions, but are adapted for educational math contexts — for example, makereducedfraction() returns a fraction in lowest terms (makereducedfraction(6, 8) gives 3/4), and prettyreal() rounds a value to a fixed number of decimal places and adds thousands separators (prettyreal(1234.5, 2) gives 1,234.50).

The engine exposes a deliberate subset of native PHP — count(), in_array(), substr(), str_replace(), explode(), sprintf(), array_keys(), array_values(), array_reverse(), array_unique() and a few more. Anything outside that subset, including strlen(), sort() and implode(), is a hard error. Use the engine's own stringlen(), sortarray() and joinarray() instead.

Quick Reference

See each category page for the full list of available macros with examples.