quantity/mag/m

10 views
Skip to first unread message

Alex Jordan

unread,
Aug 15, 2025, 4:40:59 PMAug 15
to prete...@googlegroups.com
Starting a thread about units, mag, etc. Branching off from Jeremy S's request:

Allow
  quantity/mag/m
⟶ Example: π rad
(Not sure if this one would currently render OK.)

Why do we mark up quantities? It's certainly not always convenient to write <quantity><mag>2</mag><unit base="meter"/></quantity> instead of just "2 m".
  • semantic markup so that "m" can be understood unambiguously as "meters", etc.
  • guarantee consistent styling
  • otherwise, how would you get exponents and other math-y unit layout?
  • more?
An existing engine already does all this: the LaTeX siunitx package. Let's use that! OK, and now we will let the tail wag the dog a bit, because if we are going to have the advantages of using this package, we will have to work around its limitations.

So we use siunitx in LaTeX output. HTML to come later. If there is both a magnitude and a unit, the LaTeX is like \SI{2}{\meter}. (That's the old, deprecated syntax. Newer is \qty{2}{\meter}.) This works both in and out of math mode. What if we want a math expression for the magnitude? With an optional parameter, the siunitx still works, still in and out of math mode:  \qty[parse-numbers = false]{\frac{\pi}{2}}{\meter}. So we have "parse-numbers = false" set globally, and we just lose out on the siunitx features that come along with number parsing. For example, we lose out on letting siunitx write a million meters as 1 000 000m (with thin spaces). To avoid having to support the #quantity element inside #m, I would ask that authors:
  • use #quantity when in text content
  • directly use siunitx syntax (which is semantic) when inside math content
Ah, but now HTML... We have MathJax, which does not natively handle siunitx. A former PCC colleague worked on a MJ extension:
It was supposed to be working with MJ3. Untested with MJ4. And presently, it's just his work on GitHub, not distributed in a way we could actually use it.

If we had this, those last two bullets above would work out just as nicely for HTML. Instead, the status quo is that in text content, you don't get to have math in the #mag. (We make one allowance: if you write "\pi" in your #mag, you should get good output. Just on expressions with \pi and no other math structure. So like <mag>\pi/2</mag> can work.) And if you are in math mode in the first place, we are sorry but you must use non-semantic code like <m>2\,\frac{\mathrm{m}}{\mathrm{s}}</m>.

So this is where I've been for years now. Waiting and wanting siunitx in MathJax. And then you would n't really need #m to work inside of #mag. Inside #mag, you would just always write LaTeX math. Even when it's just a number.

I would not get in the way of anyone wanting to do something different then what I've outlined here. Also if I can assist someone taking on that siuntx work for MathJax, let me know how I can help (while understanding that I do not have the javascript chops to actually do it.)


Jeremy Sylvestre

unread,
Aug 17, 2025, 10:37:12 PMAug 17
to prete...@googlegroups.com
Wow, thanks for taking the time to write such a detailed reply. Is any of this knowledge recorded anywhere besides your brain? (The relevant section of the guide is currently empty.) Everywhere else (I think?) math needs to be inside m or me or md, so it's not intuitive for users to guess that they can drop some (limited) LaTeX notation inside mag.

--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-dev/CA%2BR-jrf6-1tgxT%2Bsps-XNi-N05eQ-nQvkbdrFPz0421mg6EitQ%40mail.gmail.com.

Alex Jordan

unread,
Aug 18, 2025, 1:29:59 PMAug 18
to prete...@googlegroups.com
Well, this goes back to 2015. That's one year before the guide was born and two years before "PreTeXt". So it's just been in stasis. I'm not sure we really want to officially set in stone the thing with "\pi", but I guess we should if it's used by projects (we would not want to sweep it out from under them, and making it official would protect against that ever happening). It would hopefully become irrelevant if all mag content were treated as math mode. Maybe we should just do that part now: make #mag assume its text content should be handled in math mode...

Reply all
Reply to author
Forward
0 new messages