Kolaru / MathTeXEngine.jl

A latex math mode engine in pure Julia.
MIT License
96 stars 20 forks source link

Support \overline command #79

Closed karlwessel closed 2 years ago

karlwessel commented 2 years ago

It seems like the \overline command is not supported yet.

I guess it would be rather simple adding it, since it basically does the same as the \sqrt command but without the actual root in front.

I had a quick go on it myself but couldn't exactly understand everything that happens in the tex_layout method. Especially what it is supposed to return.

Kolaru commented 2 years ago

Thanks for reporting that.

tex_layout works recursively. The general idea is

  1. Reckognize what type of element is being layouted (e.g. sqrt or frac)
  2. Layout each subelements (e.g. the group of elements inside a sqrt or the denominator and numerator of a frac) individually calling tex_layout on their TeXExpr (which all come from the parser).
  3. Now that we have the layout information (typically inkwidth and inkheight) available, we can use them to place the subelements themselves relative to each other and add any additonal one that are needed (e.g. the horizontal bar for sqrt -- knowing the width and height of the content we can compute its position and length)
  4. Return a Group which has 3 parts
    • A list of the subelements (e.g. Group, TeXChar or HLine)
    • A list of their relative positions
    • A list of their relative scale (often just 1 for each subelement)

This may be a bit different from other systems, since each of the element is immutable and doesn't know its own position or scale, only its parent does.

This results in a deeply nested structure that is flatten at a latter point.

If you want to have another go at it and have any question, don't hesitate to ask.

karlwessel commented 2 years ago

Thanks for the explanation. I created a pull request with my first take on the implementation. Layout probably needs some fine tuning.

It would probably also be good to add your explanation to the source code, or maybe a file src/layout/readme.md, similiar to parser.md.

karlwessel commented 2 years ago

Fixed by #80