Skip to content

fix: fix Latex BuildException #7961

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

M-T-Arden
Copy link

@M-T-Arden M-T-Arden commented May 21, 2025

PR Checklist

Summary by Sourcery

Bug Fixes:

  • Fixes a BuildException that occurs when importing LaTeX equations containing raw \\ line breaks from external sources (e.g., Notion). This fix introduces a preprocessing step that wraps such input in an aligned environment, preventing CrNode exceptions without modifying the math rendering library.
  • Related to [Bug] Latex rendering error #7949

Summary by Sourcery

Prevent BuildException when rendering LaTeX equations containing raw '\' by wrapping them in an 'aligned' environment using a new preprocessing step.

Bug Fixes:

  • Prevent BuildException when importing LaTeX formulas with raw '\' line breaks by wrapping them in an 'aligned' environment if not already wrapped.

Enhancements:

  • Introduce a _safeLatex preprocessing function to wrap raw line breaks in an aligned environment before rendering.

Copy link
Contributor

sourcery-ai bot commented May 21, 2025

Reviewer's Guide

Introduces a preprocessing step in the MathEquationBlockComponentWidgetState to wrap imported LaTeX containing raw "\" line breaks in an aligned environment, preventing BuildException errors without altering the underlying rendering library.

Sequence Diagram for LaTeX Preprocessing within _buildMathEquation

sequenceDiagram
    participant BME as _buildMathEquation
    participant SL as _safeLatex
    participant Renderer as Math.tex

    BME->>SL: _safeLatex(formula)
    activate SL
    alt formula contains literal '\\\\' AND no literal '\\begin{'
        SL->>SL: newFormula = "\\begin{aligned}" + formula + "\\end{aligned}"
        SL-->>BME: newFormula
    else formula is safe OR has existing environment
        SL-->>BME: formula (unchanged)
    end
    deactivate SL
    BME->>Renderer: tex(processedFormula)
    activate Renderer
    Renderer-->>BME: RenderedOutput
    deactivate Renderer
Loading

Updated Class Diagram for MathEquationBlockComponentWidgetState

classDiagram
    class MathEquationBlockComponentWidgetState {
        +Widget _buildMathEquation(BuildContext context)
        -_safeLatex(String raw) String
    }
Loading

File-Level Changes

Change Details Files
Preprocess LaTeX formulas containing raw line breaks by wrapping them in an aligned environment
  • Added private _safeLatex(raw) helper: if raw contains "\" and no existing "\begin", wraps it in "\begin{aligned}…\end{aligned}"
  • Replaced direct use of formula with _safeLatex(formula) when calling Math.tex
frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart

Possibly linked issues

  • [Bug] Latex rendering error #7949: The PR fixes the BuildException and CrNode error when rendering Latex with raw \ line breaks by wrapping the input in an aligned environment.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CLAassistant
Copy link

CLAassistant commented May 21, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @M-T-Arden - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@M-T-Arden M-T-Arden changed the title fix: #7949 Latex BuildException fix: fix Latex BuildException May 22, 2025
@M-T-Arden
Copy link
Author

After fixing the LaTeX BuildException, the default right alignment for overflowed formulas may not meet users' needs. I adjusted this to left alignment (see the latest commit).

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

Successfully merging this pull request may close these issues.

3 participants