5

Simple problem: spacing in math mode can often be awkward, especially with large fences and super- or sub- scripts. Usually, this amounts to exponents being too far from the parenthesized expression, like in the 2nd last example, where it is closer to the enclosing parenthesis than the inner expression it attaches to.

Example 1 is the default behavior, showing both how the superscript is too far from the parenthesis and the large gap it introduces before the equal sign.
Example 2 uses mathtools' mathXlap, which just ignores the superscript, and leaves brings everything too close together, leaving the exponent looking awkward.
Example 3 improves upon 2 by adding manual negative spacing to bring the superscript closer to the parenthesis. One might argue it would still be better to add more space to the left of the equal sign.
Example 4 shows bad visuals with nested fences and exponents.
Examples 3 and 5 are what I think looks the best, or at least better than default.

Of course, I can go around manually fixing spacing issues, or manually use smaller-sized fences, but I really hope there's a way for LaTeX to do this automatically, as it is meant to be good at typesetting (mathematics).

I've heard of "staircase kerns" that some math fonts apparently have to improve super- and sub- script placement. This sounds promising, but I have not found any specific info on where to find or how to use such fonts. (I would like to keep the Computer Modern look as well.)
So, I'm just looking for any automatic solution that I might've missed.

Examples MWE: (physcs is there just to typeset the differentials easier)

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{physics}

\begin{document}

    \begin{gather*}
        \frac{z}{b} = \left( \dv{v}{t} \right)^{-1} = \frac{1}{a} \\
        \frac{z}{b} = \left( \dv{v}{t} \right)^{\mathrlap{-1}} = \frac{1}{a} \\
        \frac{z}{b} = \left( \dv{v}{t} \right)^{\mathrlap{\!\!-1}} = \frac{1}{a} \\
    \end{gather*}

    \begin{gather*}
        \left( D\left( \dv[3]{A_{x0}}{A_{y0}} \right)^{2k} \right) \\
        \left( D\!\left( \dv[3]{A_{x0}}{A_{y0}} \right)^{\!\!2k}\, \right)
    \end{gather*}

\end{document}

compiled example

2
  • 3
    Welcome to TeX.SE. Is there a reason for not considering \frac{z}{b} = \left( \dv{v}{t} \right)^{\!-1} = \frac{1}{a} or \frac{z}{b} = \left( \dv{v}{t} \right)^{\!\!-1} = \frac{1}{a} as well?
    – Mico
    Commented Nov 12, 2023 at 16:05
  • 2
    I don't know of any math typography comvention that would allow the exponent associated with some subformula to hang out/overlap with a trailing = symbol.
    – Mico
    Commented Nov 12, 2023 at 16:17

1 Answer 1

6

Too long for a comment, and David was inciting me to write something how this is done in ConTeXt lmtx.

I have, together with Hans Hagen, looked at these staircase kerns, and not so many fonts have them, and they are also not consistent in the fonts (that we have seen) that have them. The decision for ConTeXt became: Do not use them, convert to corner kerns (for the four corners).

In some fonts, like Latin Modern Math, we have manually added such kerns top right and bottom right for the right parenthesis. This is a bit complicated, since the different sizes might need different amount of kern. Looking in modern-math.lfg, where we tweak Latin Modern Math, we find the lines (0x29 is the right parenthesis)

["0x29.variants.*"]     = { topright = -0.15, bottomright = -0.15 },
["0x29.parts.top"]      = { topright = -0.3,},
["0x29.parts.bottom"]   = { bottomright = -0.3  },

All variants get a certain negative kern, and when the recipe kicks in, there is a larger negative kern. Let us look how this can come out, but first without those tweaks:

Non-tweaked

The code used was

\setupmathematics
  [differentiald=upright]

\startbuffer
\dm{\frac{z}{b} = \left(\frac{\dd v}{\dd t}\right)^{-1} = \frac{1}{a}}

\blank[small]

\dm{\left( D \left( \frac{\dd^3 A_{x0}}{\dd A^3_{y0}}\right)^{2k} \right)}

\blank[big]
\stopbuffer

\startTEXpage[offset=1DK]
\setupbodyfont[modern-nt]
\getbuffer
\stopTEXpage

Here, we have set the font to modern-nt, that should be read as modern not tweaked. This shall be compared with the default tweaked variant we get if we comment out the \setupbodyfont line:

Tweaked version

Maybe the difference is subtle. It is a bit more visible here where we show glyphs (\showglyphs) and also show the inter-atom spaces added (\showmakeup[mathglue]):

With helpers

Look at the orange boxes, and how the -1 and 2k are pushed a bit to the left.

4
  • "inciting " ? I'm sure you meant to write "offering constructive encouragement" Commented Nov 12, 2023 at 17:03
  • @DavidCarlisle Haha, yes, something like that. ;)
    – mickep
    Commented Nov 12, 2023 at 17:09
  • is this feature only available with ConTeXt or can I also get this with LuaLaTeX/XeLaTeX?
    – Akioweh
    Commented Nov 13, 2023 at 10:52
  • Currently only for ConTeXt lmtx, I'm afraid.
    – mickep
    Commented Nov 13, 2023 at 11:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .