Skip to content

Handling Nested Braces within a BlockDirective #236

@Weixi779

Description

@Weixi779

I have a question regarding the definition of BlockDirective. In LaTeX syntax, it is possible for content to contain nested curly braces, especially with structures like equation systems (cases). I'm wondering how to properly handle this scenario in the code.

For example, given the following LaTeX block:

@LaTex {
    \\begin{cases}
    \\nabla \\cdot \\vec{E} = \\frac{\\rho}{\\epsilon_0} \\\\
    \\nabla \\cdot \\vec{B} = 0
    \\end{cases}
}

This is my regex code for preprocess markdown.

    // Block math: $$...$$
    static func preprocessMathBlock(_ processed: inout String) {
        let blockPattern = /(?s)\$\$(.*?)\$\$/
        processed = processed.replacing(blockPattern) { match in
            let content = String(match.1).trimmingCharacters(in: .whitespacesAndNewlines)
            return "@\(CustomDirective.math.rawValue) { \(content) }" // if using  {\n\(content)\n} will be without any content
        }
    }

Could you please advise on the correct approach to parse and process content that includes these nested braces?

Thank you for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions