Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Dynamically calculating columns on Math symbols #26191

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

Closed

Conversation

NikosNikolaidis02
Copy link

PR summary

PR checklist

@NikosNikolaidis02
Copy link
Author

@oscargus can you check this pull request that doesn't have conflicts?

@oscargus
Copy link
Member

This looks fine from that aspect. Still, there are some linting errors.

@NikosNikolaidis02
Copy link
Author

This looks fine from that aspect. Still, there are some linting errors.
Could you advise me on how to solve them?

@rcomer
Copy link
Member

rcomer commented Jun 26, 2023

You can view the linting errors by clicking the “files changed” tab at the top of this page and scrolling down to see the comments from “reviewdog”.

@NikosNikolaidis02
Copy link
Author

All checks are passed! Can we merge it because I have deadline till today for a university project and I will enrich in the next days to be more efficient?

@QuLogic QuLogic requested a review from story645 June 26, 2023 16:47
Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better than before and the code doesn't look too bad, though I'd prefer a comment on how it's making decisions.

Can we merge it because I have deadline till today for a university project

So I'm not gonna try and teach you a lesson by blocking for this, but you really should communicate this with us earlier since most of us aren't paid to work on this-I'm not and I hadn't been planning on doing matplotlib stuff today.

@oscargus
Copy link
Member

oscargus commented Jun 26, 2023

though I'd prefer a comment on how it's making decisions.

Edit: I cannot even get my head around what it does. But now I think I am correct after several attempts. If basically takes the smallest number between 4 and 9 such that the number is not a integer factor of the number of elements.

max_reminder is never updated and the code can be rewritten as:

def columns_calculation(n):
    max_columns = columns = 10
    for columns_number in range(max_columns - 1, 3, -1):
        if n % columns_number:  # Not integer multiple
            columns = columns_number

    return columns
    
nvals = range(1, 100)
cols = [columns_calculation(n) for n in nvals]

import matplotlib.pyplot as plt
plt.bar(nvals, cols)

cols

So putting 4 is also a quite good heuristic.

@oscargus
Copy link
Member

You may want to check the discussion in #26183 @story645

My standpoint is still that this is not what is wanted.

@story645
Copy link
Member

@oscargus I think you're right that a better solution would take word and glyph length into account - there are still some lines that are not great-and use one or more of the dynamic reflow sphinx options.

I also think this solution produces easier to read tables than what is already there & removes the need to manually specify columns and is therefore a good incremental solution.

@oscargus
Copy link
Member

Better incremental solution that gives easier to read tables: 4. (I now got my head around the logic, so please reread the edited post.)

@oscargus
Copy link
Member

The only table that has 5 is because there are 32 items in it. Adding one and it will be 4 as all the others.

@oscargus
Copy link
Member

Changing the number of items, as is done in #26173 and #26176 will modify the outcome (although I have not bothered to compute the number of entries there).

I'd say that picking a column number based on a probability as 4: 75%, 5: 20%, 6: 4%, 7: 1% is a comparable approach.

Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @NikosNikolaidis02 I will block this change (the discussion made me look closer to the actual code).

  1. It uses an algorithm that is not related to the problem at hand (the problem is the width of the items, not the number of items).
  2. This means that the outcome of columns_calculations may just as well be constant 4 or selected at random between 4 and 5 (or some other distribution). Clearly those two approaches are not what we are looking for, but would be comparable.
  3. The code quality is low. remainder is initialized, but value never used. max_remainder is just a constant. len(my_list) is computed in the loop.

If you want to try to finalize this, I'd suggest finding the longest string in the list/set in syms and then use that to figure out a suitable number of columns. (Basically some function that is non-increasing as the string length increases.) Even if it may take some time to find the "best" such function, a working one is OK for now, that will at least be a method that tries to approach the problem at hand.

@NikosNikolaidis02
Copy link
Author

Ok! I will look at it! Thank you!

@NikosNikolaidis02
Copy link
Author

I was thinking about finding the sum of characters on each line and choose how many columns (from 4 to 7) will have the most equally distributed summary on each line.

@story645
Copy link
Member

story645 commented Jun 26, 2023

I'd suggest finding the longest string in the list/set in syms and then use that to figure out a suitable number of columns.

If you're gonna do this, you're gonna want to probably make the (latex, symbol) tuples and use that as longest symbol, and really this becomes an optimization problem & at that point it's likely easier to see if it's already solved by pretending it's a table of individual elements and using auto https://sphinx-design.readthedocs.io/en/latest/grids.html#item-level-column-width

ETA: Honestly I also think @oscargus's set width to 4 solution - where you strip the function call out and replace it w/ 4 is an improvement.

@rcomer
Copy link
Member

rcomer commented Sep 18, 2023

@NikosNikolaidis02 are you still interested in working on this?

@rcomer
Copy link
Member

rcomer commented Nov 18, 2023

I am going to close this one as it has stalled for a while and comments above state that the current implementation is not what is wanted. @NikosNikolaidis02 please comment if you are still interested in working on this and we can re-open.

@rcomer rcomer closed this Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[Doc]: dynamically resize the mathtext symbol tables
5 participants