# Natural display engine with TeX syntax for fx-9860G and fx-CG 50
This library is a customizable 2D math rendering tool for calculators. It can be used to render 2D formulae, either from an existing structure or TeX syntax.
Features that are partially implemented (and what is left to finish them):
* Support for inline style and display style (compute display-style subscript
and superscript layout, and expose a parameter)
* API functions to build TeX objects without a TeX formula (expose functions
which are currently in the parser)
* Full fx-CG 50 support (suitable parenthesis styles)
See the `TODO.md` file for more features to come.
## Building
First specify the platform you want to use :
*`cli` is for command-line tests, with no visualization (PC)
*`sdl2` is an SDL interface with visualization (font support coming) (PC)
*`fx9860g` builds the library for fx-9860G targets (calculator)
*`fxcg50` builds the library for fx-CG 50 targets (calculator)
For calculator platforms, you can use `--toolchain` to specify a different toolchain than the default `sh3eb` and `sh4eb`. The install directory of the library is guessed by asking the compiler, you can override it with `--prefix`.
Example for an SDL setup:
```sh
% ./configure --platform=sdl2
```
Then you can make the program, and if it's a calculator library, install it. You can later delete `Makefile.cfg` to reset the configuration, or just reconfigure as needed.
```sh
% make
% make install # fx9860g and fxcg50 only
```
## Using in a program
Before using the library in a program, a configuration step is needed. The library does not have drawing functions and instead requires that you provide some, namely:
* Draw a pixel (`TeX_intf_pixel`)
* Draw a line (`TeX_intf_line`)
* Compute the size occupied by a string (`TeX_intf_size`)
* Render a string (`TeX_intf_text`)
The three rendering functions are available in fxlib; for monospaced fonts the fourth can be implemented trivially. In gint, the four can be defined as wrappers for `dpixel()`, `dline()`, `dsize()` and `dtext()`.
The type of formulae is `TeX_Flow`. To parse and compute the size of a formula, use the `TeX_parse()` function, which returns a new formula object (or `NULL` if a critical error occurs).
The size of the formula can be queried through `formula->width` and `formula->height`. To render, specify the location of the top-left corner and the drawing color (which will be passed to all primitives):
```c
TeX_draw(formula, 0, 0, BLACK);
```
The same formula can be drawn several times. When it is no longer needed, free it with `TeX_free()`: