Quirk with \text{} ?

67 views
Skip to first unread message

Mark Fitch

unread,
Jan 25, 2022, 3:01:50 PM1/25/22
to pretext...@googlegroups.com

Math which uses \text{} to enter units seems to be producing errors with spacing. See the html examples below.

http://www.math.uaa.alaska.edu/~afmaf/classes/math104/materials/section-ratios.html#example-ratio-airspeed-solve

<example xml:id="example-ratio-airspeed-solve">
    <title>Proportion: Solving</title>
    <p>The Diamond DA-20 cruises at the rate of <me>\frac{110 \text{ nautical miles}}{1 \text{ hour}}</me>.</p>
    <p>How long will it take to travel 236 nm?</p>
    <p>Because this is a fixed ratio we can write
        <md>
            <mrow>\frac{110 \text{ nm}}{\text{hour}} \amp = \frac{236 \text{ nm}}{t \text{ hours}}.</mrow>
            <mrow>t \text{ hours} \cdot \frac{110 \text{ nm}}{\text{hour}} \amp = t \text{ hours} \cdot \frac{236 \text{ nm}}{t \text{ hours}}.</mrow>
            <mrow>t \cdot 110 \text{ nm} \amp = 236 \text{ nm}.</mrow>
            <mrow>t \cdot 110 \text{ nm} / 110 \text{ nm}  \amp = 236 \text{ nm}/ 110 \text{ nm}.</mrow>
            <mrow>t \amp = \frac{236}{110}.</mrow>
            <mrow>t \amp \approx 2.1.</mrow>
        </md>
        The multiplying steps are often called <term>cross multiplying</term>.
    </p>
</example>

http://www.math.uaa.alaska.edu/~afmaf/classes/math104/materials/section-ratios.html#example-unit-conversion1

    <example xml:id="example-unit-conversion1">
        <statement><p>We will convert 2.1 hours to a number of minutes. Note we know there are 60 minutes per hour. Notice that the conversion is like a rate. Specifically it is a fraction. If we multiply minutes/hour by hours we will end up with just minutes.</p></statement>
        <solution><p>
            <md>
                <mrow>2.1 \text{ hours} \cdot \frac{60 \text{ minutes}}{\text{hour}} \amp =</mrow>
                <mrow>2.1 \cdot 60 \cdot \frac{\bcancel{\text{ hours}}}{\bcancel{\text{hour}}} \text{ minutes} \amp =</mrow>
                <mrow>126 \text{ minutes}. \amp</mrow>
            </md>
            </p>
        </solution>
    </example>

Dr. Mark A. Fitch
Chair, Department of Mathematics & Statistics

maf...@alaska.edu
907-786-1656
SSB 154
University of Alaska Anchorage
3211 Providence Drive, Anchorage, AK 99508

David Farmer

unread,
Jan 25, 2022, 3:10:14 PM1/25/22
to pretext...@googlegroups.com

That is odd, because it works when I paste that source into the
testing box on the MathJax site.

I'll see what I can find.

David
> --
> 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/bae0fc34-89ff-48c5-c574-94c1b47fa6e1%40alaska.edu.
>
>

Rob Beezer

unread,
Jan 25, 2022, 3:14:46 PM1/25/22
to pretext...@googlegroups.com
On 1/25/22 12:01 PM, Mark Fitch wrote:
> Math which uses \text{} to enter units seems to be producing errors with
> spacing. See the html examples below.

And PDF looks good for those examples?

Alex Jordan

unread,
Jan 25, 2022, 3:26:24 PM1/25/22
to pretext...@googlegroups.com
More odd.

At first it looks bad.

I changed the math renderer from CHTML to SVG and that looks OK.

Then I change back from SVG to CHTML and it looks OK.

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

Mark Fitch

unread,
Jan 25, 2022, 3:29:17 PM1/25/22
to pretext...@googlegroups.com

Yes. I just produced that and the spacing is as expected in print.

Mark Fitch

unread,
Jan 25, 2022, 3:30:25 PM1/25/22
to pretext...@googlegroups.com

Rob Beezer

unread,
Jan 25, 2022, 3:56:56 PM1/25/22
to pretext...@googlegroups.com
MathJax has a developer drop-in hour coming up soon. ;-)

On 1/25/22 12:30 PM, Mark Fitch wrote:
> That happens for me as well.
>
> On 1/25/22 11:26 AM, Alex Jordan wrote:
>> More odd.
>>
>> At first it looks bad.
>>
>> I changed the math renderer from CHTML to SVG and that looks OK.
>>
>> Then I change back from SVG to CHTML and it looks OK.
>>
>> On Tue, Jan 25, 2022 at 12:14 PM Rob Beezer <bee...@ups.edu> wrote:
>>
>> On 1/25/22 12:01 PM, Mark Fitch wrote:
>> > Math which uses \text{} to enter units seems to be producing errors with
>> > spacing. See the html examples below.
>>
>> And PDF looks good for those examples?
>>
>> --
>> 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-support%2Bunsu...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/pretext-support/045a1c35-1756-6fa9-6dae-a8ed800544c8%40ups.edu.
>>
>> --
>> 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/CA%2BR-jrdZRx9MWYqPF_%2ByFf%3DA177PVGjaj9Kd1%3DqeBDt-hU8iQA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/pretext-support/CA%2BR-jrdZRx9MWYqPF_%2ByFf%3DA177PVGjaj9Kd1%3DqeBDt-hU8iQA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> 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/457dc679-6370-2703-be87-e1456726420a%40alaska.edu
> <https://groups.google.com/d/msgid/pretext-support/457dc679-6370-2703-be87-e1456726420a%40alaska.edu?utm_medium=email&utm_source=footer>.

David Farmer

unread,
Jan 25, 2022, 3:58:04 PM1/25/22
to pretext...@googlegroups.com

When I add that same display math near the end of the page, it has the
same error.

When I put it near the beginning, it works, and also the original one
looks right!

I have a theory (and also a meeting right now :)

On Tue, 25 Jan 2022, Mark Fitch wrote:

>
> https://groups.google.com/d/msgid/pretext-support/457dc679-6370-2703-be87-e1456726420a%40alaska.edu.
>
>

David Farmer

unread,
Jan 25, 2022, 5:01:12 PM1/25/22
to pretext...@googlegroups.com

Here is what I think is happening.

Recall that when math is hidden in a knowl, we do not want MathJax
to process it until it is ready to put on the page. (Because sometimes
the contents are messed up, because MathJax does not have access to the
surrounding material when it tries to match sizes.)

Some (presumably recent) change has cause MathJax to process the hidden
math while it is still hidden.

For example, here is the solution knowl to Example 2.3.10 in the page Mark
posted:

<div class="hidden-content tex2jax_ignore" id="hk-solution-36">
<div class="solution solution-like">
<div class="displaymath process-math" id="p-165">
\begin{align*}
\frac{450 \text{ feet}}{\text{ minute}} \cdot \frac{0.3048 \text{
meters}}{\text{ foot}} \amp = \\
450 \cdot 0.3048 \frac{\bcancel{\text{ feet}}}{\bcancel{\text{ foot}}}
\cdot \frac{\text{ meters}}{\text{ minute}} \amp \approx \\
\frac{140 \text{ meters}}{\text{ minute}}.
\end{align*}
</div>
</div>
</div>

What I see is a div.process-math inside a divtex2jax_ignore .

What is MathJax supposed to do? Process the inner div, or not
process the inner div? Well, it is processing it, which you can
see by inspecting the page before the knowl is opened.

So I took the process-math class off the hidden solution. That
prevents it from being processed. But then when I open the knowl,
it is processed! Even though it does not have the process-math class!
And it still looks wrong! (the cancel through foot is off, and other
alignment problems.) (except I looked again and don't see the alignment
problems)

That makes me think MathJax in a knowl does not know about all the
setting on the main page (otherwise, it would not process the math
without the process-math class), which may also be causing the other
problems.

So, maybe I don't actually know what is happening.

David
> https://groups.google.com/d/msgid/pretext-support/alpine.LRH.2.21.2201251556010.16281%40li375-150.members.linode.com.
>

Alex Jordan

unread,
Jan 25, 2022, 5:16:56 PM1/25/22
to pretext...@googlegroups.com
Something in MathJax is setting some widths equal to 0.

Screen Shot 2022-01-25 at 2.11.40 PM.png

Note that it is not all the text content within the math. It's only happening here with
t \text{ hours}
whether that is in a denominator or on the main baseline.

Rob Beezer

unread,
Jan 25, 2022, 5:24:44 PM1/25/22
to pretext...@googlegroups.com
tex2jax_ignore is the *old* way of doing things. But I think we need it for
Jupyter, which I don't think has moved to MJ3 yet (thats all speculation).

But "process_math" is the new way of doing things. (It lets dollar-signs be
dollar-signs, "\(" be itself, etc outside of what we already know to be math.)

What is the behavior like if you remove the outer div.tex2jax_ignore?

Rob

David Farmer

unread,
Jan 25, 2022, 5:26:51 PM1/25/22
to pretext...@googlegroups.com

I had some success replacing
t \text{ hours}
by
t\,\text{hours}

But when I globally replaced " \text{ " by "\,\text{"
it looked bad again!

BUT THEN when I replaced "\text{" by "\,\mathrm{"
everything (everything I noticed) looked good.

Maybe there is a reason why "mathrm" is better than "text" in
the case of units?

What we need is proper unit support, so authors only worry about units
and not typesetting.

On Tue, 25 Jan 2022, Alex Jordan wrote:

> Something in MathJax is setting some widths equal to 0.
>
> To view this discussion on the web visithttps://groups.google.com/d/msgid/pretext-support/CA%2BR-jrcmfTAnpBfj7gqZu24%2BniMZEvS01GOiWYZXLxyNahhR6Q%40mail.gmail.com
> .
>
>

Alex Jordan

unread,
Jan 25, 2022, 6:40:10 PM1/25/22
to pretext...@googlegroups.com
> What we need is proper unit support, so authors only worry about units
and not typesetting.

There are two approaches to this. Plan A has been:
Wait until someone develops MathJax support for units, like with a
working siunitx extension. Then for example authors could just use
9.8\meter\per\second\squared if they are inside a PTX math element.
Just as we defer to LaTeX math syntax, we'd defer to LaTeX unit
syntax. Meanwhile if you are not in math, there is the current units
support.

Plan B would be to extend the current PTX unit-making elements to work
inside a PTX math element. Initially we wanted to avoid PTX elements
inside math elements. But we do now have "fillin", for example. So
it's not a deal-breaker. It could be someone's project, if we want to
give up on Plan A.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/alpine.LRH.2.21.2201251721040.16281%40li375-150.members.linode.com.

Michael Doob

unread,
Jan 26, 2022, 10:05:51 AM1/26/22
to PreTeXt support

Your might try this snippet of code for a test:        <p>sin <m>\sin</m></p>.
One would expect the x-heights to be the same.

Attached is a tiny screen grab of what I get. Looks terrible in my case.
My installation is up to date, and I don't know of any odd implementations.

I actually mentioned this before, but waited for MathJax3 to become
the default. The recommended solution from MathJax is given here:
Since this is a CSS thing, I guess it is in your bailiwick David.
x-heighttest.jpg

David Farmer

unread,
Jan 26, 2022, 10:13:46 AM1/26/22
to PreTeXt support

Fairly often the math seems to small. When I reload, it gets bigger.

Of course, I can't reproduce that right now.

On Wed, 26 Jan 2022, Michael Doob wrote:

>
> Your might try this snippet of code for a test:        <p>sin <m>\sin</m></p>.One would expect the x-heights to be the
> --
> 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/f07fa8b0-fb2f-4cab-a4ab-f244d46575a4n%40googlegroups.com.
>
>

Michael Doob

unread,
Jan 26, 2022, 10:14:16 AM1/26/22
to PreTeXt support
Or a more revealing test: 
sin <m>\text{sin}\sin</m>

Michael Doob

unread,
Jan 26, 2022, 10:23:45 AM1/26/22
to PreTeXt support
Using 
sin <m>\text{sin}\sin</m>
gives me the same (attached) result with different browsers and multiple reloads.
x-heighttest2.jpg

Jeremy Sylvestre

unread,
Jan 27, 2022, 12:16:40 PM1/27/22
to PreTeXt support
Not only the size difference, but notice that the third sin in Michael's screen grab is in a serif font but the other two are sans serif, which to me has always been a bit jarring.

I think you might get better results by choosing a text font that more closely matches the MathJax font. I use the STIX2 font. (https://www.stixfonts.org/)

I hope this won't be a controversial opinion, but I have checked with my institution's accessibility office, and the old advice of "use a sans serif font for screens" is just that --- old advice from a time when low-resolution screens were the norm. Today high-resolution screens are the norm, and serif fonts are better for accessibility because the serifs help words "hang together." 

Here is an example of both \text and \mathrm used on the same line:
\text{rate in} = (15 \; \mathrm{g}/\mathrm{L}) (2 \; \mathrm{L}/\mathrm{s})
in the second math display of Example 4.2.4: Mixing problem.

There might be some small size differences in that line, but definitely not as pronounced as in Michael's screen grab.

Here's another example with a <m>\sin</m> in-line with text:

Cheers,
Jeremy S.

Rob Beezer

unread,
Jan 27, 2022, 12:41:36 PM1/27/22
to pretext...@googlegroups.com
Thanks, Jeremy.

On 1/27/22 9:16 AM, Jeremy Sylvestre wrote:
> I think you might get better results by choosing a text font that more closely
> matches the MathJax font. I use the STIX2 font. (https://www.stixfonts.org/)

I can't see where you do this? And even if I did, do you assume this font is
packaged with the browser (rather than getting our fonts from Google, like we do
now). Have you changed the monospace font?

> I hope this won't be a controversial opinion

Fonts? Uncontroversial? ;-)

One person't opinion (not as BDFL): I like the serifed fonts. How do they do on
a small screen (i.e. mobile)?

Rob

Rob Beezer

unread,
Jan 27, 2022, 12:41:38 PM1/27/22
to pretext...@googlegroups.com
On 1/26/22 7:05 AM, Michael Doob wrote:
> I actually mentioned this before, but waited for MathJax3 to become
> the default. The recommended solution from MathJax is given here:
> https://docs.mathjax.org/en/latest/options/output/index.html#output-options
> Since this is a CSS thing, I guess it is in your bailiwick David.

Thanks, Michael, for your experiments along these lines. Indeed, we have much
of the transition to MJ3 ironed out (I think!). But I'll have to survey the
situation for Jupyter.

Has *anybody* (I'm looking at you, Michael ;-) ) experimented with the scaling
options? Grab a page and hand-edit to suit?

Right now we have a MJ configuration that includes

chtml: {
scale: 0.88,
mtextInheritFont: true
},

That 0.88 scale factor was determined experimentally on Dec 20, 2013, so may
need updating. ;-)

Seems Jeremy is using

chtml: {
mtextInheritFont: true, matchFontHeight: true
},

Rob


Jeremy Sylvestre

unread,
Jan 27, 2022, 1:50:38 PM1/27/22
to pretext...@googlegroups.com
On Thu, Jan 27, 2022 at 10:41 AM Rob Beezer <bee...@ups.edu> wrote:
On 1/27/22 9:16 AM, Jeremy Sylvestre wrote:
> I think you might get better results by choosing a text font that more closely
> matches the MathJax font. I use the STIX2 font. (https://www.stixfonts.org/)

I can't see where you do this?  And even if I did, do you assume this font is
packaged with the browser (rather than getting our fonts from Google, like we do
now).  Have you changed the monospace font?

I still use the html.css.extra stringparam when building, and in that extra css file I have:

@font-face {
  font-family: "STIX Two Text";
  src: url(STIX2Text-Regular.woff2) format("woff2"),
       url(STIX2Text-Regular.woff) format("woff");
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: "STIX Two Text";
  src: url(STIX2Text-Bold.woff2) format("woff2"),
       url(STIX2Text-Bold.woff) format("woff");
  font-weight: bold;
  font-style: normal;
}
@font-face {
  font-family: "STIX Two Text";
  src: url(STIX2Text-Italic.woff2) format("woff2"),
       url(STIX2Text-Italic.woff) format("woff");
  font-weight: normal;
  font-style: italic;
}
@font-face {
  font-family: "STIX Two Text";
  src: url(STIX2Text-BoldItalic.woff2) format("woff2"),
       url(STIX2Text-BoldItalic.woff) format("woff");
  font-weight: bold;
  font-style: italic;
}
body {
  font-family: "STIX Two Text", "Times New Roman", Times, serif;

I have those WOFF/WOFF2 files stored in
and link to them from inside each of the subdirectories under
(Though now that I'm thinking of it, I should just add a fonts/ prefix to each of those src urls and simply link to the fonts directory instead of linking to each font file individually...)

Having visited https://www.stixfonts.org/ for the first time today in quite a while just to write these emails, they've got an old news update that "STIX Two" was added to Google Fonts last summer. Does this mean they could just be pulled from a Google CDN?

Then I've got a sed call in my Makefile to adjust the MathJax chtml configuration in each html file after the pretext build.
 
One person't opinion (not as BDFL): I like the serifed fonts.  How do they do on
a small screen (i.e. mobile)?

They look nice and crisp on mobile to me, and the math is well-integrated into the text. But my opinion on serif vs sans is based entirely on asking one question on fonts at a "Making Your Course Materials More Accessible" workshop here on my campus a few years ago, so there is probably a lot more to the issue than I'm aware of....  ;)

Rob Beezer

unread,
Jan 27, 2022, 2:06:36 PM1/27/22
to pretext...@googlegroups.com
On 1/27/22 10:50 AM, Jeremy Sylvestre wrote:
> I still use the html.css.extra stringparam when building, and in that extra css
> file I have:

Thanks, I didn't think to peek there. More than we'd expect from most
publishers, but perhaps something we could expose to publishers via online
delivery from Google.

STIX:
https://fonts.google.com/specimen/STIX+Two+Text

Seems to be Latin, Cyrrilic and Greek. Likely also usable with xelatex.

Noto (Google)
https://fonts.google.com/noto/fonts

Aiming for many, many alphabets.

Michael Doob

unread,
Jan 28, 2022, 10:35:26 AM1/28/22
to PreTeXt support
According the current MathJax documentation at
the use of the CSS
matchFontHeight: true
is deprecated.

Michael Doob

unread,
Jan 28, 2022, 10:40:06 AM1/28/22
to PreTeXt support
But matchFontHeight: true is available  for for the chtml block.

Rob Beezer

unread,
Jan 29, 2022, 2:16:52 PM1/29/22
to pretext...@googlegroups.com
This thread has been hijacked with concerns about the size of math and text
within mathematics elements. Please try not to distract from author's support
needs with discussions that should probably be on -dev. I'm moving the
typography to a new thread there.

Mark's original problem is different and should be addressed. The
"tex2jax_ignore" and "processMath" classes strike me as the best route to
explore, but I've not yet had a chance to do that myself.

Reply all
Reply to author
Forward
0 new messages