Browse Source

core: add grouping vertical lines and update README

master
Lephenixnoir 6 months ago
parent
commit
a1b2b79410
3 changed files with 16 additions and 6 deletions
  1. +6
    -2
      README.md
  2. +6
    -0
      src/classes.c
  3. +4
    -4
      src/platform/sdl2.c

+ 6
- 2
README.md 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):


+ 6
- 0
src/classes.c 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;
}
}


+ 4
- 4
src/platform/sdl2.c 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; }

Loading…
Cancel
Save