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

\underbrace and \overbrace should put their args into \displaystyle unconditionally #764

Closed
kevinbarabash opened this issue Jul 14, 2017 · 11 comments

Comments

@kevinbarabash
Copy link
Member

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.

@kohler
Copy link
Collaborator

kohler commented Jul 14, 2017

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

@edemaine
Copy link
Member

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?

@kevinbarabash kevinbarabash changed the title effect of \displaystyle should continue until next style command \underbrace and \overbrace should put their args into \displaystyle unconditionally Jul 14, 2017
@ronkok
Copy link
Collaborator

ronkok commented Jul 15, 2017

"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.

@kohler
Copy link
Collaborator

kohler commented Jul 15, 2017

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}

@edemaine
Copy link
Member

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

@kevinbarabash
Copy link
Member Author

Looks great!

@edemaine
Copy link
Member

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?

@ronkok
Copy link
Collaborator

ronkok commented Jul 15, 2017

I do agree.

@kohler
Copy link
Collaborator

kohler commented Jul 17, 2017

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

@edemaine
Copy link
Member

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.

@ronkok
Copy link
Collaborator

ronkok commented Jul 17, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants