## `generate::TeX` -- generate TeX formatted string from expressions

#### Introduction

`generate::TeX(`e`)` generates TeX output for an expression `e`.

#### Call(s)

`generate::TeX(e)`

#### Parameters

`e` | - | an arithmetical expression

#### Returns

`generate::TeX` returns a `string` containing TeX code.

### Overloadable:

`e`

#### Related Functions

`fprint`, `print`

#### Details

- `generate::TeX(`e`)` returns a TeX formatted string representing `e`. This string may be printed to a file using `fprint`. Use the printing option `Unquoted` to remove quotes and to expand special characters like newlines and tabs.
- The output string may be used in the math-mode of TeX. Note that `generate::TeX` doesn't break large formulas into smaller ones.

#### Example 1

`generate::TeX` generates a string containing the TeX code:

    >> generate::TeX(hold(int)(exp(x^2)/x, x))

               "\\int \\frac{\\mbox{exp}\\left(x^2\\right)}{x} d x"

Use `print` with option `Unquoted` to get a more readable output:

    >> print(Unquoted, generate::TeX(hold(int)(exp(x^2)/x, x)))

                   \int \frac{\mbox{exp}\left(x^2\right)}{x} d x

#### Example 2

This example shows how to write a `"TeX"`-method for a domain. The domain elements represent open intervals. The `"TeX"`-method makes recursive use of `generate::TeX` in order to TeX-format its operands and concatenates the resulting strings to a new string containing the TeX output of the interval.

    >> interval := newDomain("interval"):
       interval::TeX :=
         e -> "\\left]".generate::TeX(extop(e, 1)).
              ", ".generate::TeX(extop(e, 2))."\\right[":
       print(Unquoted,
             generate::TeX(new(interval, 1, x^(a+2)))):

                             \left]1, x^{a + 2}\right[

#### Background

- A domain overloading `generate::TeX` has to provide a function as its `"TeX"`-slot which translates its elements into a TeX formatted string. This function may use `generate::TeX` recursively. Cf. example 2.

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000