[GH-ISSUE #7949] [Bug] Latex rendering error #3474

Closed
opened 2026-03-23 21:30:33 +00:00 by mirror · 6 comments
Owner

Originally created by @stepisptr-t on GitHub (May 19, 2025).
Original GitHub issue: https://github.com/AppFlowy-IO/AppFlowy/issues/7949

Bug Description

After importing from Notion, one latex block fails to render. This is the output: Build Exception: Unsanitized build exception detected: Unsupported operation: Temporary node CrNode encountered..Please report this error with correponding input.

How to Reproduce

Putting this in a latex block

f:D_f\rarr\mathbb{R},\\
g:D_g\rarr\mathbb{R},\\ a \in \overline{\R}, \textnormal{a je hromadným bodem množiny } D_f\cap D_g
\\ \exists V_a \textnormal{ tak, že } V_a\cap D_f = V_a\cap D_g \\ 
f(x)=\mathcal{O}(g(x)) \textnormal{ pro } x\rarr a \Leftrightarrow (\exists c \gt 0, c\in \mathbb{R}) (\exists U_a)\\ (\forall x \in (U_a\cap D_f \cap D_g) \setminus \{a\}) \Rightarrow |f(x)|\le c \cdot |g(x)|)

Expected Behavior

render the latex

Operating System

Windows

AppFlowy Version(s)

0.9.2

Screenshots

No response

Additional Context

No response

Originally created by @stepisptr-t on GitHub (May 19, 2025). Original GitHub issue: https://github.com/AppFlowy-IO/AppFlowy/issues/7949 ### Bug Description After importing from Notion, one latex block fails to render. This is the output: `Build Exception: Unsanitized build exception detected: Unsupported operation: Temporary node CrNode encountered..Please report this error with correponding input.` ### How to Reproduce Putting this in a latex block ```latex f:D_f\rarr\mathbb{R},\\ g:D_g\rarr\mathbb{R},\\ a \in \overline{\R}, \textnormal{a je hromadným bodem množiny } D_f\cap D_g \\ \exists V_a \textnormal{ tak, že } V_a\cap D_f = V_a\cap D_g \\ f(x)=\mathcal{O}(g(x)) \textnormal{ pro } x\rarr a \Leftrightarrow (\exists c \gt 0, c\in \mathbb{R}) (\exists U_a)\\ (\forall x \in (U_a\cap D_f \cap D_g) \setminus \{a\}) \Rightarrow |f(x)|\le c \cdot |g(x)|) ``` ### Expected Behavior render the latex ### Operating System Windows ### AppFlowy Version(s) 0.9.2 ### Screenshots _No response_ ### Additional Context _No response_
mirror 2026-03-23 21:30:33 +00:00
Author
Owner

@M-T-Arden commented on GitHub (May 20, 2025):

Hi @stepisptr-t ,

I've successfully reproduced this bug and identified the root cause. Here's a temporary solution for users like you (Part 3).

Summary of the root cause and suggested fix:

1. Problem

  • Bug behavior: When inputting LaTeX equations that contain a raw \\, the following build exception is thrown:

  • Build Exception: Unsanitized build exception detected:
    Unsupported operation: Temporary node CrNode encountered.
    
  • Root cause:

    The LaTeX parser used by AppFlowy (suspected to be flutter_math) does not properly handle raw \\ line breaks outside of environments like aligned. This causes the parser to generate a temporary CrNode, which leads to the crash. However, the same line break works fine inside those environments.


2. Reproduction

  • Minimal reproducible example:
% Triggers build exception
\\

% Works correctly
\begin{aligned}
\\
\end{aligned}
  • key findings
    • Replacing with \\\\, \newline, or \cr does not resolve the issue.
    • Wrapping the content in environments like aligned does prevent the exception.

💡3. Proposed Fixes

  1. For users:
    Wrap the LaTeX content with \begin{aligned} and \end{aligned} as shown below:

    \begin{aligned}
    f:D_f\rarr\mathbb{R},\\
    g:D_g\rarr\mathbb{R},\\
    ...
    \end{aligned}
    
  2. As a contributor :

    • Implement a pre-processing step to automatically wrap raw content with aligned if it contains a standalone \\:

        String _safeLatex(String raw) {
          if (raw.contains(r'\\') && !raw.contains(r'\begin{')) {
            return r'\begin{aligned}' + raw + r'\end{aligned}';
          }
          return raw;
        }
      
    • Alternatively, check whether this issue is caused by an outdated version of flutter_math and consider upgrading the dependency.

I would like to work on fixing this issue and I will start working on a PR shortly. Please let me know if there's any preferred direction (e.g., pre-processing vs parser-level fix).

<!-- gh-comment-id:2894845528 --> @M-T-Arden commented on GitHub (May 20, 2025): Hi @stepisptr-t , I've successfully reproduced this bug and identified the root cause. Here's a temporary solution for users like you (Part 3). ### Summary of the root cause and suggested fix: #### 1. Problem - **Bug behavior**: When inputting LaTeX equations that contain a raw `\\`, the following build exception is thrown: - ``` Build Exception: Unsanitized build exception detected: Unsupported operation: Temporary node CrNode encountered. ``` - **Root cause**: The LaTeX parser used by AppFlowy (suspected to be `flutter_math`) does **not properly handle raw `\\` line breaks** outside of environments like `aligned`. This causes the parser to generate a temporary `CrNode`, which leads to the crash. However, the same line break works fine inside those environments. --- #### 2. Reproduction - **Minimal reproducible example**: ```latex % Triggers build exception \\ % Works correctly \begin{aligned} \\ \end{aligned} ``` - **key findings**: - Replacing with `\\\\`, `\newline`, or `\cr` does **not** resolve the issue. - Wrapping the content in environments like `aligned` **does** prevent the exception. ------ #### 💡3. Proposed Fixes 1. **For users**: Wrap the LaTeX content with `\begin{aligned}` and `\end{aligned}` as shown below: ``` \begin{aligned} f:D_f\rarr\mathbb{R},\\ g:D_g\rarr\mathbb{R},\\ ... \end{aligned} ``` 2. **As a contributor** : - Implement a pre-processing step to automatically wrap raw content with `aligned` if it contains a standalone `\\`: ``` String _safeLatex(String raw) { if (raw.contains(r'\\') && !raw.contains(r'\begin{')) { return r'\begin{aligned}' + raw + r'\end{aligned}'; } return raw; } ``` - Alternatively, check whether this issue is caused by an outdated version of `flutter_math` and consider upgrading the dependency. I would like to work on fixing this issue and I will start working on a PR shortly. Please let me know if there's any preferred direction (e.g., pre-processing vs parser-level fix).
Author
Owner

@stepisptr-t commented on GitHub (May 20, 2025):

Is this LLM generated?

<!-- gh-comment-id:2895326726 --> @stepisptr-t commented on GitHub (May 20, 2025): Is this LLM generated?
Author
Owner

@M-T-Arden commented on GitHub (May 20, 2025):

Not actually, I have done this work by myself. I only use AI to summary and polish this content because my mother language is not English and I am new to open source project. I thought AI could make it more clear and accurate.

<!-- gh-comment-id:2895362974 --> @M-T-Arden commented on GitHub (May 20, 2025): Not actually, I have done this work by myself. I only use AI to summary and polish this content because my mother language is not English and I am new to open source project. I thought AI could make it more clear and accurate.
Author
Owner

@LucasXu0 commented on GitHub (May 21, 2025):

Image

I can confirm that wrapping with \begin{aligned} and \end{aligned} works. I'll make a quick fix later.

I would like to work on fixing this issue and I will start working on a PR shortly. Please let me know if there's any preferred direction (e.g., pre-processing vs parser-level fix).

@M-T-Arden I prefer the preprocessing without modifying the math library.

<!-- gh-comment-id:2896256291 --> @LucasXu0 commented on GitHub (May 21, 2025): <img width="785" alt="Image" src="https://github.com/user-attachments/assets/b286d4f5-351c-4d85-9df7-cd2cc5118a9b" /> I can confirm that wrapping with `\begin{aligned}` and `\end{aligned}` works. ~~I'll make a quick fix later.~~ > I would like to work on fixing this issue and I will start working on a PR shortly. Please let me know if there's any preferred direction (e.g., pre-processing vs parser-level fix). @M-T-Arden I prefer the preprocessing without modifying the math library.
Author
Owner

@stepisptr-t commented on GitHub (May 21, 2025):

It might be better to show an error message, which indicates that the Tex should contain the alignment. The user (me) should've known that while being in the equation environment, one should use the aligned environment together with "\". Default behavior (using xelatex to compile) shows overflowing text and ignores the "\" which is what I would expect the Web Tex rendering engine to do as well.

Image

Using the aligned environment from package amsmath results in the same result as you provided, which is expected:

Image

<!-- gh-comment-id:2897247124 --> @stepisptr-t commented on GitHub (May 21, 2025): It might be better to show an error message, which indicates that the Tex should contain the alignment. The user (me) should've known that while being in the equation environment, one should use the aligned environment together with "\\". Default behavior (using xelatex to compile) shows overflowing text and ignores the "\\" which is what I would expect the Web Tex rendering engine to do as well. ![Image](https://github.com/user-attachments/assets/0da5b5a8-6e82-4f30-be26-1b255cc72fb3) Using the aligned environment from package `amsmath` results in the same result as you provided, which is expected: ![Image](https://github.com/user-attachments/assets/c5dcdaa5-a7c7-4ddb-b2e4-b894672edacb)
Author
Owner

@M-T-Arden commented on GitHub (May 21, 2025):

@LucasXu0 Got it. I've implemented a pre-processing logic inside _buildMathEquation (in math_equation_block_component.dart) without modifying the math rendering library, as suggested.
I've submitted a PR as this fix: #7961
Also, as users pointed out, wrapping the LaTeX in an aligned environment avoids the crash, but causes the equation to lose center alignment. If possible, I’d like to continue working on improving that rendering behavior as a follow-up. I wonder whether this is okay.

<!-- gh-comment-id:2898741781 --> @M-T-Arden commented on GitHub (May 21, 2025): @LucasXu0 Got it. I've implemented a pre-processing logic inside `_buildMathEquation` (in `math_equation_block_component.dart`) without modifying the math rendering library, as suggested. I've submitted a PR as this fix: #7961 Also, as users pointed out, wrapping the LaTeX in an `aligned` environment avoids the crash, but causes the equation to lose center alignment. If possible, I’d like to continue working on improving that rendering behavior as a follow-up. I wonder whether this is okay.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
AppFlowy-IO/AppFlowy#3474
No description provided.