verybadcat / CSharpMath

LaTeX. in C#. (ported from the wonderful iosMath project).
MIT License
380 stars 61 forks source link

Line break with Russian Language #192

Open Aqoolare opened 3 years ago

Aqoolare commented 3 years ago

Describe the bug

Line break does not work when using the Russian language.

To Reproduce

Steps to reproduce the behavior:

  1. Add a string "Число d > 0 называется наибольшим общим делителем (НОД) двух целых чисел a и b, если оно удовлетворяет следующим условиям: 1) d | a и d | b; 2) если c | a и c | b, то c | d." to the LaTeX field of the TextView.

Expected behavior

Words are wrapped to a new line at the end of a word

Environment (please complete the following information):

1

Additional context

I really need to solve this problem :(

Aqoolare commented 3 years ago

Thank you very much for your prompt answer, but I am having problems using the given solution. But I have some problems with its application, I attach screenshots with errors. And also I have a question, where should this code be placed in the project? 3 1 2

Happypig375 commented 3 years ago

@Aqoolare The change is not published yet, I'll publish a 0.5.1 and you can use that code.

Also to use C# 9 which I've used, you must add <LangVersion>latest</LangVersion> to the <PropertyGroup> inside your .csproj.

Aqoolare commented 3 years ago

Ok, thanks a lot for the help. And I have one more question, is there any way to add horizontal scrolling to a textview if its content doesn't fit on the page? 4 in this case the content is enclosed in $$ .. $$

Happypig375 commented 3 years ago

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scrollview

Aqoolare commented 3 years ago

Yes, it really works, thanks 5 but my other textviews, which were aligned to the width of the screen, also stretched, so I need to add a separate textview, for the $$ .. $$ cases? 6 7

Happypig375 commented 3 years ago

You can also add your own line breaks with \\ or reduce the font size.

Aqoolare commented 3 years ago

Ok, thank you very much for such prompt support.

charlesroddie commented 3 years ago

but my other textviews, which were aligned to the width of the screen, also stretched, so I need to add a separate textview, for the $$ .. $$ cases?

That's one option. You can also measure the minimum width to control the layout. E.g.:

Aqoolare commented 3 years ago

Thanks for the advice, but I'm new to Xamarin app development, could you give me a small example if it's not difficult for you?

Aqoolare commented 3 years ago

How can i refer in xaml code to parameters of another object? I don't understand, how to scale FontSize based on the width

Aqoolare commented 3 years ago

1 2 3 I have FontSize=43, HeightRequest is fixed for each TextView, and i have different results on different devices

Happypig375 commented 3 years ago

I think it's related to screen density differences? You could try dividing or multiplying with https://docs.microsoft.com/en-us/xamarin/essentials/device-display?tabs=android#main-display-info.

Aqoolare commented 3 years ago

Also, I installed new version, but the contents are gone image

Aqoolare commented 3 years ago

I think it's related to screen density differences? You could try dividing or multiplying with https://docs.microsoft.com/en-us/xamarin/essentials/device-display?tabs=android#main-display-info.

Ok, thank you, i'll try it

Happypig375 commented 3 years ago

@Aqoolare Try InvalidateSurface() on the TextView?

Aqoolare commented 3 years ago

I think it's related to screen density differences? You could try dividing or multiplying with https://docs.microsoft.com/en-us/xamarin/essentials/device-display?tabs=android#main-display-info. image

Can you give some advice about formula? I tried this but it didn’t work in full, the text in places crawls out of the screen horizontally and vertically, in the case of vertical maybe I should increase the height of the textview too, but I can’t think of a suitable formula

Aqoolare commented 3 years ago

@Aqoolare Try InvalidateSurface() on the TextView?

I use this in data binding and don't know how to call this method It looks like this image

Aqoolare commented 3 years ago

I'm sorry for asking so many stupid questions, but I really need to figure this out.

Happypig375 commented 3 years ago

Use https://docs.microsoft.com/en-us/dotnet/desktop/xaml-services/xname-directive to get the view.

Aqoolare commented 3 years ago

Guys, I found how to solve the display problem! I used the wrapper this way public class MyTextView : TextView { public MyTextView() { InvalidateSurface(); } } And used it on xaml this way <views:MyTextView x:Name="textView" LaTeX="{Binding Formula}" Margin="15, 5" FontSize="43"/> But issue with the words wrapping remains

image

Maybe I don't understand where to put this code CSharpMath.Rendering.Text.TextLaTeXParser.AdditionalBreakingEngines.Add(new RussianBreakingEngine());

charlesroddie commented 3 years ago

This thread is getting overloaded with different issues so I've hidden everything not related to line breaks. Please post other issues if you have unresolved questions not relating to line breaks @Aqoolare . Thanks.

Currently CSharpMath uses Typography.TextBreak, so one option is to wait for Typography.TextBreak to resolve the issue that @Happypig375 posted.

I'm not convinced that text breaking is difficult enough to require a separate engine. Can't we break on spaces and hyphens only? LaTeX doesn't usually support automatic hyphenation and I assume we have no plan to support that, so breaking should be easy shouldn't it?

Overleaf breaks on spaces and commas but not punctuation:

image image

Aqoolare commented 3 years ago

This thread is getting overloaded with different issues so I've hidden everything not related to line breaks. Please post other issues if you have unresolved questions not relating to line breaks @Aqoolare . Thanks.

Currently CSharpMath uses Typography.TextBreak, so one option is to wait for Typography.TextBreak to resolve the issue that @Happypig375 posted.

I'm not convinced that text breaking is difficult enough to require a separate engine. Can't we break on spaces only? LaTeX doesn't usually support hyphenation and I assume we have no plan to support that, so breaking should be easy shouldn't it?

My other problems have been resolved, thanks, the only thing I would like to clarify, that is, at the moment the transfer by Russian words does not work?

Even with this code 'CSharpMath.Rendering.Text.TextLaTeXParser.AdditionalBreakingEngines.Add(new RussianBreakingEngine());'?