core: add grouping vertical lines and update README

This commit is contained in:
Lephenixnoir 2019-05-30 11:40:18 -04:00
parent 06291194bc
commit a1b2b79410
3 changed files with 16 additions and 6 deletions

View File

@ -3,10 +3,12 @@
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.
```latex
\frac{x_7}{\left\{\frac{\frac{2}{3}}{27}\right\}^2}
\frac{x^7\left[X,Y\right]+3\left|\frac{A}{B}\right>}
{\left\{\frac{a_k+b_k}{5!}\right\}^n}
+ \sum_{k=1}^nk(-1)^k
```
![Sample image](https://framapic.org/v4ODO95ftSAV/szXvX2amwuUN.png)
![Sample image](https://framapic.org/MGABuOpMUDxn/duzY5eaLNVTj.png)
## Features
@ -21,6 +23,8 @@ 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)
* Summation symbols
Features that are partially implemented (and what is left to finish them):

View File

@ -118,6 +118,8 @@ void leftright_size(struct TeX_Node *node)
if(node->subtype == '<' || node->subtype == '>')
node->width = TEX_LEFTRIGHT_ANGLE_WIDTH;
if(node->subtype == '|')
node->width = 1;
}
void leftright_render(struct TeX_Node const * node, int x, int y, int color)
@ -183,6 +185,10 @@ void leftright_render(struct TeX_Node const * node, int x, int y, int color)
TeX_line(x + w - 1, y + l, x, y, color);
TeX_line(x + w - 1, y + l, x, y + h - 1, color);
break;
case '|':
TeX_line(x, y, x, y + h - 1, color);
break;
}
}

View File

@ -117,7 +117,7 @@ static void init(void)
if(SDL_Init(SDL_INIT_VIDEO) < 0) fail("failed to initialize SDL");
int c = SDL_WINDOWPOS_CENTERED;
w = SDL_CreateWindow("2D rendering", c, c, 256, 128, 0);
w = SDL_CreateWindow("2D rendering", c, c, 320, 240, 0);
if(!w) fail("cannot create SDL window");
r = SDL_CreateRenderer(w, -1, SDL_RENDERER_ACCELERATED);
@ -161,9 +161,9 @@ static void fini(void)
int main(void)
{
char const * formula =
"\\frac{x_7}{"//\\left<X,Y\\right>+3\\left<\\frac{A}{B}\\right>}{"
"\\left\\{\\frac{\\frac{2}{3}}{27}\\right\\}^2"
"} + \\sum_{k=1}^nk";
"\\frac{x^7\\left[X,Y\\right]+3\\left|\\frac{A}{B}\\right>}{"
"\\left\\{\\frac{a_k+b_k}{5!}\\right\\}^n"
"} + \\sum_{k=1}^nk(-1)^k";
struct TeX_Flow *flow = TeX_parse(formula);
if(!flow) { puts("parsing error!"); return 1; }