Kolaru / MathTeXEngine.jl

A latex math mode engine in pure Julia.
MIT License
97 stars 19 forks source link

Support \overline command #79

Closed karlwessel closed 1 year ago

karlwessel commented 1 year 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 1 year 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 1 year 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 1 year ago

Fixed by #80