# TexFormat¶

TexFormat provides a coercion from OutputForm to TeX format. The particular dialect of TeX used is LaTeX, but for flexibility reasons TexFormat outputs everything into a fricasmath environment in which certain additional commands are avaiblable. These commands are defined in a .sty file that is distributed with the source code of FriCAS.

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 TeX 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 TeX command given by cmd.
coerce: % -> OutputForm
from CoercibleTo OutputForm
coerce: OutputForm -> %
coerce(o) changes o in the standard output format to TeX format.
convert: (OutputForm, Integer) -> %
convert(o, step) changes o in standard output format to TeX format and also adds the given step number. This is useful if you want to create equations with given numbers or have the equation numbers correspond to the interpreter step numbers. This function will be called after ‘)set output tex on’ has been executed in an interpreter session.
display: % -> Void
display(t) outputs the TeX formatted code t so that each line has length less than or equal to the value set by the system command spadsys{)set output length}.
display: (%, Integer) -> Void
display(t, width) outputs the TeX formatted code t so that each line has length less than or equal to spadvar{width}.
environment: (String, String, String) -> (Integer, List OutputForm) -> List String
environmnt(env, x, sep) returns a handler that typesets its arguments (without parentheses) in a LaTeX environment with name env. The string x is put right after the start of the environment. The arguments are separated by the string sep.
epilogue: % -> List String
epilogue(t) extracts the epilogue section of a TeX form t.
formatExpression: (OutputForm, Integer) -> List String
formatExpression(o, p) returns a list of strings that represent the expression o in TeX 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 ths 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 TeX format.
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, String) -> (Integer, List OutputForm) -> List String
matrix(env, sep) returns a handler that typesets a matrix in a LaTeX environment with name env that takes one argument. The argument to this environment is the number of columns of the matrix. The rows are separated by the string sep.
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!, setTex! 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. It simply returns cmd, i.e. cmd must not change it meaning even if some arbitrary string is appended to it. In other words, add a space or a pair of braces after it, if this is necessary.
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 TeX operator like $sum$, $prod$, or $int$. Outer parentheses are added if p < prec.
prologue: % -> List String
prologue(t) extracts the prologue section of a TeX form t.
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 TeX 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 TeX form t to strings.
setTex!: (%, List String) -> List String
setTex!(t, strings) sets the TeX section of a TeX 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.
tex: % -> List String
tex(t) extracts the TeX section of a TeX form t.
theMap: String -> (Integer, List OutputForm) -> List String
theMap(cmd) is a special handler to format a function. The respective function name will be put into the argument of a TeX command given by cmd.
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 TeX command given by cmd. Outer parentheses are added if p < prec.
unaryNoParen: String -> (Integer, List OutputForm) -> List String
unaryNoParen(cmd) returns a handler such that unaryNoParen(cmd)(prec, args) formats args.1 without outer parentheses and puts the result into the argument of the TeX command given by cmd.