PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
268 stars 210 forks source link

MathJax 4 #1841

Open Alex-Jordan opened 2 years ago

Alex-Jordan commented 2 years ago

The first alpha for MathJax 4 was just announced: https://github.com/mathjax/MathJax-src/releases/tag/4.0.0-alpha.1

This issue is a reminder to monitor the features and progress of MathJax 4, informing decisions about when to eventually move to using it.

rbeezer commented 2 years ago

Inserted the new Javascript script tag for first alpha release, under influence of debug.mathjax4 parameter. No configuration adjustments implemented (or even considered).

Seems to be working OK. Commutative diagram in Subsection 7.6 of sample article has short arrows. Broken arrow in Subsection 7.1 seems to be unrelated (present with MJv3).

rbeezer commented 2 years ago

Just thought to check. Arrows (both examples) are good in Chrome. Bad versions are in Firefox.

dpvc commented 2 years ago

@rbeezer, can you provide me the example diagram? I will look into the issue.

Alex-Jordan commented 2 years ago

We've generally (not completely) ruled out XML children of a PTX math element. But something new with MJ4 is you can have HTML inside the math content. I haven't thought hard about it but that may open up interesting possibilities for PTX elements inside math.

rbeezer commented 2 years ago

@rbeezer, can you provide me the example diagram? I will look into the issue.

Thanks! I was going to wait a bit for confirmation. ;-) Here is the CD which is authored as a PreTeXt <me> element, resulting in HTML and screenshot.

Oooh, that's weird. Screenshot has full arrows. And now I see that if I zoom to just 110% I get full arrows. And full at 90%. (At 100% arrows are all short and pushed to the right, which I can't show you!)

Screenshot 2022-10-03 at 10-46-12 SA Mathematics

\begin{CD}
 E[x]/\langle p(x) \rangle    @>\psi>>  F[x]/\langle q(x) \rangle\\
@VV{\sigma}V        @VV{\tau}V\\
 E(\alpha)     @>\overline{\phi}>>  F(\beta)\\
@VVV        @VVV\\
 E     @>\phi>>  F
 \end{CD}
<div class="displaymath process-math" data-contains-math-knowls="">
\begin{equation*}
\begin{CD}
E[x]/\langle p(x) \rangle    @&gt;\psi&gt;&gt;  F[x]/\langle q(x) \rangle\\
@VV{\sigma}V        @VV{\tau}V\\
E(\alpha)     @&gt;\overline{\phi}&gt;&gt;  F(\beta)\\
@VVV        @VVV\\
E     @&gt;\phi&gt;&gt;  F
\end{CD}
\end{equation*}
</div>
rbeezer commented 2 years ago

may open up interesting possibilities

Exactly. But I'm also not sure what they are yet. ;-)

dpvc commented 2 years ago

@rbeezer, Thanks! I had hoped the new fonts would resolve that (and I wasn't able to reproduce in my setting). There does seem to be a problem with Firefox (ongoing, version 3 has it as well) dealing with displaying the stretched extender used for the rest of the arrow (what you are seeing is just the head of the arrow, without the extender). I will need to look into that problem (again).

rbeezer commented 2 years ago

I've restored the debug.mathjax.svg parameter to be effective with v4 as well as v3. Might be a useful option to employ when debugging something with the "regular" configuration.

dpvc commented 2 years ago

@rbeezer, just FYI, as part of the one-line breaking implementation in v4.0.0, I think I have taken care of the dangling punctuation problem, where a line break could occur between math and a following period or other punctuation.

rbeezer commented 2 years ago

I think I have taken care of the dangling punctuation

Thanks, @dpvc, that was the first thing I was going to experiment with!

Alex-Jordan commented 2 years ago

About HTML within the math. We should look into handling text within math this way. So where an author might currently do <m>x\text{ some text here}</m> there would be something like <m>x<text>some text here</text></m>.

rbeezer commented 1 year ago

Thorough experiments suggest MathJax 4 has line-breaking under control when inline math butts up to clause-ending punctuation. So we can turn on our manipulations for just display math. Remaons to test expressions like <m>x</m>-axis. Complete details posted on pretext-dev "MathJax v4" thread and reproduced here.


Well into the weeds on this one. ;-) Browsers have been inclined to put a line-break right after some inline math (MathJax) and before "clause-ending punctuation," such as a period or a comma. Which looks really unprofessional.

So we have been absorbing the punctuation into the math with a \text{} and scrubbing it from where it was authored. You're welcome! Good, but maybe not so optimal for the math bits when used in other ways (braille). MathJax 4 has this under control now.

Experiment: hack into our fix, turn it off, but also add a " FOO " after the punctuation and before whatever comes next. To make these situations easy to locate. Build Judson's AATA, chunked by chapter. Investigate. Chapters 5, 8, 17, 21, 23 (for no particular reason). 907 locations where punctuation follows math. 7 are a bad line-break. And never more than two in a single chapter.

Now, turn on MathJax 4 and rebuild. All 7 bad breaks behave themselves. Chapters 5, 8 and 17 show no bad breaks (didn't cruise the others).

https://pretextbook.org/beta/2022-11-29-math-punctuation/

Alex is interested in expressions like $x$-axis which I did not explicitly test.

Notes:

  1. Punctuation on display math may be messed up, just a consequence of my hack.

  2. A "FOO" at the start of a line is an apparent success (look at end of previous line).

  3. " FOO" at the start of a line is a failure.

  4. Mostly tested in Chrome. Only Chapter 17 tested in my Firefox has been crippled for testing by Ubuntu's delivery via Snap packaging. Not a fan. (Yes, I'll install it differently when I get a chance.) Both bad breaks were fixed, but the math+punctuation unit went to different lines on different browsers. I'd guess fine details of font sizes, etc will influence these minute decisions.

  5. debug.mathjax4 yes|no can control the MathJax version.

  6. math.punctuation.include display will turn off our inline adjustments, but you won't get a "FOO", and this is not what I did.

Short answer: perhaps we turn off our low-level manipulation when we switch to MathJax 4. We may still want it for SVG images of math that go into EPUB (and similar). We'll need to test line-breaking between an image and punctuation there, since we won't have MathJax controlling it.

bnmnetp commented 1 year ago

I tried a runestone build for academy with mathjax4 enabled. Chaos ensued. Will require some investigation to figure out what is going wrong. Looks like startup stuff may have changed.

rbeezer commented 1 year ago

Visit #1493 before closing this one.

rbeezer commented 1 year ago

From Davide Cervone on the mathjax-users Google Group:

We are in final preparation for v4.0.0-beta.1, which should be out early next week, if not this weekend. Then, provided that goes well, there is some code cleanup we want to do, but I expect an official v4.0 by the end of August.

rbeezer commented 1 year ago

beta 3 is available (1 and 2 were packaging mistakes, so this is the first real beta). Change at 58f22acc9c77c5e8966549a84b31edf58e9ce7d4

Reminder: stringparam debug.mathjax4 set to yes will activate this new vesion.

Release notes: https://github.com/mathjax/MathJax-src/releases/tag/4.0.0-beta.3

I've only tested to make sure math renders. Seems fine in that regard.

rbeezer commented 1 year ago

See

https://github.com/mathjax/MathJax/issues/1081#issuecomment-1769203901

for a possible long-term solution to \sfrac support.

rbeezer commented 6 months ago

Now available to test beta-6.

rbeezer commented 5 months ago

See https://github.com/PreTeXtBook/pretext/pull/2180 for a solution to the problems with knowls inside display math.

whaynes commented 3 months ago

But something new with MJ4 is you can have HTML inside the math content. I haven't thought hard about it but that may open up interesting possibilities for PTX elements inside math.

Just reading this two year old thread for the first time today, but one interesting possibility would be to permit quantities with units inside math.

rbeezer commented 3 months ago

one interesting possibility would be to permit quantities with units inside math

Yes, that prospect might excite @Alex-Jordan!

Alex-Jordan commented 3 months ago

We (99% my colleague @limefrogyank) have been working on this:

https://github.com/limefrogyank/siunitx-pcc

I haven't had time to put it into PTX. But I think the better solution with units inside math is to just use siunitx syntax. Assuming this meets all needs.

rbeezer commented 1 month ago

I keep looking here thinking I will find this. To test MJ4,

stringparam debug.mathjax4 is set to yes.