Skip to content
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

"TypeError: Cannot read properties of undefined (reading 'length')" in math blocks while using rtl plugins #40

Open
YonatanRubin opened this issue Jan 8, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@YonatanRubin
Copy link

I am not sure if this plugin is the cause for the problem or the rtl plugin, but since this plugin shows the error I assume this one. while using either dynamic rtl or obsidian-rtl with the math block options on.
writing math blocks seem to most of the time show the error "TypeError: Cannot read properties of undefined (reading 'length')" on some blocks, but only when in read mode. this issue persisted both on android and linux.

in edit mode:
Screenshot_20240108_081610_Obsidian

in read mode:
Screenshot_20240108_081556_Obsidian

after disabling the rtl plugin:
Screenshot_20240108_082054_Obsidian

@d-kaue
Copy link
Contributor

d-kaue commented Jan 8, 2024

I can't reproduce this with the ObsidianRTL plugin. Are you sure you're getting an error with that one?

The DynamicRTL plugin seems to be deprecated.

@YonatanRubin
Copy link
Author

yes. I recreated it now in a new vault having only obsidian-rtl and typst-renderer. I used the following file to check if the direction matters, and got it even when the page was set to ltr (which is weird because it is the first time it behaved like this that I have seen)

test for only ltr in my code.
a few lines
inline $f_x (t) = integral_0^oo e^(k/2) d t$
block :
$$f_x (t) = integral_0^oo e^(k/2) d t$$
multiline block:
$$f_x (t) = integral_0^oo e^(k/2) d t\ 
F'_x (t)=f_x (t)
$$

@fenjalien fenjalien added the bug Something isn't working label Jan 9, 2024
@d-kaue
Copy link
Contributor

d-kaue commented Jan 9, 2024

with your example I was able to reproduce it.

e.g. this is OK.

Lorem $Alpha$ ipsum.

Lorem $Beta$ ipsum.

but this will get an error.

Lorem $Alpha$ ipsum.
Lorem $Beta$ ipsum.

Obsidian recognises it as a single <p> element and insert a <br> line break. In this case obsidian-rtl creates a <div>.

with obsidian-rtl enabled
with obsidian-rtl

with obsidian-rtl disabled
without obsidian-rtl

obsidian-rtl separates each element inside the <p> element that contains a <br> line break and creates a <div> in each element.
the typst compiler is probably losing the reference of the element it is rendering.

To be honest, I don't know anything about Right-to-Left. The content inside each inline maths have to change position?

@fenjalien
Copy link
Owner

I can reproduce this as well, it looks like at some point the custom HTML element that renders the Typst source code gets reset or recreated. The error is from the source string being undefined but still being read as a string. This shouldn't happen as it gets given the source code so I'm not entirely sure whats happening.

@YonatanRubin
Copy link
Author

what do you mean by change position? if you mean change position in relation to the normal text then probably (since a line with n chars before the math block should position it either n pixels to the correct alignment). if you mean compared to itself then no, the math should be in the same direction orientation and position.

@d-kaue
Copy link
Contributor

d-kaue commented Jan 24, 2024

I can reproduce this as well, it looks like at some point the custom HTML element that renders the Typst source code gets reset or recreated. The error is from the source string being undefined but still being read as a string. This shouldn't happen as it gets given the source code so I'm not entirely sure whats happening.

I've been debugging for a while, and it seems to be a problem with the CustomElements lifecycle.
obsidian-rtl modifies before draw, but after obsidian-typst creating the element.

In the TypstRenderElement class the draw method only has an idea of the fontSize and this.size because it is defined inside it, everything else that is passed in the .compile is undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants