On Saturday, September 5th, 2026 at 2:38 PM, Ihor Radchenko <[email protected]> wrote:
> Carlos Dagorret <[email protected]> writes: > > > I ran into this exact issue when exporting a document with a complex > > MathJax formula, and applying your fix solved the stack overflow for me. > > ... > > It worked fine in my specific test, but I think we need to keep the > > full `<math>...</math>` wrapper because OpenDocument / LibreOffice needs > > those tags to know where the MathML object actually starts and ends. > > Without them, it might fail to render as a proper formula in other cases. > > > > To keep the tags (just like the original code did), we could use > > `(match-beginning 0)` like this: > > > > (when (re-search-forward > > (format "<math[^>]*?%s[^>]*?>" > > (regexp-quote > > "xmlns=\"http://www.w3.org/1998/Math/MathML\"")) > > nil t) > > (let ((from (match-beginning 0))) > > (when (re-search-forward "</math>" nil t) > > (buffer-substring from (match-end 0))))) > > What about simply using non-greedy version of the original regexp? > I cannot test it myself since I do not have a reproducer. The original problem was that the regexp matching engine in Emacs crashes if there is a match which is too long. It can possibly be treated as a bug in Emacs itself (and its fix would probably require redesigning the regexp matching engine), but two regexps instead of one should be a decent workaround for the time being. And yes, the greedy match here invites another kind of trouble: what if there are two MathMLs there and something else in-between? Mykhailo Mishchenko
