Skip to content

Fix equation rendering #137

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

EmilyBourne
Copy link

@EmilyBourne EmilyBourne commented May 23, 2025

Fix equation rendering by saving strings from a <formula> tag into a MdInlineEquation or MdBlockEquation. Fixes #133

Summary by Sourcery

Fix equation rendering by introducing inline and block math nodes and mapping <formula> tags to them in the XML parser.

Bug Fixes:

  • Restore equation rendering by converting <formula> tags into math nodes.

Enhancements:

  • Add MdInlineEquation and MdBlockEquation classes for inline and block LaTeX rendering.
  • Update XML parser to strip delimiters and choose inline or block equation based on context.

Copy link

sourcery-ai bot commented May 23, 2025

Reviewer's Guide

Adds support for parsing and rendering mathematical equations by introducing new Markdown node types for inline and block LaTeX formulas and updating the XML parser to detect and handle tags appropriately.

Sequence Diagram: Processing of Tags by XmlParser

sequenceDiagram
    participant Caller
    participant P as XmlParser
    participant E_item as "item: Element"
    participant ME_Block as MdBlockEquation
    participant ME_Inline as MdInlineEquation

    Caller->>P: paras(p, italic)
    activate P
    loop For each item in p elements
        P->>E_item: Access item.tag
        alt If item.tag is "formula"
            P->>E_item: Access item.text (to get equation)
            P->>P: Determine if block or inline (based on p and item.tail)
            alt If block equation
                P->>ME_Block: __init__(equation)
                activate ME_Block
                ME_Block-->>P: mdBlockEquation
                deactivate ME_Block
                P->>P: Add mdBlockEquation to result list
            else Else (inline equation)
                P->>ME_Inline: __init__(equation)
                activate ME_Inline
                ME_Inline-->>P: mdInlineEquation
                deactivate ME_Inline
                P->>P: Add mdInlineEquation to result list
            end
        end
    end
    P-->>Caller: List of Md objects
    deactivate P
Loading

Class Diagram: New Markdown Equation Types and Parser Integration

classDiagram
    class Md {
        <<Abstract>>
        +render(f: MdRenderer, indent: str) void
    }
    class MdInlineEquation {
        -equation: str
        +__init__(equation: str)
        +render(f: MdRenderer, indent: str) void
    }
    class MdBlockEquation {
        -equation: str
        +__init__(equation: str)
        +render(f: MdRenderer, indent: str) void
    }
    class XmlParser {
        +paras(p: Element, italic: bool) list~Md~
    }
    class MdRenderer {
        +write(text: str) void
    }
    class Element {
        +tag: str
        +text: str
        +tail: str
    }

    Md <|-- MdInlineEquation
    Md <|-- MdBlockEquation

    XmlParser ..> MdInlineEquation : "creates"
    XmlParser ..> MdBlockEquation : "creates"
    XmlParser ..> Element : "uses"

    MdInlineEquation ..> MdRenderer : "uses"
    MdBlockEquation ..> MdRenderer : "uses"
Loading

File-Level Changes

Change Details Files
Introduced two new Markdown node classes to render inline and block LaTeX equations
  • Defined MdInlineEquation with inline LaTeX wrapper
  • Defined MdBlockEquation with block LaTeX wrapper
  • Implemented render methods using appropriate delimiters
mkdoxy/markdown.py
Enhanced the XML parser to recognize tags and choose the correct equation node
  • Imported MdInlineEquation and MdBlockEquation
  • Added logic to extract and trim equation text
  • Determined context to differentiate inline vs. block formulas
  • Appended corresponding equation node to the parse tree
mkdoxy/xml_parser.py

Assessment against linked issues

Issue Objective Addressed Explanation

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

@EmilyBourne EmilyBourne force-pushed the ebourne-133-equation-rendering branch from 714935a to 5dcbf02 Compare May 23, 2025 11:41
Copy link

@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 @EmilyBourne - I've reviewed your changes - here's some feedback:

  • The block vs inline equation detection using len(p) == 1 && item.tail is None seems fragile—consider using an explicit context flag or attribute instead of relying on that heuristic.
  • The equation trimming logic item.text.strip("$ ") may remove valid dollar signs inside your equation; use a more precise regex or logic to strip only the outer delimiters.
  • In MdBlockEquation.render, the indent parameter isn’t used and blank‐line handling may be inconsistent—ensure block equations respect indentation and proper Markdown spacing.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: 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.

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.

LaTeX math equation rendering
1 participant