Enter-tainer / typst-preview

[DEPRECATED] Use tinymist instead
https://Enter-tainer.github.io/typst-preview/
MIT License
450 stars 21 forks source link

Right-to-left text files are not displayed correctly when sentences is composed of rtl and ltr text #304

Closed giladfarber closed 3 months ago

giladfarber commented 3 months ago

When using #set text(dir: rtl), the output file of the compiled text is messy, which means characters in math expressions and English sentences are switched up, mostly where spaces are present, when a line contains both rtl and ltr text.

To Reproduce

  1. use at the start of the file:

    set text(dir: rtl)

  2. write a line using both rtl and ltr characters (for example: נראה ש-$lim_(n->oo) sqrt(n)-sqrt(n-1)=0$)

Expected behavior the real time preview displays the text as intended. only the output file is messy

Package/Software version: none

VSCode version(Help -> About):

Version: 1.90.1
Commit: 611f9bfce64f25108829dd295f54a6894e87339d
Date: 2024-06-11T21:44:54.914Z (3 wks ago)
Electron: 29.4.0
ElectronBuildId: 9593362
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 23.5.0

typst-preview extension version: v0.11.7

Enter-tainer commented 3 months ago

Can you try reproduce this in typst-cli or typst webapp? I suspect it's not within typst-preview scope.

giladfarber commented 3 months ago

I'm currently copying and pasting my files to the Typst website to export them, which it does without any issues

Enter-tainer commented 3 months ago

Can you post full code here so I can copy paste them?

giladfarber commented 3 months ago

sure, I'll also attach two photos, one is a file that I exported from Typst and the other is a file that the Typst Preview compiled. this is from the Typst preview:

Screenshot 2024-07-03 at 9 05 49

this is from the Typst website:

Screenshot 2024-07-03 at 9 07 24
giladfarber commented 3 months ago

this is the code:

ומחדו״א 1 אנו יודעים שזהו טור מתכנס, לכן האינטגרל מתכנס. נראה לפי היינה שהגבול אינו אפס: ניקח את הסדרה $a_n=n$ ואת הסדרה $b_n = n+1/2^(n+1)$, ונקבל $lim_(n->oo) f(a_n)=0!=1/2=lim_(n->oo) f(b_n)$, ולכן הגבול אינו קיים ובפרט אינו אפס כנדרש. \ *(ב)* ייתכן. לדוגמה, הפונקציה $g(x) = cases(0 space :x in.not ZZ, x space:x in ZZ)$ אינטגרבילית כיוון שבכל תת קטע סופי של האינטגרל נקבל שהאינטגרל שווה ל-0, כיוון שהוא מזדהה עם $integral 0$ למעט מספר נקודות סופי, אך הסדרה לא חסומה מלמעלה. \ *(ג)* החל ממקום מסוים $N$ מתקיים: $0<=L-epsilon<=f(x)<=L+epsilon$, ואינטגרל שומר על אי שוויון חלש, לכן מתקבל $integral_N^oo (L-epsilon) dx<=integral_N^oo f(x)dx => oo<=integral_N^oo f(x)dx => integral_N^oo f(x)dx = oo$. אין פה סתירה לסעיפים הקודמים, כיוון שבהם בכל קרן אינסופית ניתן היה למצוא ערך קרוב עד כדי $epsilon$ ל-$0$, וכאן לכל $0<epsilon<L$ קיים $N$ שהחל ממנו כל ערך רחוק לפחות ב-$epsilon$ מ-$0$. == שאלה 3: $ integral_(-oo)^oo f^2(x)dx => [space.hair^(u=f^2(x))_(u'=2f(x)f'(x)) space^(v'=1)_(v=x)] = underbrace([x f^2(x)]_(-oo)^oo, =(plus.minus sqrt(|x|) f(x))^2=0) - integral_(-oo)^oo 2x f(x)f'(x)dx = 1 => $ $ => integral_(-oo)^oo x f(x)f'(x)dx = -1/2 $

giladfarber commented 3 months ago

and thank you :)

Enter-tainer commented 3 months ago
image

Would you mind reduce previous code to a minimal example?

giladfarber commented 3 months ago

here's the code without any modifications that I added: ומחדו״א 1 אנו יודעים שזהו טור מתכנס, לכן האינטגרל מתכנס. נראה לפי היינה שהגבול אינו אפס: ניקח את הסדרה $a_n=n$ ואת הסדרה $b_n = n+1/2^(n+1)$, ונקבל $lim_(n->oo) f(a_n)=0!=1/2=lim_(n->oo) f(b_n)$, ולכן הגבול אינו קיים ובפרט אינו אפס כנדרש. \ *(ב)* ייתכן. לדוגמה, הפונקציה $g(x) = cases(0 space :x in.not ZZ, x space:x in ZZ)$ אינטגרבילית כיוון שבכל תת קטע סופי של האינטגרל נקבל שהאינטגרל שווה ל-0, כיוון שהוא מזדהה עם $integral 0$ למעט מספר נקודות סופי, אך הסדרה לא חסומה מלמעלה. \ *(ג)* החל ממקום מסוים $N$ מתקיים: $0<=L-epsilon<=f(x)<=L+epsilon$, ואינטגרל שומר על אי שוויון חלש, לכן מתקבל $integral_N^oo (L-epsilon) dif x<=integral_N^oo f(x)dif x => oo<=integral_N^oo f(x)dif x => integral_N^oo f(x)dif x = oo$. אין פה סתירה לסעיפים הקודמים, כיוון שבהם בכל קרן אינסופית ניתן היה למצוא ערך קרוב עד כדי $epsilon$ ל-$0$, וכאן לכל $0<epsilon<L$ קיים $N$ שהחל ממנו כל ערך רחוק לפחות ב-$epsilon$ מ-$0$.

Enter-tainer commented 3 months ago

reproduced. which is... weird.. I will take closer look when i leave work.

cc @Myriad-Dreamin

image
giladfarber commented 3 months ago

ok, thank you

Myriad-Dreamin commented 3 months ago

The preview's renderer is developed based on typst_render but I haven't seen any process to rtl text from my quick glance. We may debug the concrete code then.

Enter-tainer commented 3 months ago

image

For some reason I cannot reproduce this on my windows machine.

Enter-tainer commented 3 months ago

previous reproduction is done on my m2 macbook

Enter-tainer commented 3 months ago

possibly related:

Myriad-Dreamin commented 3 months ago

possibly related:

Does it mean that we might get it by having different default lang/region on different machines?

giladfarber commented 3 months ago

that got it fixed. thanks a lot