-
Notifications
You must be signed in to change notification settings - Fork 52
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
Wrapping #8
Comments
Thank you for your interest in this library! Yes, wrapping (Breakable equations) was originally planned and even prototyped in this repository in very early stages (but later removed). It will be added in future, probably very soon. The major blocking issue is how to design those render contracts. I currently can only think of completely rewriting custom versions of RenderBox and BoxConstraint, but that leads to very bad code quality. If you have any thoughts on this, or if you know any exisiting Flutter library that handled this correctly, please let me know. It will greatly accelerate the development of this feature. |
@znjameswu What I'm going to do about that as a workaround is just split my katex into chunks, render them separately and put it in the Wrap widget. I also split normal text into each word and put each word into it's own Text widget, so I could insert katex inline. That's the best idea I can think of. |
That is how KaTeX renders equation, but is very hard to achieve with current Flutter Math's design. For example, the height of left/right delimiters depends on the highest element within the delimiters. In Flutter Math, I decided to leave the height/width calculation to Flutter's layout pipeline rather than precalculating them from AST. So I have to wrap the entire thing in a RenderObject to share layout result, which causes problem for line breaking. Also, wrap the entire node within one RenderObject is very helpful for future editing implementations. So currently my plan is still to render them as one RenderObject and then develop contracts for line breaking. |
Using a Wrap widget is a workaround. Spit the Tex equation into multiple smaller ones and make them as children of Wrap. Probably not efficient but worked for me. Wrap(
direction: Axis.horizontal,
runSpacing: 5,
spacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text('What are the'),
Text('solutions of'),
Text('the quadratic '),
Text('equation: '),
Math.tex(
r'x^2',
textStyle: TextStyle(fontSize: 25, color: Colors.black),
),
Math.tex(
r'+6x',
textStyle: TextStyle(fontSize: 25, color: Colors.black),
),
Math.tex(
r'+8',
textStyle: TextStyle(fontSize: 25, color: Colors.black),
),
Math.tex(
r'=0',
textStyle: TextStyle(fontSize: 25, color: Colors.black),
),
Text('? '),
Text('(find both'),
Text('solutions)'),
],
) Need to split the rest of the text too. Otherwise inline wrapping will not be perfect. |
@creativecreatorormaybenot Again I may need your help😄. I'm not so sure about the correct way to do the wrapping. Also I quite doubt the idea of mocking Your team definitely has more experiences on Flutter and design patterns. This is a long plan though, it would be great if you can spare some time in the next few weeks to give it a check. |
@znjameswu It would be incredible from you, this is definitely the only thing that is missing in this library ! 😄 |
@znjameswu To be honest, wrapping is probably not what you want to support first. KaTeX supported wrapping line breaks late into their development, see KaTeX/KaTeX#1287 I think the main reason for this is that horizontal scrolling is preferrable or you do not intend your equation to exceed the horizontal constraint anyway. It makes a lot more sense with text mode and inline mode, but I would still argue that it is not what you are interested in tackling first. Instead and I think that you threw it in with automatic wrapping, I would suggest that only manual line breaks should be tackled first ( The upside of only supporting manual line breaks initially is that this is well documented and of course already fully implemented in KaTeX for example. As for your proposal - I think that it is very interesting. I fully understand your concerns for making unsound design decisions.
The whole intrinsic size concept is only a
Overall, amazing efforts from your side ✨ |
Yes, I think so too, currently large equations with many expressions are rendered in one line, without ‘//‘ it is a long line, adding support for ‘//‘ will be awesome!. |
Yeah, you are right. Respecting manual line breaks should be a higher priority. It can be done with a modification to the parser and ast. Thank you for pointing out. I just went to check TeXBook Ch.14. Well it seems TeXBook doesn't fancy the idea of line breaking inside a nested node ("only outer-level"). That arguably does make things a lot easier. Originally I am trying to reproduce the behavior of MS Word equations, which allows line breaks inside nested nodes (as long as all of its ancestors are of certain types). It seems that the design goal is different and makes the single most difference in implementation. The reason I'm stuck with RenderBox rather than making whole new RenderObject classes is that, as a result of MS Word style of line breaking, a node itself cannot know if it is allowed to line break (you can line break deep in the trees) -- it all dependes on the type of its ancestors. So the way I come up is mocking RenderBox's contract. If there is a ancestor that prohibits line breaking (e.g. subscript node), the ancestor Anyways, I think from the information it may be worth discussing which line-breaking scheme we should be after, TeX or MS Word. Personally, I prefer MS Word. I think vanilla TeX's line breaking is so conservative that I frequently ignore that feature. But as you have shown, it is better documented and understood. |
@znjameswu Makes sense! From the perspective of content creation, I think that 1. manual line breaks is most important because that is what people really want to do and 2. if there are automatic line breaks, TeX line breaking might be sufficient because it is not crucial to line break in nested nodes (people probably might not really notice the difference). So judging from that "different perspective" than what we might have, I think that an MVP for line breaking would only need to support the easiest ways. I guess it also depends on how ambitious you want to be. |
@znjameswu Great package and a very impressive effort! Just to second @creativecreatorormaybenot's comments: I would advocate only starting with explicit line breaking, with For dealing with variable screen/widget widths, perhaps something like an I haven't tried the following myself, but somewhere down the line you might be interested in looking at the package |
It turns out we can support TeX-style line-breaking quite easily. Since TeX only allows line-breaks at the outmost level, the problem I explained earlier is a non-problem. At the outmost level, no layout elements are interacting. Thus the simple solution proposed in #8 (comment) actually works: Render them in chunks and even expose those chunks to let users decide how to wrap them. (Of course, This is such a simple plan. I think I'll go for this for now. As for advanced MS-Word style line-breaking, they seem to be a strict superset of TeX line-breaking, and I can work on it later in a different issue. @creativecreatorormaybenot What do you think? |
@znjameswu Well, frankly we do this already anyway :D I think the simple |
We can introduce a new static function to
Which makes no modification to the parser nor the ast. It does the normal parsing, but unwraps the outermost row node, and put each piece into a |
@znjameswu Yeah, that is what we do at the moment :D I think it is a really crude solution, but it does work of course. |
I have implemented the easier TeX-style line breaking. It is currently on the I'll close this issue and open a new one for the remaining tasks. |
Hi, I can't access the Math.texBreak() method. I am using the null-safety version (0.3.0-nullsafety.1). Is this functionality yet to be added? My code looks something like this: final tex = Math.tex(r'2+2');
final tex2 = tex.texBreak(); // this line is erroneous saying texBreak() is not defined. |
Not in |
This seems to be working. Will this repo eventually add that feature or do I have to continue using the forked one? |
I can't mix text and maths together and wrap them. final teXt = Math.tex(
// context.select<QuizState, String>((state) => state.questionStr!),
r'\text {This string is not going to be wrapped. Is there a way? because I want to mix text and math} \frac {3} {4.4}',
).texBreak();
// ...
Wrap(children: teXt.parts), //output: everything is in a single line. overflow error.
|
I think you'll have to stay with the forked one for now. |
Is this issue solvable? Here the \text block is not breaking up. Is the logic hard to implement? I think it just needed to separate each words. |
I have no clue sadly. You may have to directly edit the source code of this library if it doesn't work for you. |
Hey @znjameswu ! Awesome library! Thanks for making such amount of work publicly available!
Currently the whole equation is rendered on a single line, are you planning (or is there already) a built-in support for wrapping?
Thanks! Have a great day!
The text was updated successfully, but these errors were encountered: