Weirdness with \cancel command

71 views
Skip to first unread message

Bruce Yoshiwara

unread,
Jul 25, 2023, 3:19:21 PM7/25/23
to PreTeXt support
In Katherine Yoshiwara’s Core Math textbook, the \cancel command sometimes does not draw the cancel mark through the intended text but is placed just before the intended position.

I’ve created a minimal example with two instances of the issue.
https://byoshiwara.github.io/scratch/section-1.html#note-1

First instance:
Inside the Note, the displayed equation does have a slash through the word “hours” but only partially through the “h” of “hour” in the denominator.

Second instance:
Inside the solution of Example 1.3, the second displayed equation has both slashes occurring just before, rather than through, the word “inches”.


I don’t think the problem is merely a mistake in how \cancel was used in these two instances because the identical markup for the Note works fine if the Note is not preceded by Example 1.1.
https://byoshiwara.github.io/scratch/section-2.html#note-2

And the identical markup for the weird displayed equation of Example 1.3 gives the desired result if that displayed equation is all by itself in the subsection.

Bruce Yoshiwara

Alex Jordan

unread,
Jul 25, 2023, 3:34:25 PM7/25/23
to pretext...@googlegroups.com
When I put in the source for the first example
3 \cancel{\text{hours}} \times \frac{52}{1}
\frac{\text{miles}}{\cancel{\text{hour}}} = \text{156 miles}
into the MathJax demo page
https://www.mathjax.org//#demo
it looks good.

This strikes me as something we have seen before. At some early stage
before it's all rendered, MJ calculates the width of the argument to
\cancel to be 0, and the narrow slash is based on that incorrect
calculation. I'm not sure what the solution is, but it's probably
something about the timing of how this is rendered.
> --
> 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/5e801ee9-f50a-4387-8787-3d1987669706n%40googlegroups.com.

Rob Beezer

unread,
Jul 26, 2023, 3:53:34 AM7/26/23
to pretext...@googlegroups.com
There is finally a beta of MathJax 4 out, as of a few days ago. I'll update the behavior of the flag available for testing and maybe this will fix itself?

Cara Lee

unread,
Jun 25, 2024, 4:12:55 PMJun 25
to PreTeXt support
Hi All,

I'm trying to cancel units when solving a proportion problem and I'm running into a similar issue. Here's my code, mathjax preview, and how it appears in my web preview.

Canceling values is working just fine, but I would also like to be able to cancel a value with units like "300 miles" and I had a similar issue with that.

Any help would be appreciated, thanks!

Cara Lee
Portland Community College

<md>
<mrow>x\amp=\frac{12\text{ gallons}\cdot1300\cancel{\text{miles}}}{300\cancel{\text{miles}}}</mrow>
<mrow>x\amp=52\text{ gallons}</mrow>
</md>
Screen Shot 2024-06-25 at 12.54.39 PM.png

Screen Shot 2024-06-25 at 12.56.09 PM.png

Cara Lee

unread,
Jun 25, 2024, 6:02:23 PMJun 25
to PreTeXt support
To add on a bit more, the pdf doesn't seem to build with the \cancel statements. Here's the line of code and the error message. When I comment out all the statements with cancel it does build.

Here's the whole project if that's helpful: https://github.com/PCCMathSAC/MathInSocietyPCC

<mrow>\frac{\cancel{300}x}{\cancel{300}}\amp=\frac{12\cdot1300}{300}</mrow>

************************************************

Subsection 1.3.10 Solving Proportion Problems with an Algebraic Equation

************************************************

[30]

! Undefined control sequence.

<argument> \cancel 

                   {300}x

l.2619 \end{align*}

This is the html which is great:

Screen Shot 2024-06-25 at 2.55.37 PM.png

Thanks!

Sean Fitzpatrick

unread,
Jun 25, 2024, 7:01:50 PMJun 25
to pretext...@googlegroups.com

Cara Lee

unread,
Jun 25, 2024, 7:25:36 PMJun 25
to PreTeXt support
Excellent, that fixed the pdf!

Is there something I can do for the html version to cancel units? Here's the pdf output, code and html output. Thanks!
Screen Shot 2024-06-25 at 4.22.22 PM.png
<mrow>x\amp=\frac{12\text{ gallons}\cdot1300\cancel{\text{ miles}}}{300\cancel{\text{ miles}}}</mrow>

Screen Shot 2024-06-25 at 4.19.51 PM.png

Alex Jordan

unread,
Jun 25, 2024, 7:36:20 PMJun 25
to pretext...@googlegroups.com
Do you see the same issue across different web browsers?

If a MathJax or browser bug is involved here, a hack-ish thing to try is to do like \text{ miles } (with extra spaces) and see if that changes anything. Also try \mathrm{miles} instead of \text{miles}. If either of these "fix" it for you, that's great in the short term but still apparently there is some bug with MathJax and cancel.

Sean Fitzpatrick

unread,
Jun 25, 2024, 7:42:28 PMJun 25
to pretext...@googlegroups.com

That I'm not sure.

I sort of expected that as long as the cancel package is added in the docinfo, MathJax should do the same thing as LaTeX.

I like using the MathJax live demo page to tinker if something isn't quite right.


Mark Fitch

unread,
Jun 25, 2024, 8:05:23 PMJun 25
to pretext...@googlegroups.com

There is an old thread (link below) in which I ask about the same issue. There was no resolution as far as I can tell (some discussion moved to -dev which I have not tracked down).

https://groups.google.com/g/pretext-support/c/eXh7QtoUi9E/m/A-zHOA47AwAJ

Cara Lee

unread,
Jun 25, 2024, 8:44:01 PMJun 25
to PreTeXt support
Great thought, Alex. It does show up properly in Chrome, before I was using Firefox. 

Screen Shot 2024-06-25 at 5.40.24 PM.png
I'm updating Firefox to see if that fixes it there and I'll look at your other suggestions if needed after that.

Alex Jordan

unread,
Jun 25, 2024, 10:02:48 PMJun 25
to pretext...@googlegroups.com

It's possibly at the intersection of Firefox and MathJax as a bug where MathJax calculates the text as zero width based on Firefox somewhere and draws the slash accordingly.


Cara Lee

unread,
Jul 1, 2024, 3:00:38 PMJul 1
to PreTeXt support
\mathrm{ miles} works, except the space doesn't appear in the pdf. I think this is a good enough fix, unless it makes more sense to prioritize the pdf over Firefox.

Firefox and Chrome:
Screen Shot 2024-07-01 at 11.56.23 AM.png
PDF:
Screen Shot 2024-07-01 at 11.57.29 AM.png

Alex Jordan

unread,
Jul 1, 2024, 3:18:46 PMJul 1
to pretext...@googlegroups.com
The signs point to there being some bug at the intersection of Firefox, MathJax, and PreTeXt. We have control over one of those three things, and ideally we should look into this. Roughly, it seems like we could be loading MathJax in a way that (when Firefox is the browser) misleads MathJax to calculate a certain width as 0, and collapses the cancel slash to be too narrow. (That's an armchair diagnosis without looking at a live example.) If we understood what is happening we might adjust how we load MathJax.

Are you confirming that \mathrm{miles} (using mathrm, but not using an extra space) didn't work? If that works, but does not leave space between the number and the unit, then consider using:
1300\,\mathrm{miles}
which puts a thinspace in place before the "miles" is printed.

Cara Lee

unread,
Jul 16, 2024, 9:35:47 PMJul 16
to PreTeXt support
I'm just getting back to this...

The \, is working in the pdf and html, thanks: 1300\,\mathrm{miles} with or without the space before miles.

Neither \cancel{\mathrm{miles}} nor \cancel{\mathrm{ miles}} gave a space between the number and units in the pdf. I also had some \highlight{} thrown in there as well on other examples.

I'm happy for now, but something to look into if you're able to.

Alex Jordan

unread,
Jul 17, 2024, 12:07:28 AMJul 17
to pretext...@googlegroups.com
Cara, I can meet with you tomorrow to investigate this. We can verify the right things are declared for using the cancel package in the first place. But IIRC earlier you found things worked on one browser but not on another. So there will be an interesting investigation to have there.

Reply all
Reply to author
Forward
0 new messages