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

The commands \tilde, \dot, \ddot, \hat, and \bar mess up with subscripts. #2474

Closed
Batominovski opened this issue Jul 18, 2020 · 3 comments
Closed

Comments

@Batominovski
Copy link

Let's take a look at $\tilde{f}_{k}$ and $f_k$. Do you notice that the subscript $k$ is awkwardly spaced from $\tilde{f}$ in $\tilde{f}_k$? The same problem occurs if I use \widetilde: $\widetilde{f}_k$. Even with \dot, \hat, and \bar commands, the same problem occurs: $\dot{f}_k$, $\hat{f}_k$, and $\bar{f}_k$. The command \ddot also causes a similar problem.

I know there is a way to re-adjust the spacing by using \!, so $\tilde{f}_{\!k}$ and $\tilde{f}_{\!\!k}$ would become $\tilde{f}{!k}$ and $\tilde{f}{!!k}$, respectively. They look a lot better than $\tilde{f}_k$, although the spacing isn't the same as in $f_k$ (which annoys me a little bit).

For some other characters, the spacing is ok. For example, $\tilde{a}_k$ produces $\tilde{a}_k$, which has the same spacing as $a_k$. It seems the problem occurs with tall characters like $d$ and $t$: $\tilde{d}_k$ and $\tilde{t}_k$ (comparing with $d_k$ and $t_k$). The problem is lessened with deep characters like $g$ and $y$: $\tilde{g}_k$ and $\tilde{y}_k$ (comparing with $g_k$ and $y_k$).

Please also see: https://math.meta.stackexchange.com/questions/32180/the-command-tilde-messes-up-with-subscripts. I basically copied most of what I had written there to the bug report.

@Batominovski Batominovski changed the title The command \tilde, \dot, \ddot, \hat, \bar, messes up with subscripts. The command \tilde, \dot, \ddot, \hat, \bar, mess up with subscripts. Jul 18, 2020
@Batominovski Batominovski changed the title The command \tilde, \dot, \ddot, \hat, \bar, mess up with subscripts. The commands \tilde, \dot, \ddot, \hat, and \bar mess up with subscripts. Jul 18, 2020
@dpvc
Copy link
Member

dpvc commented Jul 21, 2020

Since MathJax converts TeX to MathML internally, the processing of expressions is somewhat different in MathJax than in TeX itself. The natural translation of \tilde{f}_{k} into MathML is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <msub>
    <mover>
      <mi>f</mi>
      <mo stretchy="false">~</mo>
    </mover>
    <mi>k</mi>
  </msub>
</math>

while that for f_k is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <msub>
    <mi>f</mi>
    <mi>k</mi>
  </msub>
</math>

When both TeX and MathJax add super- or subscripts to a base expression, special rules apply if the base is a single letter. If it is, the italic correction of the letter is taken into account when the scripts are placed. That is the case for f_k, which means the k is slightly closer to the f than it would normally be. Where TeX and MathJax differ is in the handling of accents, as you have found out. In TeX, there are heuristics whereby TeX ignores an accent for spacing purposes (see issue #712 for some details about that). MathJax doesn't have this heuristics, and so treats the <mover> as it would any other one, and uses its bounding box for positioning the super- and subscripts. This is done without any italic correction, which puts the k directly at the right-hand side of the bounding box. Moreover, since the tilde has been shifted to the right in order to center on the top of the f better, it actually extends to the right of the f slightly, so the bounding box for the collection is a bit father to the right of the top of the f, which makes the position k even more to the right.

That is the technical reason for the issue. Issue #712 is a feature request to use similar heuristics to those of TeX to better handle the vertical position of the scripts, but it would also allow the use of the italic correction values to better position the subscript horizontally as well.

Until that is done, you do have the various suggestions from the StackExchange site that can be used to improve the results for now.

@dpvc
Copy link
Member

dpvc commented Jul 21, 2020

I'm marking this a duplicate of #712 because resolving that issue will resolve this one.

@dpvc
Copy link
Member

dpvc commented Mar 11, 2021

This will be resolved in v3 by PR mathjax/MathJax-src#618.

@dpvc dpvc added this to the 3.1.3 milestone Mar 11, 2021
dpvc added a commit to mathjax/MathJax-src that referenced this issue Mar 19, 2021
Handle accents more like TeX does (better sizes and placement) (mathjax/MathJax#712, mathjax/MathJax#2474)
@dpvc dpvc closed this as completed Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants