Skip to content
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

Extra space with starred version of a DeclarePairedDelimiter command #3183

Closed
evfinkn opened this issue Feb 14, 2024 · 2 comments
Closed

Extra space with starred version of a DeclarePairedDelimiter command #3183

evfinkn opened this issue Feb 14, 2024 · 2 comments
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Merged Merged into develop branch v3 v4

Comments

@evfinkn
Copy link

evfinkn commented Feb 14, 2024

Issue Summary

When using an operator before the starred version of a command made with \DeclarePairedDelimiter (or its variants), an extra space is added between them. This is true in both MathJax v3 and MathJax v4. I would expect this when using scaled delimiters manually, such as in \sin\left(x\right), but the mathtools documentation mentions fixing this:

Within the starred version of \DeclarePairedDelimiter and \DeclarePairedDelimiterX we make a few changes such that the auto scaled \left and \right fences behave as opening and closing fences, i.e. $\sin(x)$ vs. $\sin\left(x\right)$ (the later made via $\sin\left(x\right)$), notice the gap between ‘sin’ and ‘(’.

Technical details:

  • MathJax Versions: 3.2.2, 4.0.0-beta.4
  • Client OS: macOS 14.3
  • Browsers: Obsidian 1.5.3 (which uses Chromium), Firefox 122.0.1

I'm not sure how Obsidian configures and loads MathJax, but for MathJax v4.0.0-beta.4 in Firefox, I'm using the following configuration:

MathJax = {
  loader: { load: ["[tex]/mathtools"] },
  tex: { packages: { "[+]": ["mathtools"] } },
};

and loading MathJax via

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

Supporting information:

The following screenshots show what I'm referring to. I'd expect the brackets on both lines to align, like in LaTeX.

LaTeX:
dpdxpp-latex

MathJax v3:
dpdxpp-mathjax3

MathJax v4:
dpdxpp-mathjax4

And here's the TeX used in those screenshots:

\DeclarePairedDelimiterXPP\Prob[1]{\Pr}[]{}{#1}
\begin{align}
    \text{unstarred:}\qquad & \Prob{A} \Prob{B} \\
    \text{starred:}\qquad & \Prob*{A} \Prob*{B} \\
\end{align}
@dpvc dpvc added Accepted Issue has been reproduced by MathJax team v3 v4 labels Feb 16, 2024
@dpvc
Copy link
Member

dpvc commented Feb 16, 2024

Thanks for the report. I will need to look into how best to resolve this.

@dpvc
Copy link
Member

dpvc commented Feb 17, 2024

OK, I have a solution and will make a PR for it. In the meantime, you can use

MathJax = {
  loader: {load: ['[tex]/mathtools']},
  tex: {packages: {'[+]': ['mathtools']}},
  startup: {
    ready() {
      const ParseUtil = MathJax._.input.tex.ParseUtil.default;
      const {MathtoolsMethods} = MathJax._.input.tex.mathtools.MathtoolsMethods;
      MathtoolsMethods.PairedDelimiters = function PariedDelimiters(
        parser, name, open, close, body = '#1', n = 1, pre = '', post = ''
      ) {
        const star = parser.GetStar();
        const size = (star ? '' : parser.GetBrackets(name));
        const [left, right, after] = (star ? ['\\mathopen{\\left', '\\right', '}\\mathclose{}'] :
                                      size ? [size + 'l' , size + 'r', ''] : ['', '', '']);
        const delim = (star ? '\\middle' : size || '');
        if (n) {
          const args = [];
          for (let i = args.length; i < n; i++) {
            args.push(parser.GetArgument(name));
          }
          pre  = ParseUtil.substituteArgs(parser, args, pre);
          body = ParseUtil.substituteArgs(parser, args, body);
          post = ParseUtil.substituteArgs(parser, args, post);
        }
        body = body.replace(/\\delimsize/g, delim);
        parser.string = [pre, left, open, body, right, close, after, post, parser.string.substring(parser.i)]
          .reduce((s, part) => ParseUtil.addArgs(parser, s, part), '');
        parser.i = 0;
        ParseUtil.checkMaxMacros(parser);
      };

      MathJax.startup.defaultReady();
    }
  }
};

as a work-around until it is fixed.

@dpvc dpvc added Ready for Review Code Example Contains an illustrative code example, solution, or work-around labels Feb 17, 2024
dpvc added a commit to mathjax/MathJax-src that referenced this issue Feb 17, 2024
dpvc added a commit to mathjax/MathJax-src that referenced this issue Mar 8, 2024
Make stretchy paried delimiters not be class INNER.  (mathjax/MathJax#3183)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Mar 8, 2024
@evfinkn evfinkn closed this as completed Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Merged Merged into develop branch v3 v4
Projects
None yet
Development

No branches or pull requests

2 participants