Graph & Table Macros¶
Use these macros to generate inline graphs and data tables within question text or solution text.
Graphs¶
drawgraph($settings)¶
Generates an inline coordinate-plane graph. Pass a settings string that configures the function, scale, and display options.
Basic usage:
$graph = drawgraph("xmin=-5,xmax=5,ymin=-5,ymax=5,f=$a*x+$b");
Then display in question text:
<p>Use the graph below to answer the question.</p>
$graph
Common Graph Settings¶
| Setting | Default | Description |
|---|---|---|
xmin, xmax |
-10, 10 | X-axis range |
ymin, ymax |
-10, 10 | Y-axis range |
f |
(none) | Function to plot, e.g. f=x^2-3 |
points |
(none) | Specific points, e.g. points=(1,2),(3,4) |
width |
300 | Graph width in pixels |
height |
300 | Graph height in pixels |
grid |
1 | Show grid (1=yes, 0=no) |
axes |
1 | Show axes (1=yes, 0=no) |
Multiple Functions¶
Plot several functions on one graph by separating them with semicolons:
$graph = drawgraph("xmin=-5,xmax=5,ymin=-5,ymax=5,f=$a*x+$b;-$a*x+$b");
Drawing Question Graphs¶
For Drawing question types, use drawsetup() to configure the student's drawing canvas:
$setup = drawsetup("xmin=-5,xmax=5,ymin=-5,ymax=5,grid=1");
See the Drawing question type page for full options.
Tables¶
arraytable($array, $headers)¶
Generates an HTML table from an array of values.
$data = array(1, 4, 9, 16, 25);
$headers = array("n", "n²");
$table = arraytable($data, $headers);
matrixtable($matrix)¶
Displays a 2D array as a formatted matrix table:
$m = array(array(1, 2), array(3, 4));
$table = matrixtable($m);
Manual HTML Tables¶
For full control, write HTML directly in the question text:
<table>
<thead><tr><th>x</th><th>f(x)</th></tr></thead>
<tbody>
<tr><td>0</td><td>`$f0`</td></tr>
<tr><td>1</td><td>`$f1`</td></tr>
<tr><td>2</td><td>`$f2`</td></tr>
</tbody>
</table>
Images¶
To include a static image in a question, upload it to the question's file library and reference it:
<img src="$imgurl" alt="Description of the figure" />
Where $imgurl is the URL returned after uploading through the question editor's media library.