-
Notifications
You must be signed in to change notification settings - Fork 64
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
Auto bracket improvements #156
base: master
Are you sure you want to change the base?
Auto bracket improvements #156
Conversation
Now 12(12)^2 explicitly renders the brackets
Now ab^2 does not put brackets, but 12(12)^2 does.
Provisionally, this seems to work great--even on things like |
One edge-case that comes to mind is (and this is not proper notation at all, but still): definite_integral(1, 2, x, 2)4 renders as int_1^2 x d24 when perhaps it should render as int_1^2 x d(2)4. The problem is if you require, say, no adjacent numbers either before or after, then 2^3 4 will get brackets when it shouldn't. Perhaps the right thing to do in the case of adjacent numbers like this is to bracket the entire symbol, so 12(12^2) or (int_1^2 x d2)4. |
On second look, this PR also causes For example, the LaTeX rendering for integral is
If you want to try morphing this PR into something that addresses the above concerns, this is fine, but I realise it is a tall order and have mostly left this as a musing to return to when I next get time to code on this. I appreciate both the attempt and driving forward the business of fixing this issue. |
Thanks for the comments. Another thing that might be required to check, is to see if the node with the auto bracket and the corresponding node before or after it contains the same value for Feel free to close this PR when you get around to implementing a proper fix. I doubt my way of trying to implement your comments would be ideal, so I will refrain from modifying this PR. |
Yeah, I think it's even subtler than I'd thought at first; e.g. imagine Another edge-case, which may raise the Another, perhaps simpler option, for those cases is that blank e nodes are rendered in LaTeX with a small amount of horizontal space. At any rate, I'll work on it but will leave this PR open as a way of tracking the various ideas/issues around this problem and then close when it's resolved. |
I thought of another option that would only work for the exp symbol. It would be to consider the exp symbol like the multiply symbol in that the what's left and right of the multiply symbol aren't actually its children, even though they technically belong under it. I presume it is done like this so that it makes it easy to break out of the multiply symbol by, for example, typing a plus in front of it and have to manually group text together with parenthesis if otherwise implied. This same concept can be applied to the exp symbol and would involve making the symbol only have one input like so, "^{{$1}}" and letting the parser group it together correctly. |
That sounds like a good idea, it should work! |
Now brackets are shown when the previous character is a number.
E.g. Typing
12(12)^2
now explicitly renders the brackets butab^2
,12+12^2
or12*12^2
does not.This fixes #135 but when importing the syntax tree, the multiplication becomes hidden.
E.g.
3*10^8
becomes3(10)^8
. I guess this is expected as the syntax tree does not contain this information. Maybe there should be another symbol, likemul_implicit
to differentiate the two?