Next: , Previous: , Up: Top   [Contents][Index]

10 Interactive mode

Interactive mode is entered by executing the command asy with no file arguments. When the -multiline option is disabled (the default), each line must be a complete Asymptote statement (unless explicitly continued by a final backslash character \); it is not necessary to terminate input lines with a semicolon. If one assigns settings.multiline=true, interactive code can be entered over multiple lines; in this mode, the automatic termination of interactive input lines by a semicolon is inhibited. Multiline mode is useful for cutting and pasting Asymptote code directly into the interactive input buffer.

Interactive mode can be conveniently used as a calculator: expressions entered at the interactive prompt (for which a corresponding write function exists) are automatically evaluated and written to stdout. If the expression is non-writable, its type signature will be printed out instead. In either case, the expression can be referred to using the symbol % in the next line input at the prompt. For example:

> 2+3
> %*4
> 1/%
> sin(%)
> currentpicture
<picture currentpicture>
> %.size(200,0)

The % symbol, when used as a variable, is shorthand for the identifier operator answer, which is set by the prompt after each written expression evaluation.

The following special commands are supported only in interactive mode and must be entered immediately after the prompt:


view the manual;


erase currentpicture;


reset the Asymptote environment to its initial state, except for changes to the settings module (see settings), the current directory (see cd), and breakpoints (see Debugger);

input FILE

does an interactive reset, followed by the command include FILE. If the file name FILE contains nonalphanumeric characters, enclose it with quotation marks. A trailing semi-colon followed by optional Asymptote commands may be entered on the same line.


exit interactive mode (exit is a synonym; the abbreviation q is also accepted unless there exists a top-level variable named q). A history of the most recent 1000 (this number can be changed with the historylines configuration variable) previous commands will be retained in the file .asy/history in the user’s home directory (unless the command-line option -localhistory was specified, in which case the history will be stored in the file .asy_history in the current directory).

Typing ctrl-C interrupts the execution of Asymptote code and returns control to the interactive prompt.

Interactive mode is implemented with the GNU readline library, with command history and auto-completion. To customize the key bindings, see:

The file in the Asymptote system directory provides an alternative way of entering Asymptote commands interactively, coupled with the full power of Python. Copy this file to your Python path and then execute from within Python the commands

from asymptote import *
g.fill("unitsquare, blue")
g.label("\"$O$\", (0,0), SW")

Next: , Previous: , Up: Top   [Contents][Index]