Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial layout for matrices #111

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

adamslc
Copy link

@adamslc adamslc commented Nov 10, 2023

This builds on the work in #56 (which itself builds on #50). All those commits
have been rebased onto master for convience.

I implemented a simple layout algorithm for matrices (only supports matrix
right now, but extending to include pmatrix and bmatrix should be possible).
It works quite well for simple entries, although perhaps the entries should be
centered horizontally and vertically.
test.pdf

However, you can see that the layout is very poor when taller notation (e.g.
fractions) are used. I think this results from a misunderstanding on my part of
how they layout is done. In the second attached pdf, you can see pairs of
horizontal lines where I think the symbols should be, which disagrees quite
dramatically with where they are.
test_vert_extent.pdf

@codecov-commenter
Copy link

Codecov Report

Attention: 88 lines in your changes are missing coverage. Please review.

Comparison is base (91aefd0) 81.02% compared to head (18a03e5) 70.96%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #111       +/-   ##
===========================================
- Coverage   81.02%   70.96%   -10.07%     
===========================================
  Files          10       10               
  Lines         585      675       +90     
===========================================
+ Hits          474      479        +5     
- Misses        111      196       +85     
Files Coverage Δ
src/parser/commands_registration.jl 87.50% <0.00%> (-1.01%) ⬇️
src/engine/layout.jl 76.43% <0.00%> (-13.80%) ⬇️
src/parser/texexpr.jl 55.55% <0.00%> (-24.81%) ⬇️
src/parser/parser.jl 63.18% <29.41%> (-12.60%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Kolaru
Copy link
Owner

Kolaru commented Nov 13, 2023

Thanks a lot for the PR !

The alignment problem is there because of where the origin of glyphs (and TeXElements) is. Basically if you draw a TeXElement at position (0, 0) it should sit correctly on the text baseline, at the leftmost reasonable point.

This graph has been quite useful to me (xMin, xMax, yMin and yMax are ink bounds, leftinkbound, rightinkbound, bottominkbound and topinkbound respectively in term of MathTeXEngine functions)
image

As a consequence, the vertical offset[*] for a pair of row (top, bot) should be something like bottominkbound(top) - row_gap - topinkbound(bot). The minus signs are there because the offset goes negative as we go down the page.

Then an additional global offset is needed to set the origin of the matrix itself correctly.

[*] The same principle apply for horizontal, but it doesn't matter as much, because the horizontal origin in always roughly at the left edge.

Regarding the other matrix types, I believe we can just translate them to be surrounded by adaptive parentheses, like \left( \begin{matrix} ... \end{matrix} \right) and it should work fine. It can be a separate PR too.

Also in the prototype folder there is a script that can draw the bounding box of all characters, you may find it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants