Skip to content

Imports

import "./file.axis" drops the whole of another file in, exactly as if it had been typed here, and puts it in a folder of its own. The path is relative to this file, and the .axis may be left off.

An imported file is flattened first: whatever folders it organises itself with are dropped, and everything they held joins the one folder the import makes. Desmos has one level of folders, and the import has claimed it.

examples/16-imports.axis

config {
showGrid: true
}
"Two libraries, each arriving as one folder."
// The folder is named after the file - "waves" - unless the import says
// otherwise, and metadata on the statement styles it like any other folder.
// An import's folder starts collapsed, since what is in it is written and read
// elsewhere; `collapsed: false` opens it.
import "./lib/waves.axis" as "Waves" @ collapsed: false
// This one imports a file of its own; both land in the same folder.
import "./lib/envelope.axis"
// Everything an import brings is in scope - its definitions, and its macros and
// styles too - so the graph itself is written against it.
y = sine(x) * envelope(x) @ color: RED, lineWidth: 3
y = envelope(x) @ color: BLACK, lineStyle: DOTTED
y = -envelope(x) @ color: BLACK, lineStyle: DOTTED
folder "Comparison" {
// An import inside a folder joins that folder rather than opening a new
// one, for the same reason: there is nowhere for a second level to go.
y = cosine(x) * envelope(x) @ color: BLUE, lineWidth: 2
}
Open in playground →