# Macro Language

## Introduction

There are ~ 230 commands, ~55 math functions and ~90 constants available in the Plot macro language. Most of the commands need one or more argument. Simply enter the command followed by the arguments separated by spaces. Multiple commands in one line must be separated with `:`. If an argument contains spaces you have to quote the argument with `"`. Comments can be escaped with `#`. For example a command may look like this:

`atext xb "Axis Text"`
`clr : list : exit`

This command sets the axis text label for the first (bottom) X axis.

Note: some macro commands does not fully work with the Plot2 version from the AppStore. Use the download version instead.
http://apps.micw.org/apps/plot2/downloads.php

## Variables

During macro execution several variables are available. String variable starts with a `$` sign.

`cb` | number of the current working buffer in the document
`$date` | the current date
`$document` | the filename of the current document
`dx1` | the distance between the last two measures with the mouse (1. X axis)
`dx2` | the distance between the last two measures with the mouse (2. X axis)
`dy1` | the distance between the last two measures with the mouse (1. Y axis)
`dy2` | the distance between the last two measures with the mouse (2. Y axis)
`$file` | the filename from the `browse` command
`framebottom` | the position of bottom frame line
`frameleft` | the position of left frame line
`frameright` | the position of right frame line
`frametop` | the position of top frame line
`framewidth` | the width of the frame
`$home` | the users home directory
`input` | the result of the last input command
`$input` | the result of the last input command as string
`integral` | the result from the last `calcint` command
`l` | the run variable for loops
`lx` | the X value during a data loop
`ly` | the Y value during a data loop
`lxe` | the X error value during a data loop
`lye` | the X error value during a data loop
`lastbuffer` | the number of the last buffer generated by one of the calculation commands
`marginbottom` | the bottom margin
`marginleft` | the left margin
`marginright` | the right margin
`margintop` | the top margin
`nb` | number of data buffer in the document
`option` | the result of the `askoption` command
`ref1` | the 1. reference value
`ref2` | the 2. reference value
`linbga`, `linbgb` | the reference values for linear background subtraction
`rega`, `regb`, `regr` | the result of the last regression
`textheight` | the height of the last added text
`textwidth` | the width of the last added text
`$time` | the current time
`$user` | the user name
`viewheight` | the height of the current view
`viewwidth` | the width of the current view
`windowheight` | the window height
`windowwidth` | the window width
`xpos1` | the last result of the measure with the mouse (1. X axis)
`xpos2` | the last result of the measure with the mouse (2. X axis)
`ypos1` | the last result of the measure with the mouse (1. Y axis)
`ypos2` | the last result of the measure with the mouse (2. Y axis)
`xmin1` | min value of the 1. (bottom) X axis
`xmax1` | max value of the 1. (bottom) X axis
`ymin1` | min value of the 1. (left) Y axis
`ymax1` | max value of the 1. (left) Y axis
`xmin2` | min value of the 2. (top) X axis
`xmax2` | max value of the 2. (top) X axis
`ymin2` | min value of the 2. (right) Y axis
`ymax2` | max value of the 2. (right) Y axis
`ut` | the number of seconds from the reference date (00:00:00 UTC on 1 January 1970), aka unix timestamp
`mt` | the number of seconds from the absolute reference date (00:00:00 UTC on 1 January 2001)

## Arguments

In the command descriptions on the following pages optional argument is written with surround square brackets (`[argument]`) and required arguments with angle brackets (`<argument>`).

There are also some special arguments:

`<BUFFER>`

a list of one or more data buffers. Possible values are:

`all` | all buffers in the document
`selected` | selected buffers in the document
`unselected` | unselected buffers in the document
`visible` | visible buffers in the document
`hidden` | hidden buffers in the document
`none` | no buffer
`b1,b2,b3,...,bn` | a list of buffers where the arguments may be math expressions.
`bs..be` | buffers from bs to be

`<AXIS>`

A definition of the four axis. Possible values are:

`all` | all four axis
`x` | both X axis
`y` | both Y axis
`1, x1, xb, bottom` | 1. X axis (bottom)
`2, y1, yl, left` | 1. Y axis (left)
`3, x2, xt, top` | 2. X axis (top)
`4, y2, yr, right` | 2. Y axis (right)

`<AXISGROUP>`

The coordinates system:

`0, both` | both axis
`1, first` | first axis (left and bottom)
`2, second` | second axis (right and top)

`<AXISFORMAT>`

The axis format:

`0, lin` | linear axis
`1, log` | logarithmic axis
`2, time` | time axis
`3, bin` | binary axis with base 2 numbers

`<NUMBERFORMAT>`

The axis number format:

`0, sci` | numbers with scientific notation
`1, eng` | numbers with engineering notation
`2, si` | numbers with SI notation

`<COOR>`

The coordinates system:

`0, screen` | screen coordinates
`1, first` | first axis (left and bottom)
`2, second` | second axis (right and top)

`<RANGE>`

A list of numbers (e.g. used for the `loop` command):

`n` | defines a range from 0 to n
`from;to;step` | defines a range where the arguments may be math expressions.
`b1,b2,b3,...,bn` | a list of numbers where the arguments may be math expressions.
`bs..be` | numbers from bs to be

`<COLOR>`

This can be a hexadecimal color definition in the format RGB, ARGB, RRGGBB or AARRGGBB where R is red, G is green, B is blue and A is alpha.

There are also named colors which can be used: black, white, red, green, blue, orange, yellow, magenta, cyan, aluminum, aqua, asparagus, banana, blueberry, bubblegum, cantaloupe, carnation, cayenne, clover, eggplant, fern, flora, grape, honeydew, ice, iron, lavender, lead, lemon, licorice, lime, magnesium, maraschino, maroon, mercury, midnight, mocha, moss, nickel, ocean, orchid, plum, salmon, seafoam, silver, sky, snow, spindrift, spring, steel, strawberry, tangerine, teal, tin, tungsten, turquoise

The Plot default colors can be addressed with the numbers 0-15