Make WordPress Core

Opened 9 months ago

Closed 2 weeks ago

#64310 closed defect (bug) (reported-upstream)

Math component Problem with matrix

Reported by: blackstar1991 Owned by:
Priority: normal Milestone:
Component: Editor Version: 6.9
Severity: normal Keywords: reporter-feedback has-patch
Cc: Focuses: ui, tests

Description

I tested new WP 6.9 and their component Math, and found that it has problem with work with matrixes in LaTeX

Multiplication of three matrices

\[
\begin{pmatrix}
1 & 0 \\
0 & 1
\end{pmatrix}
\cdot
\begin{pmatrix}
2 & 3 \\
4 & 5
\end{pmatrix}
\cdot
\begin{pmatrix}
x \\
y
\end{pmatrix}
=
\begin{pmatrix}
2x + 3y \\
4x + 5y
\end{pmatrix}
\]

shoude convert to

(10​01​)⋅(24​35​)⋅(xy​)=(2x+3y4x+5y​)

but I see problem -> Can't use function '\]' in math mode at position 69: …rix} = ad - bc \̲]̲

also the same -> Matrix with determinant

\[
\det(A) =
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
= ad - bc
\]

shoude be -> `det(A)=
​ac​bd​
​=ad−bc`

Don't work. Please fix

Attachments (1)

64310-math-doc-update.diff (651 bytes ) - added by iflairwebtechnologies 9 months ago.
Documentation update: clarify that \[ \] and $$ $$ must not be used inside Math block.

Download all attachments as: .zip

Change History (18)

#1 @ellatrix
9 months ago

  • Component GeneralEditor
  • Keywords reporter-feedback added

Can you try removing \[? The code should not be wrapped in \[\]

\begin{pmatrix}
1 & 0 \\
0 & 1
\end{pmatrix}
\cdot
\begin{pmatrix}
2 & 3 \\
4 & 5
\end{pmatrix}
\cdot
\begin{pmatrix}
x \\
y
\end{pmatrix}
=
\begin{pmatrix}
2x + 3y \\
4x + 5y
\end{pmatrix}
Last edited 9 months ago by ellatrix (previous) (diff)

#2 @blackstar1991
9 months ago

Yes, it works, but if this formula is imported from other sources, it will be a problem.
Maybe you shoude add description that symbols need to be corrected to \begin{equation} and \end{equation}

Last edited 9 months ago by blackstar1991 (previous) (diff)

#3 @ellatrix
9 months ago

You already had \begin{pmatrix} etc., you just needed to remove the other brackets. Could you elaborate on the importing? How are you importing this math text?

#4 @wildworks
9 months ago

  • Milestone Awaiting Review6.9

Just to be safe, change the milestone to 6.9.

@iflairwebtechnologies
9 months ago

Documentation update: clarify that \[ \] and $$ $$ must not be used inside Math block.

#5 @iflairwebtechnologies
9 months ago

  • Keywords has-patch added

The attached patch updates inline comments describing math calculations in the targeted area of core. The existing comments were either misleading or incomplete. This patch standardizes terminology, clarifies formula behavior, and aligns the documentation with the actual implementation logic.
This improves maintainability and developer clarity. No code behavior or output is modified.

#6 @ellatrix
9 months ago

@blackstar1991 could you let me know how you were entering the LaTeX? I think we can make some improvements in the editor by stripping those common delimiter used for full LaTeX documents on paste.

But I think it would be better suited for a point release.

#7 @blackstar1991
9 months ago

I used plugins for it: https://wordpress.org/plugins/search/LaTeX/
I tested this component just out of curiosity, because when I was a student I often used LaTeX to communicate with teachers on forums.

*If you need real testing of this component, you can simply ask an AI model to generate 50–100 physics or mathematics formulas and then convert them to LaTeX and check results in WP.

#8 @ellatrix
9 months ago

  • Milestone 6.97.0

Well, thank you for testing! I also frequently use this, so I totally get your problem. What we accept is LaTeX math mode, so just the code used to input math, but not all layout/document level LaTeX. Those brackets are used to delimit the math mode from the other syntax, even outside of LaTeX (like Markdown or HTML documents), to parse/detect the LaTeX math mode code. In the visual editor however, we don't need those delimiters. Even in popular libraries like KaTeX https://katex.org, this would error, and as a result also in editors such as Notion.

Let's address this in the next release, 7.0, to be a bit more forgiving. I don't think it's a critical issue. Happy to consider it in point release if we get more reports.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


5 months ago

#10 @audrasjb
5 months ago

As per today's 7.0 bug scrub:

There is a patch, but it's only a markdown file to update the documentation, it doesn't fix the outlined issue.
Are we good only updating the docs or do we want to fix the issue? If so and given we're on beta cycle, I'd suggest to move this ticket to Future Release.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


5 months ago

#12 @audrasjb
5 months ago

  • Milestone 7.07.1

As per today's 7.0 pre-RC1 bug scrub:
Moving to Future Release, see previous comment.

#13 follow-up: @wildworks
3 weeks ago

  • Milestone 7.1Future Release

If updating the documentation is sufficient to address this ticket, we can simply add a note to the following file. This is the README for the individual block, which will be published as part of the Block Editor Handbook.

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/math/README.md
https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-math/

@blackstar1991, Can you submit a PR to update this README in the Gutenberg repository? In any case, I don't think this ticket addresses a critical issue, so I will change the milestone.

#14 in reply to: ↑ 13 @blackstar1991
3 weeks ago

Replying to wildworks:

If updating the documentation is sufficient to address this ticket, we can simply add a note to the following file. This is the README for the individual block, which will be published as part of the Block Editor Handbook.

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/math/README.md
https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-math/

@blackstar1991, Can you submit a PR to update this README in the Gutenberg repository? In any case, I don't think this ticket addresses a critical issue, so I will change the milestone.

I continued testing more complex mathematical formulas for matrices, and I can say that they don't look good.

Examles -

  1. Multiplication of Two 3×3 Matrices
    \begin{aligned}
    A &=
    \begin{pmatrix}
    1 & 2 & -1 \\
    0 & 3 & 4 \\
    2 & -2 & 1
    \end{pmatrix},
    &
    B &=
    \begin{pmatrix}
    2 & 0 & 1 \\
    -1 & 3 & 2 \\
    4 & -2 & 0
    \end{pmatrix},
    \\[8pt]
    AB &=
    \begin{pmatrix}
    1\cdot2+2\cdot(-1)+(-1)\cdot4 &
    1\cdot0+2\cdot3+(-1)\cdot(-2) &
    1\cdot1+2\cdot2+(-1)\cdot0
    \\
    0\cdot2+3\cdot(-1)+4\cdot4 &
    0\cdot0+3\cdot3+4\cdot(-2) &
    0\cdot1+3\cdot2+4\cdot0
    \\
    2\cdot2+(-2)\cdot(-1)+1\cdot4 &
    2\cdot0+(-2)\cdot3+1\cdot(-2) &
    2\cdot1+(-2)\cdot2+1\cdot0
    \end{pmatrix}
    \\[8pt]
    &=
    \begin{pmatrix}
    -4 & 8 & 5 \\
    13 & 1 & 6 \\
    10 & -8 & -2
    \end{pmatrix}.
    \end{aligned}
    
    

https://i.ibb.co/rfGGRQKK/Edit-Page-Sample-Page-elementor-test-Word-Pre.png

  1. Finding the inverse matrix using algebraic complements
    \begin{aligned}
    A &=
    \begin{pmatrix}
    2 & 1 & 0 \\
    -1 & 3 & 2 \\
    4 & 0 & 1
    \end{pmatrix},
    \\[6pt]
    \det(A)
    &=
    \begin{vmatrix}
    2 & 1 & 0 \\
    -1 & 3 & 2 \\
    4 & 0 & 1
    \end{vmatrix}
    \\
    &=
    2
    \begin{vmatrix}
    3 & 2 \\
    0 & 1
    \end{vmatrix}
    -
    1
    \begin{vmatrix}
    -1 & 2 \\
    4 & 1
    \end{vmatrix}
    \\
    &=
    2(3\cdot1-2\cdot0)
    -
    \left((-1)\cdot1-2\cdot4\right)
    \\
    &=6-(-9)=15.
    \\[8pt]
    \operatorname{adj}(A)
    &=
    \begin{pmatrix}
    3 & -1 & 2 \\
    9 & 2 & -4 \\
    -12 & 4 & 7
    \end{pmatrix},
    \\[8pt]
    A^{-1}
    &=
    \frac{1}{\det(A)}\operatorname{adj}(A)
    \\
    &=
    \frac{1}{15}
    \begin{pmatrix}
    3 & -1 & 2 \\
    9 & 2 & -4 \\
    -12 & 4 & 7
    \end{pmatrix}.
    \end{aligned}
    
    

https://i.ibb.co/b51JTmSh/Edit-Page-Sample-Page-elementor-test-Word-Pre.png

  1. Singular Value Decomposition (SVD) of a Matrix
\begin{aligned}
A &=
\begin{pmatrix}
3 & 0 \\
4 & 0
\end{pmatrix},
&
A^{\mathsf T}A
&=
\begin{pmatrix}
3 & 4 \\
0 & 0
\end{pmatrix}
\begin{pmatrix}
3 & 0 \\
4 & 0
\end{pmatrix}
=
\begin{pmatrix}
25 & 0 \\
0 & 0
\end{pmatrix}.
\\[10pt]
\det(A^{\mathsf T}A-\lambda I)
&=
\begin{vmatrix}
25-\lambda & 0 \\
0 & -\lambda
\end{vmatrix}
\\
&=\lambda(\lambda-25)=0.
\\[8pt]
\lambda_1&=25,
&
\lambda_2&=0,
\\
\sigma_1&=\sqrt{\lambda_1}=5,
&
\sigma_2&=\sqrt{\lambda_2}=0.
\\[10pt]
\mathbf v_1&=
\begin{pmatrix}
1\\0
\end{pmatrix},
&
\mathbf v_2&=
\begin{pmatrix}
0\\1
\end{pmatrix},
&
V&=
\begin{pmatrix}
1&0\\
0&1
\end{pmatrix}.
\\[10pt]
\mathbf u_1
&=
\frac{A\mathbf v_1}{\sigma_1}
=
\frac{1}{5}
\begin{pmatrix}
3\\4
\end{pmatrix}
=
\begin{pmatrix}
\frac{3}{5}\\[2pt]
\frac{4}{5}
\end{pmatrix},
&
\mathbf u_2
&=
\begin{pmatrix}
-\frac{4}{5}\\[2pt]
\frac{3}{5}
\end{pmatrix}.
\\[12pt]
U&=
\begin{pmatrix}
\frac{3}{5} & -\frac{4}{5} \\
\frac{4}{5} & \frac{3}{5}
\end{pmatrix},
&
\Sigma&=
\begin{pmatrix}
5&0\\
0&0
\end{pmatrix}.
\\[12pt]
A
&=
U\Sigma V^{\mathsf T}
\\
&=
\begin{pmatrix}
\frac{3}{5} & -\frac{4}{5} \\
\frac{4}{5} & \frac{3}{5}
\end{pmatrix}
\begin{pmatrix}
5&0\\
0&0
\end{pmatrix}
\begin{pmatrix}
1&0\\
0&1
\end{pmatrix}
=
\begin{pmatrix}
3&0\\
4&0
\end{pmatrix}.
\end{aligned}

https://i.ibb.co/HTgn3xG2/Edit-Page-Sample-Page-elementor-test-Word-Pre.png

#15 @wildworks
2 weeks ago

@blackstar1991, Could you post the issues you are aware of and their solutions to the Gutenberg repo? That way, we can close this ticket as reported-upstream.

#16 @blackstar1991
2 weeks ago

Here are the problems I encountered while testing this Math block.
https://github.com/WordPress/gutenberg/issues/80732

#17 @wildworks
2 weeks ago

  • Milestone Future Release
  • Resolutionreported-upstream
  • Status newclosed
Note: See TracTickets for help on using tickets.