horizontal spacing in overbrace and underbrace

1,061 views
Skip to first unread message

Chrissy Safranski

unread,
Jul 22, 2021, 12:21:05 PM7/22/21
to PreTeXt support
The words that go above and below the braces are far too long for the math they're describing.  In the original LaTeX source, it was adjusted with hskips and parboxes, neither of which survived the conversion to PreTeXt, and neither of which appear in the sample article, so I deduce that they're not available. 

I found a different LaTeX solution using \mathclap from the mathtools package, which is available to PreTeXt, so I tried using that, but it's not working.  Not throwing errors, just still giving me uncentered text above and below the braces, like the attached picture.  I included mathtools in my index file, like the sample article did with the cancel package.  

This is what I have now:

\overbrace{(m\times \underbrace{r) \times (r}_{\mathclap{\text{these inner dimensions must match}}} \times n)}^{\mathclap{\text{final dimensions are the outer dimensions}}}

The LaTeX works in overleaf, but the PreTeXt still gives me uncentered text in the html.  

overbracewithtext.JPG
Thank you for any help!
Chrissy

David Farmer

unread,
Jul 22, 2021, 1:10:28 PM7/22/21
to PreTeXt support

This might be a PreTeXt issue, or it might be a MathJax issue.

Are we using the mathtools extension in MathJax in the HTML?
That is needed to get mathclap:

https://docs.mathjax.org/en/latest/input/tex/extensions/mathtools.html




Can you post a live HTML example so we can take a closer look?
> overbracewithtext.JPG
> Thank you for any help!
> Chrissy
>
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt support"
> group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> pretext-suppo...@googlegroups.com.
> To view this discussion on the web visithttps://groups.google.com/d/msgid/pretext-support/f67ba8ce-96d8-4f1a-8aa5-606d5e0aa1b8n%40googl
> egroups.com.
>
>

Rob Beezer

unread,
Jul 22, 2021, 1:29:31 PM7/22/21
to pretext...@googlegroups.com
\underbrace and \overbrace are part of the core functionality of MathJax, so
it would be best to understand how they are working, or not working, first.

I think I understand that if the words are longer than the brace, then even
"pure" LaTeX does not behave so well. So maybe whipping MJ into shape is moot.

"mathtools" is not being loaded now. It is an extension, as David notes. We
might need to look closely at how to make it available as an author, as Chrissy
has tried.

"mathtools" provides 103 macros in the MJ list of supported commands, and maybe
overwrites some?

https://docs.mathjax.org/en/latest/input/tex/macros/index.html

Loading it, for both LaTeX and HTML is an option - always, or conditionally.

Rob

Sean Fitzpatrick

unread,
Jul 22, 2021, 3:25:10 PM7/22/21
to pretext...@googlegroups.com
Not a solution, but a note that when I'm running into issues with math rendering, I find it helpful to go to the MathJax website and use their live demo tool.

I tinker there with different options until I get something that looks ok, and if it works there, it will work in PreTeXt

Alex Jordan

unread,
Jul 22, 2021, 4:06:51 PM7/22/21
to pretext...@googlegroups.com
Here is a hack that works with vanilla MathJax.

\overbrace{(m\times \underbrace{r)\times(r}_{{\llap{\text{these inner
dimen}}\rlap{\text{sions must match}}}}\times n)}^{\text{final
dimensions are the outer dimensions}}

Note that since this breaks up the word "dimensions", the speech
processor reads that part as:
these inner dimen sions must match

If you can settle for not being centered (but still fitting) you could
do the same trick but break it up as {these inner} {dimensions must
match}.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/CAH%2BNcPbXoq-Uc2ngx_bjGt_NW3in-cAcVysCf%3DmZ8RGLTv%2BUdw%40mail.gmail.com.

Chrissy Safranski

unread,
Jul 22, 2021, 7:42:19 PM7/22/21
to PreTeXt support
You are all awesome!

Let me see if I'm understanding:  
 1. mathtools can't just be loaded like an available package can because it's an extension of a package.  (I also don't know how to post a live html example, and that might be useful to know for the future).
 2. Turning that extension on is something that is not generally done at the author level, or at least not at *my* author level ;) but may be a possibility.
 2a. It looks like mathtools does overload some commands, which would make me a little nervous that it would have unexpected results to things that previously looked different.  But I suppose it could make them better.
 
Thank you for the MathJax website tip, and thank you for the workaround!

Another workaround I had tried was to define the command in macros myself.  But I'm really messing above my head with that, and it didn't work (no error thrown, but it broke how matrices display, for example), even if I changed \def to \newcommand.

But this was in the package documentation... could it work to define the command in macros in the index file if someone knew what they were doing?
-----------------------------
% For comparison, the existing overlap macros: 
% \def\llap#1{\hbox to 0pt{\hss#1}} 
% \def\rlap#1{\hbox to 0pt{#1\hss}} 

\def\clap#1{\hbox to 0pt{\hss#1\hss}} 
\def\mathllap{\mathpalette\mathllapinternal} 
\def\mathrlap{\mathpalette\mathrlapinternal} 
\def\mathclap{\mathpalette\mathclapinternal} 
\def\mathllapinternal#1#2{% \llap{$\mathsurround=0pt#1{#2}$}} 
\def\mathrlapinternal#1#2{% \rlap{$\mathsurround=0pt#1{#2}$}} 
\def\mathclapinternal#1#2{% \clap{$\mathsurround=0pt#1{#2}$}}  

from: http://www.tug.org/TUGboat/Articles/tb22-4/tb72perlS.pdf on the second page, which is numbered 351. 
---------------------------

Thank you again!
Chrissy

Rob Beezer

unread,
Jul 23, 2021, 12:30:37 PM7/23/21
to pretext...@googlegroups.com
On 7/22/21 4:42 PM, Chrissy Safranski wrote:
> You are all awesome!

Nicest thing anybody said to me all day yesterday. ;-)

>  1. mathtools can't just be loaded like an available package can because it's
> an extension of a package.  (I also don't know how to post a live html example,
> and that might be useful to know for the future).

More precisely, it is a MathJax extension, which implements the macros of a
LaTeX package. And it *can* be configured as part of the MathJax configuration
(a developer task).

> I included mathtools in my index file, like the sample article did with the
cancel package.

<docinfo>
<latex-preamble>
<package>mathtools</package>
</latex-preamble>
</docinfo>

This should work, and is working for the "cancel" package. Can you test some
obscure, obvious "mathtools" macro that is visually obvious in your HTML output?

>  2a. It looks like mathtools does overload some commands, which would make me a
> little nervous that it would have unexpected results to things that previously
> looked different.  But I suppose it could make them better.

Makes me nervous too. "Better" is in the eye of the beholder.

Rob

Chrissy Safranski

unread,
Jul 23, 2021, 1:29:39 PM7/23/21
to PreTeXt support
Rob, that's what I had in the index file, and it still produced the output of the picture in my first post, which is also what I get when I don't use mathclap.  I'll try to test another mathtools macro the next time I work on it.

But, I think I may have a larger problem... I played around with the mathjax demo site last night (which will be very helpful to me to test things out in the future without reprocessing the whole book).  The code produces different output there than I see in my html version in CoCalc after processing.  Even for the original overbrace-underbrace code that prompted my question (latex and mathjax both show the math part spread out to fit the words, not the text part off center).  So the hack Alex gave works on the MathJax site and looks great visually (though I know the processing isn't quite right), but it doesn't look like that when I put it into CoCalc. I get the same off-center thing.

I have had a recurring issue with lack of space after math and punctuation, too, and it happens everywhere, not just in knowls like the other thread said.  I gave up and moved on, because I figured if the code was right, then I'd figure out how to make it look right later (author vs publisher, right??)

Do you think these visual things are because I'm using CoCalc?  And/or because I don't have a publisher file, yet?  I do a git pull on the development branch of mathbook every day that work on this stuff, so I don't think that's it.

I would drop in to Sococo today, but I'll be on the road then. 

Thanks,
Chrissy

Chrissy Safranski

unread,
Jul 27, 2021, 11:53:52 PM7/27/21
to PreTeXt support
My best guess is that it's the CoCalc html viewer.  I tried with another mathtools macro, the xRightarrow, and the html page didn't look right in the CoCalc iframe, but when I hit "preview" then it did look right.  And when I pasted the html into an online viewer, it looked right.   

So I'm back to what I originally had when I asked my question, but I've learned about the Mathjax demo site, and Netlify (so David, I can post a live html now if I need to in the future!), and also just how helpful everyone is!

And I am loading mathtools as a package, so I'll keep an eye on that affects things.

Thank you again!

Rob Beezer

unread,
Jul 28, 2021, 12:34:41 PM7/28/21
to pretext...@googlegroups.com
Dear Chrissy,

Thanks for the report. I was about to chase you down to see where you were.
Thart's part of being helpful. ;-)

I wonder what's up with CoCalc? We've switched to MathJax 3 recently, but I'd
be surprised if that was the cause? CoCalc is careful with how users access the
internet (like paid v. free). I wonder if there is some difference?

Rob
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/7b76d988-c154-40c6-9b5d-2d3cec56d957n%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/7b76d988-c154-40c6-9b5d-2d3cec56d957n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages