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
5
> %*4
20
> 1/%
0.05
> sin(%)
0.0499791692706783
> 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:

help

view the manual;

erase

erase currentpicture;

reset

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.

quit

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: https://tiswww.case.edu/php/chet/readline/readline.html

The file asymptote.py 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 3 the commands

from asymptote import *
g=asy()
g.size(200)
g.draw("unitcircle")
g.send("draw(unitsquare)")
g.fill("unitsquare, blue")
g.clip("unitcircle")
g.label("\"$O$\", (0,0), SW")