Skip to content

纯数字的数学公式是不是不解析啊 #342

Description

@liangchencl

是这样的:我让大模型输出一道 20以内的加减法

content: "好呀,那这道题是\(9 + 8 = \) 。同样可以用实物辅助孩子理解哦,比如用小卡片,9张卡片加上8张卡片,看看总数是多少。"

然后用 正则匹配\( *** \) 替换成了 $***$ 但是页面上显示的

好呀,那这道题是$9 + 8 = $。同样可以用实物辅助孩子理解哦,比如用小卡片,9张卡片加上8张卡片,看看总数是多少。

其他的公式都会转换成一张图,但是这个并没有 还是一个字符串

Activity

  1. liangchencl commented on Aug 15, 2025

    @liangchencl
    Author

    自己用正则匹配了一下 没有字母的公式按原样输出 有字母的则走上面的替换

    return str.replace(/(\\\()(.*?)(\\\))/g, (match, start, content, end) => {
            // 检查内容中是否包含字母
            if (/[a-zA-Z]/.test(content)) {
                // 有字母则替换为 $...$
                return `$${content}$`;
            } else {
                // 无字母则保持原样
                return match;
            }
        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions