fx9860g and fxcg50 2D math rendering library with support for TeX syntax.
Go to file
Heath Mitchell 12b8599370 Make the cursor enter text nodes when it's at the start or end of one 2023-02-25 17:54:15 +00:00
config implement environments and refactor 2019-06-12 12:53:50 -04:00
include/TeX More docs and rename a function 2023-01-29 14:14:05 +00:00
src Make the cursor enter text nodes when it's at the start or end of one 2023-02-25 17:54:15 +00:00
.gitignore update documentation after writing the wiki 2019-06-21 19:07:17 -04:00
Makefile initial commit: basic parsing, flow, rendering and some nodes 2019-05-28 22:11:05 -04:00
README.md expose display mode and inline mode 2019-06-19 11:52:09 -04:00
TODO.md update documentation after writing the wiki 2019-06-21 19:07:17 -04:00
configure use the proper shebang for bash 2019-06-19 14:17:10 -04:00
font5x7.bmp core: add products and integrals 2019-05-30 13:22:30 -04:00
font8x9.bmp core: add products and integrals 2019-05-30 13:22:30 -04:00
font10x12.bmp sdl2: add font rendering from a bitmap file 2019-05-29 15:58:06 -04:00

README.md

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.

\frac{x^7 \left[X,Y\right] + 3\left|\frac{A}{B}\right>}
     {\left\{\frac{a_k+b_k}{k!}\right\}^5}
+ \int_a^b \frac{\left(b-t\right)^{n+1}}{n!} dt
+ \left(\begin{matrix} \frac{1}{2} & 5 \\ -1 & a+b \end{matrix}\right)

Sample image

Features

  • Build formulae from TeX syntax or using the structural API
  • Highly-customizable graphical and layout parameters
  • Drawing uses only a few user primitives (point, line, text size, text)
  • Compatible with fxlib and gint

List of currently supported elements:

  • Fractions (\frac)
  • Subscripts and superscripts (_ and ^)
  • Grouping parentheses, brackets, and braces (\left and \right)
  • Grouping angle brackets, vertical lines, and dots (invisible)
  • Sums, products and integrals (\sum, \prod and \int)
  • Vectors (\vec) and limits (\lim)
  • Square roots (\sqrt)
  • Matrices (\begin{matrix} ... \end{matrix})

Features that are partially implemented (and what is left to finish them):

  • Support for inline style and display style (expose a parameter)
  • Theme that can decently port to fx-CG 50 (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 (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:

% ./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.

% 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_Env. 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 second parameter display is set to non-zero to use display mode (similar to \[ .. \] in LaTeX) or zero to use inline mode (similar to $ .. $ in LaTeX).

char *code = "\\frac{x_7}{\\left\\{\\frac{\\frac{2}{3}}{27}\\right\\}^2}";
struct TeX_Env *formula = TeX_parse(code, 1);

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):

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():

TeX_free(formula);