Skip to content

Bug: tagformat extension generates IDs with colon, but ui/safe default idPattern doesn't allow colons, breaking \eqref anchor navigation #3580

Description

@silencial

Description

When both [tex]/tagformat and ui/safe extensions are enabled in MathJax v4, \eqref links cannot navigate to the target equation. The equation's DOM element loses its id attribute because the safe extension filters it out.

Steps to Reproduce

  1. Enable both tagformat and ui/safe extensions:
window.MathJax = {
  loader: {
    load: ['ui/safe', '[tex]/tagformat']
  },
  tex: {
    tags: 'ams',
    packages: { '[+]': ['tagformat'] }
  }
};
  1. Use \label and \eqref in the document:
\begin{equation}
  E = mc^2 \label{eq:einstein}
\end{equation}

See equation \eqref{eq:einstein}.
  1. Click the equation number generated by \eqref

Expected Behavior

Clicking the \eqref link should scroll/jump to the target equation (same behavior as MathJax v3, or when ui/safe is disabled).

Actual Behavior

  • The equation number (tag) displays correctly
  • The \eqref link is generated with href="#mjx-eqn:eq:einstein"
  • But the target equation element has no id attribute
  • Clicking the link does nothing

Root Cause

  • tagformat extension generates IDs in the format mjx-eqn:label-name (contains colon :)
  • ui/safe extension's default idPattern in safe mode is /^mjx-[-a-zA-Z0-9_.]+$/ which does not include colon
  • IDs with colons are silently stripped by the safe extension

Workaround

Customize idPattern to allow colons:

options: {
  safeOptions: {
    idPattern: /^mjx-[-a-zA-Z0-9_.:]+$/
  }
}

Suggested Fix

Update the default idPattern in ui/safe to include colon, since tagformat is an official extension and its default ID format should work out-of-the-box with the safe extension.

Environment

  • MathJax version: v4.1.2
  • Browser: All browsers

I am loading MathJax via

<script src="https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js"></script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    AcceptedIssue has been reproduced by MathJax teamv4

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions