# LinearOutputFormatΒΆ

LinearOutputFormat provides a coercion from OutputForm to a linear format with the aim to enable cut&paste from FriCAS into itself or possibly another computer algebra system.

- altsupersub: (String, Integer) -> (Integer, List OutputForm) -> List String
`altsupersub(cmd, p)`

returns a handler such that`altsupersub(cmd, p)(prec, args)`

formats the first argument with respect to the precedence`p`

. The remaining arguments are formatted without parentheses and interpreted as subscript, superscript, subscript, superscript, etc. where the subscripts and superscripts are pairwise aligned. Outer parentheses are added if`p < prec`

.

- binary2: (String, Integer, Integer, Integer) -> (Integer, List OutputForm) -> List String
`binary2(cmd, p, p1, p2)`

returns a handler such that`binary2(cmd, p, p1, p2)(prec, args)`

formats`args.1`

and`args.2`

according to the precedences`p1`

and`p2`

, respectively. It puts the result into the first and second argument of the command given by`cmd`

. Outer parentheses are added if`p < prec`

.

- binary: (String, Integer) -> (Integer, List OutputForm) -> List String
`binary(cmd, p)`

is identical to`binary2(cmd, p, p, p`

.

- binaryNoParen: String -> (Integer, List OutputForm) -> List String
`binaryNoParen(cmd)`

returns a handler such that`binaryNoParen(cmd)(prec, args)`

formats`args.1`

and`args.2`

without outer parentheses and puts the result into the first and second argument of the command given by`cmd`

.- coerce: % -> OutputForm
- from CoercibleTo OutputForm

- coerce: OutputForm -> %
`coerce(o)`

changes`o`

in the standard output format to 1-dimensional format.- convert: (OutputForm, Integer) -> %
- from OutputFormatterCategory
- display: % -> Void
- from OutputFormatterCategory

- display: (%, Integer) -> Void
`display(t, width)`

outputs the 1D formatted code`t`

so that each line has length less than or equal to spadvar{width}.

- formatExpression: (OutputForm, Integer) -> List String
`formatExpression(o, p)`

returns a list of strings that represent the expression`o`

in 1D-format when considered in a context with outer precedence`p`

. This function is the main dispatcher function. It first checks whether`o`

is an integer or a string and treats these cases. Then, if the number`n`

of arguments is less than 3, it tries to find a handler for the top-level operator of`o`

. If none is found, it checks for a handler of an`n`

-ary operator. If no handler is found, the operator is treated as a function symbol and formatted as such.

- handler: (Integer, String) -> (Integer, List OutputForm) -> List String
`handler(n, op)`

is only valid if`knownOperator?(n, op)`

. It returns a function that takes the current precedence and the current list of arguments of the structure for operator`op`

and returns a list of strings representing that operator and its arguments in 1D-format.

- infix: (String, Integer, Integer, Integer) -> (Integer, List OutputForm) -> List String
`infix(op, p, p1, p2)`

returns a handler such that`infix(op, p, p1, p2)(prec, args)`

formats`args.1`

and`args.2`

according to the precedences`p1`

and`p2`

, respectively. It puts the result into the first and second argument of the operator given by`op`

. Outer parentheses are added if`p < prec`

.

- knownOperator?: (Integer, String) -> Boolean
`knownOperator?(n, op)`

checks an internal data structure whether a handler for operator`op`

is known. The number`n`

denotes the number of arguments of the operator can take. For this function`n`

is either 0, 1, 2 or`-1`

where the value`-1`

stand for “the operator takes arbitrarily many arguments”. It is OK if both`knownOperator?(m, op)`

and`knownOperator?(n, op)`

return`true`

for different`m`

and`n`

.

- matrix: String -> (Integer, List OutputForm) -> List String
`matrix(prefix)`

returns a handler that typesets a matrix in a simple linear form.

- nary: (String, Integer) -> (Integer, List OutputForm) -> List String
`nary(sep, p)`

returns a handler such that`nary(sep, p)(prec, args)`

formats the arguments according to the precedence`p`

. These arguments will be separated by the string`sep`

. Outer parentheses are added if`p < prec`

.

- naryNoParen: String -> (Integer, List OutputForm) -> List String
`naryNoParen(cmd)`

returns a handler such that`naryNoParen(cmd)(prec, args)`

formats all arguments without outer parentheses. These arguments will be separated by the string`cmd`

.

- new: () -> %
`new()`

create a new, empty object. Use setPrologue!, setFormat! and setEpilogue! to set the various components of this object.

- nullary: String -> (Integer, List OutputForm) -> List String
`nullary(cmd)`

is a handler to format nullary operators. That handler simply returns`cmd`

.

- operatorWithLimits: (String, Integer) -> (Integer, List OutputForm) -> List String
`operatorWithLimits(cmd, p)`

returns a handler such that`operatorWithLimits(cmd, p)(prec, args)`

formats the arguments without parentheses and interprets the arguments as upper or lower limits/indices of an operator.`cmd`

is assumed to be a operator like $SUM$, $PROD$, or $INT$. Outer parentheses are added if`p < prec`

.

- paren: (String, String, (Integer, List OutputForm) -> List String) -> (Integer, List OutputForm) -> List String
`paren(left, right, h)`

returns a handler such that`paren(left, right, h)(prec, args)`

formats the arguments via`h(prec, args)`

and then puts`left`

and`right`

at the beginning respectively end of the result.

- removeOperator!: (Integer, String) -> Void
`removeOperator(n, op)`

removes any handler from an internal data structure (for the pair`(n, op)`

such that afterwards`knownOperator?(n, op)`

returns`false`

.

- scripts: (String, Integer) -> (Integer, List OutputForm) -> List String
`scripts(cmd, p)`

returns a handler such that`scripts(cmd, p)(prec, args)`

formats the first argument with respect to the precedence`p`

. The other arguments are formatted without parentheses and interpreted as subscript, superscript, presuperscript, and presubscript (in this order). Outer parentheses are added if`p < prec`

.

- setEpilogue!: (%, List String) -> List String
`setEpilogue!(t, strings)`

sets the epilogue section of a 1D form`t`

to strings.

- setFormat!: (%, List String) -> List String
`setFormat!(t, strings)`

sets the linear section of a 1D-form`t`

to strings.

- setHandler!: (Integer, String, (Integer, List OutputForm) -> List String) -> (Integer, List OutputForm) -> List String
`setHandler!(n, op, hdl)`

puts`hdl`

into an internal data structure such that it can be queried afterwards. Setting or modifying a handler should be done with great care since it gives complete freedom of how an operator is treated.

- setPrologue!: (%, List String) -> List String
`setPrologue!(t, strings)`

sets the prologue section of a 1D-form`t`

to strings.

- subscript: (String, Integer) -> (Integer, List OutputForm) -> List String
`subscript(cmd, p)`

returns a handler such that`subscript(cmd, p)(prec, args)`

formats the first argument with respect to the precedence`p`

. The other arguments are formatted without parentheses and interpreted as subscripts separated by commas. Outer parentheses are added if`p < prec`

.

- theMap: String -> (Integer, List OutputForm) -> List String
`theMap(cmd)`

is a special handler to format a function.

- unary: (String, Integer, Integer) -> (Integer, List OutputForm) -> List String
`unary(cmd, p, p1)`

returns a handler such that`unary(cmd, p, p1)(prec, args)`

formats`args.1`

according to the precedence`p1`

and puts the result into the argument of the command given by`cmd`

. Outer parentheses are added if`p < prec`

.