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

LaTeX formula cannot wrap #4102

Open
Silfra-glacier opened this issue Dec 15, 2024 · 2 comments
Open

LaTeX formula cannot wrap #4102

Silfra-glacier opened this issue Dec 15, 2024 · 2 comments

Comments

@Silfra-glacier
Copy link

Description

When dealing with LaTeX mathematical formulas, it seems impossible to wrap the multi line formulas included in $$.

Problem reproduction:

from nicegui import ui

ui.markdown("""$$
z_1=\overrightarrow{\mathrm{w}}_1 \cdot \overrightarrow{\mathrm{x}}+b_1 \\
z_1=\overrightarrow{\mathrm{w}}_1 \cdot \overrightarrow{\mathrm{x}}+b_1 \\
z_1=\overrightarrow{\mathrm{w}}_1 \cdot \overrightarrow{\mathrm{x}}+b_1 \\
z_1=\overrightarrow{\mathrm{w}}_1 \cdot \overrightarrow{\mathrm{x}}+b_1
$$""", extras=['latex'])

ui.run()

The browser page displays:

image

Preview in the MD file editor as follows:

image

Can this problem be solved? Thanks.

@falkoschindler
Copy link
Contributor

Hi @Silfra-glacier,

I checked your LaTeX code with an online editor and got a very similar result like with NiceGUI. What caught my eye though is the following note:

UPDATE 2023.03.18: I recently updated this site's MathJax renderer version and some users have reported their line ending '\\' characters don't work as they did before. It turns out this was an intentional change by the MathJax developers to honor correct LaTeX syntax rules.

To get the same line break behavior as in the prior version, use this form:

\begin{array}{llll}
aa \\
bb \\
cc \\
dd \\
\end{array} 

Other approaches will work, example "\displaylines{x = a + b \\ y = b + c}" but the point is that a bare line break isn't correct LaTeX syntax and shouldn't have been accepted as it was in the prior version.

So I assume your input isn't valid LaTeX. If in doubt, you should check the latex2mathml package, which NiceGUI uses behind the scenes.

@Silfra-glacier
Copy link
Author

Thank you for your answer. I tried using:

\begin{array}{llll}
aa \\
bb \\
cc \\
dd \\
\end{array} 

It can be rendered normally in the browser, but when using:

from nicegui import ui

ui.markdown(r'''
$$
\begin{array}{llll}
Proj_{V_{1}}b&=\frac{(b,a_1)}{(a_1,a_1)}a_1\\
&=(a_1^Hb)(a_1^Ha_1)^{-1}a_1\\
&=a_1(a_1^Ha_1)^{-1}a_1^Hb\\
&\triangleq E_{1}b
\end{array}
$$
''', extras=['latex'])

ui.run()

It seems that the position of the equal sign cannot be aligned, but the overall equation is displayed in the center on the right, but this can be rendered normally in the [LaTeX Editor](https://arachnoid.com/latex/):

image

Browser display:

image

Perhaps it's still a problem with LaTeX syntax, I will conduct a duplicate check. thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants