Katex: \underbrace and \overbrace should put their args into \displaystyle unconditionally

Created on 14 Jul 2017  Â·  11Comments  Â·  Source: KaTeX/KaTeX

If there's a group that comes right after \displaystyle then we only apply its effects to that group instead of everything that follows \displaystyle.

\overbrace{
\displaystyle{\oint_S{\vec E\cdot\hat n\,\mathrm d a}}}^\text{emf} = 
\underbrace{\frac{q_{\text{enc}}}{\varepsilon_0}}_{\text{charge}}

horizontalbraces
LaTeX is in green, KaTeX is in red. Notice the size difference.

All 11 comments

Don't think this is a correct analysis. The \displaystyle is inside a group, the \overbrace group.

What really appears to be going on is that \underbrace and \overbrace should put their arguments into display mode unconditionally. TeX input

$
{{\oint_S{\vec E\cdot\hat n\,\mathrm d a}}} = 
{\frac{q_{\text{enc}}}{\varepsilon_0}}
$

$
\overbrace{{\oint_S{\vec E\cdot\hat n\,\mathrm d a}}} = 
\underbrace{\frac{q_{\text{enc}}}{\varepsilon_0}}
$

pdftex output

screen shot 2017-07-14 at 2 35 41 pm

groupTypes.horizBrace has the following code:

    // Build the base group
    const body = buildGroup(
       group.value.base, options.havingStyle(style.cramp()));

I'm not sure what cramped means, but I'm guessing we want to in addition / instead switch style to its display version, with a new display() method on Style?

"Cramped" is a style modification in which exponents are not raised as high as they would be in in non-cramped style. "Cramped" is typically used in something like a fraction numerator or denominator, or in this case, a brace.

I reckon that you are correct in saying that a style adjustment is needed here. If you would like to suggest something more detailed, that would be welcome. Otherwise I'll get some time for research in a few days.

Definition of \over/underbrace in LaTeX fontmath.ltx

\def\overbrace#1{\mathop{\vbox{\m@th\ialign{##\crcr\noalign{\kern3\p@}%
      \downbracefill\crcr\noalign{\kern3\p@\nointerlineskip}%
      $\hfil\displaystyle{#1}\hfil$\crcr}}}\limits}
\def\underbrace#1{\mathop{\vtop{\m@th\ialign{##\crcr
   $\hfil\displaystyle{#1}\hfil$\crcr
   \noalign{\kern3\p@\nointerlineskip}%
   \upbracefill\crcr\noalign{\kern3\p@}}}}\limits}

I'm a little confused about cramped style. Does it correspond to something in LaTeX (perhaps defined in mathtools?) that you're reproducing? I looked at mathtools's definition of \over/underbrace and didn't see anything about "cramped"...

\def\overbrace#1{\mathop{\vbox{\m@th\ialign{##\crcr
  \noalign{\kern.5\fontdimen5\textfont2}%
  \downbracefill\crcr
  \noalign{\kern.7\fontdimen5\textfont2\nointerlineskip}%
  $\hfil\displaystyle{#1}\hfil$\crcr}}}\limits}

Anyway, with the following change:

diff --git a/src/buildHTML.js b/src/buildHTML.js
index 944fdc6..d9d8e9a 100644
--- a/src/buildHTML.js
+++ b/src/buildHTML.js
@@ -1516,7 +1516,7 @@ groupTypes.horizBrace = function(group, options) {

     // Build the base group
     const body = buildGroup(
-       group.value.base, options.havingStyle(style.cramp()));
+       group.value.base, options.havingBaseStyle(Style.DISPLAY));

     // Create the stretchy element
     const braceBody = stretchy.svgSpan(group, options);

I get the following texcmp output for the HorizontalBraces test, which seems to be on the right track:

horizontalbraces

Looks great!

OK, #765 was merged, which switches the text being braced into displaystyle. This definitely seems in line with the LaTeX/mathtools source.

@ronkok In particular, I don't see why the main-line text would be cramped. (I could see it for the above/below text...) Do you agree?

I do agree.

FYI TeX commands such as \textstyle/\displaystyle always reset the “cramped” flag to false.

Finally found "cramped" briefly mentioned on page 140 of the TeXbook.

TEX actually has eight different styles in which it can treat formulas, namely
display style (for formulas displayed on lines by themselves)
text style (for formulas embedded in the text)
script style (for formulas used as superscripts or subscripts)
scriptscript style (for second-order superscripts or subscripts)
and four other “cramped” styles that are almost the same except that exponents aren’t raised quite so much. For brevity we shall refer to the eight styles as
D, D', T, T', S, S', SS, SS',
where D is display style, D' is cramped display style, T is text style, etc.

Looks like #765, which uses options.havingBaseStyle(Style.DISPLAY), will indeed reset cramped to false.

Yep, that's "cramped". And KaTeX does use "cramped" to modify sup elevation when inside numerators, denominators, \sqrt, etc. It was an error on my part to use it inside \overbrace. I'm glad that others have straightened things out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

msridhar picture msridhar  Â·  3Comments

shaunc picture shaunc  Â·  4Comments

sophiebits picture sophiebits  Â·  3Comments

asmeurer picture asmeurer  Â·  3Comments

q2apro picture q2apro  Â·  3Comments