Compare different methods of entering primes in LaTeX Math
As we discussed on Mastodon, here is a change that uses the Siunitx package to typeset the geographic dimensions.
I've also compared different methods of handling of primes in math, because I think it is better to use ' instead of \prime (which should be in fact ^{\prime}). You can see that using of just \prime, \dprime and \trprime leads to big differences in the end result.
Thanks.
The Use of siunitx here is certainly more idiomatic here. In fact I already cherry picked that commit, so the only thing left here is about math mode primes.
I'm not so sure what to do here. I am not convinced you are correct about this:
which should be in fact
^{\prime}
This seems like something subjective you are doing because you prefer the output, not because it is the correct math typesetting expectation. In fact I suspect from what other people have said about this and elsewhere that this is objectively wrong and just a work around for a different visial preference than the math font designer intended. In particular the use of STIX TWO and Libertinus Math here were specifically to highlight different ways of encoding the prime, and the latter might actually be wrong. As such hacking around it is hiding the difference between typesetting engines I was trying to highlight.
c.f. https://github.com/typst/typst/issues/2860
It might be good to add a comparison between ' and \prime though, I might rework this a little bit to accomplish that. I'm not sure what is supposed to be the "right" or "more idiomatic of LaTeX way" for that, do you have docs to point to on that topic?
Also on the coordinates topic: the difference between XeLaTeX Unicode handling and the \ang{} command is interesting!
On deeper review a detail I missed:
- For STIX-MATH, all inputs create the same output.
- Using the
unicode-mathpackage and Libertinus Math, thef'creates the same output asf^{\prime}, which I didn't expect. That suggests I might be wrong about LaTeX's expectations on how a prime should be encoded.
In TeX math, ' is essentially a short-hand for ^{\prime}, so both should result in the same output. This is because in Computer Modern, \prime is a full size glyph that sets on the baseline that is designed with the expectation that it will be scaled down and positioned by math layout engine.
This is contrary to how the prime ′ (U+2032) symbol is expected, as its glyph supposed to be in the appropriate size and raised above baseline. To work around this, OpenType math fonts usually will have a U+2032 glyph like any other font, and provide alternate glyphs in the ssty feature that are scaled up and set on the baseline. This way when it is used as superscript, the layout engine will apply the ssty feature and then scale it down and raise it like any other math superscript.
@michal-h21 @alerque Yes the examples on polytype for primes are currently wrong, both for LaTeX and SILE.
f\prime (etc.) in these examples should be either f' or f^\prime (both being equivalent, the former is the "short-hand" convenience version).
And as noted by @khaledhosny, the engine is assumed to apply the ssty font feature in these case, rendering the intended glyphs. That's what also does SILE now (since v0.15.7)...
... Well theoretically, as not all existing math fonts seem to implement it, but some have other features that can do the trick. For the record, I've devoted a section to this topic in SILE and the Hydra of Maths. Showcase & Critical Assessment 2024, Part II §2.1 "Primes gone wild".
Can the PR be possibly completed with the right syntax both for TeX and SILE?
Well theoretically, as not all existing math fonts seem to implement it, but some have other features that can do the trick.
Which fonts does this? Any feature other than ssty wouldn't work by default.
Which fonts does this? Any feature other than ssty wouldn't work by default.
This is discussed in the above-mentioned booklet.
IIRC, Asana uses salt I have not tested them all, and not necessarily in latest versions. Also at the time of writing, I did not succeed using ssty with (some version of) STIX Two and SILE, but ss04 worked. Also discussed there is Libertinus Math not having the quadruple prime covered by ssty (I reported that fact on the Libertinus repository).
@khaledhosny
Any feature other than
sstywouldn't work by default.
From Unicode Charts for STIX Two Math Regular
We could ask the contributors why they included this stylistic set. Er... Wait... :rofl: Gotcha!
@Omikhleia what is the correct handling of primes in Sile? I've tried to modify the example in this way:
\begin[papersize=a7]{document}
\nofolios
\neverindent
\font[family=Libertinus Serif,size=12pt]
\use[module=packages.math]
\set[parameter=math.font.size,value=16]
Math mode manners:
\set[parameter=math.font.family,value=STIX Two Math]
\begin[mode=display]{math}
\table[columnalign=right left]{
f(x) &= a\prime + b\dprime + c\trprime \\
f(x) &= a^\prime + b^\dprime + c^\trprime \\
f(x) &= a' + b'' + c''' \\
f\prime(x) &= x^2 + 1
}
\end{math}
\set[parameter=math.font.family,value=Libertinus Math]
\begin[mode=display]{math}
\table[columnalign=right left]{
f(x) &= a\prime + b\dprime + c\trprime \\
f\prime(x) &= x^2 + 1
}
\end{math}
Prose poses problems:
\medskip
\begin{raggedright}
60*10'16"N 24*55'52"E (plain)\break
60°10′16″N 24°55′52″E (unicode)\break
60°10′16″N 24°55′52″E (idiomatic)
\end{raggedright}
\end{document}
And from the rendering, it seems that the correct result is done using a\prime, which is different to TeX.
@Omikhleia what is the correct handling of primes in Sile?
Same as TeX now -- Using SILE 0.15.9 (I am on SILE v0.15.9 (LuaJIT 2.1.1731601260) [Rust]) and a simplified example:
\begin[papersize=a7]{document}
\nofolios
\neverindent
\use[module=packages.math]
\set[parameter=math.font.size,value=16]
\set[parameter=math.font.family,value=Libertinus Math]
\begin[mode=display]{math}
\table[columnalign=right left]{
f(x) &= a^\prime + b^\dprime + c^\trprime \\
f^\prime(x) &= x^2 + 1
}
\end{math}
\begin[mode=display]{math}
\table[columnalign=right left]{
f(x) &= a' + b'' + c''' \\
f'(x) &= x^2 + 1
}
\end{math}
\end{document}
With STIX Two however see discussion above. Maybe try with temporarily set math.font.script.feature to ss04...
I am using SILE v0.14.17 (Lua 5.4), packed in Fedora. Maybe it is too old, because I get this error when I try to set the math script:
! Undefined setting 'math.font.script.feature' at sile.sil:11:1: in \set[parameter="math.font.script.feature",value="ss04"]
But I must admit that I don't know anything about Sile, so maybe I am doing something wrong.
@michal-h21
I am using
SILE v0.14.17 (Lua 5.4), packed in Fedora. Maybe it is too old, because I get this error when I try to set the math script
Far too old. There has been a huge number of fixes on the math engine between 0.15.6 and 0.15.8. This is also all explained in the above-mentioned booklet (TL;DR I suppose... EDIT: It's sad, 'cause I think its a fairly interesting reading, once one is accustomed to my bad sense of humor and my ramblings ;) )
@khaledhosny STIX Two Math (2.13 b171) support for ssty also seems broken with LibreOffice, unless I'm totally missing something (EDIT: So it's not a SILE-or-whatever-only issue, very likely. Advice is welcome on how to interpret the situation.)
The STIX Two Math font has ssty feature only for math script. LibreOffice does not allow setting Math script AFAIK, but you can test with hb-shape/hb-view:
$ hb-shape STIXTwoMath-Regular.otf ′ --features="ssty=1"
[minute=0+296]
$ hb-shape STIXTwoMath-Regular.otf ′ --features="ssty=1" --script=math
[minute.ssty=0+356]
Math layout engine are expected to set script to math, and that is what LaTeX (unicode-math package) does, and I think other implementations as well. May be that is what SILE is missing.
Asana Math does not have an ssty feature at all because it does not have optical variants and its primes are designed like legacy TeX fonts (big and set on the baseline).
In short, ssty feature should be set to 1 for first script level, and 2 for all other script level unconditionally. Fonts that don’t have ssty feature either don’t need it for broken, but math layout engine does not need to be concerned about this.
Asana Math does not have an
sstyfeature at all because it does not have optical variants and its primes are designed like legacy TeX fonts (big and set on the baseline).
Actually it has ssty feature for optical variants, but not for primes as they don’t need it like I said above.
Re math script from https://learn.microsoft.com/en-us/typography/opentype/spec/math#opentype-layout-tags-used-with-the-math-table:
'math' Script tag to be used for features in math layout. The only language system supported with this tag is the default language system.
Well I guess we have to wait for SILE 0.15.10 for the fix to pass then... But to go back on tracks with the original discussion, the expectations are:
- That
a'anda^\prime(etc.) are equivalent - And both are the correct way to encode primes (etc.) in LaTeX, and also in SILE TeX-like math alike (the latter thriving at respecting a decent subset of the LaTeX math syntax, under the principle of least astonishment).
@Omikhleia I've updated the SILE example, is it correct now?
You might want to show _{\prime} as well, since IIRC allowing such use is why CM fonts have full size prime glyph setting on the baseline.
@Omikhleia I've updated the SILE example, is it correct now?
I've annotated the PR (both for the TeX and SILE cases). But it will be hard for you to check the SILE case without a recent version. Hmm. Let's see how close we get, I'll try to jump in for another review.