Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare different methods of entering primes in LaTeX Math #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

michal-h21
Copy link
Contributor

As we discussed on Mastodon, here is a change that uses the Siunitx package to typeset the geographic dimensions.

@michal-h21
Copy link
Contributor Author

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.

@alerque
Copy link
Owner

alerque commented Jan 5, 2024

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. typst/typst#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?

@alerque
Copy link
Owner

alerque commented Jan 5, 2024

Also on the coordinates topic: the difference between XeLaTeX Unicode handling and the \ang{} command is interesting!

@alerque alerque changed the title Use siunitx to typeset the geographic dimensions Compare different methods of entering primes in LaTeX Math Jan 5, 2024
@alerque
Copy link
Owner

alerque commented Jan 5, 2024

On deeper review a detail I missed:

  • For STIX-MATH, all inputs create the same output.
  • Using the unicode-math package and Libertinus Math, the f' creates the same output as f^{\prime}, which I didn't expect. That suggests I might be wrong about LaTeX's expectations on how a prime should be encoded.

@khaledhosny
Copy link

khaledhosny commented Jan 16, 2024

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.

@Omikhleia
Copy link
Contributor

Omikhleia commented Feb 5, 2025

@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?

@khaledhosny
Copy link

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.

@Omikhleia
Copy link
Contributor

Omikhleia commented Feb 5, 2025

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

@Omikhleia
Copy link
Contributor

@khaledhosny

Any feature other than ssty wouldn't work by default.

From Unicode Charts for STIX Two Math Regular

image

We could ask the contributors why they included this stylistic set. Er... Wait... 🤣 Gotcha!

@michal-h21
Copy link
Contributor Author

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

obrazek

@Omikhleia
Copy link
Contributor

Omikhleia commented Feb 5, 2025

@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}

image

With STIX Two however see discussion above. Maybe try with temporarily set math.font.script.feature to ss04...

@michal-h21
Copy link
Contributor Author

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.

@Omikhleia
Copy link
Contributor

Omikhleia commented Feb 5, 2025

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

image

@khaledhosny
Copy link

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.

@khaledhosny
Copy link

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

Actually it has ssty feature for optical variants, but not for primes as they don’t need it like I said above.

@khaledhosny
Copy link

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.

@Omikhleia
Copy link
Contributor

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' and a^\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).

@michal-h21
Copy link
Contributor Author

@Omikhleia I've updated the SILE example, is it correct now?

@@ -15,13 +15,19 @@
\setmathfont{STIX Two Math}
\[\mathlarger{\begin{aligned}
f(x) & = a\prime + b\dprime + c\trprime \\
f\prime(x) & = x^{2} + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this one (lacking the ^ is removed, why do we keep the preceding line? Reading the original description of the test for all languages, I'd tend to guess it expected proper user input (so with a^\prime etc. for the "long" variant, and a' etc. for the short-hand variant), both following The TeXBook. Do we also want to show the output for an incorrect user input? If so, we need both lines, and to explain the issue...

f\prime(x) & = x^{2} + 1
f(x) & = a^{\prime} + b^{\dprime} + c^{\trprime} \\
f(x) & = a' + b'' + c''' \\
f\prime(x) & = x^{2} + 1\\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be this one a ^\prime?

f(x) & = a^{\prime} + b^{\dprime} + c^{\trprime} \\
f(x) & = a' + b'' + c''' \\
f\prime(x) & = x^{2} + 1\\
f'(x) & = x^{2} + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remarks as for the STIX example.

@khaledhosny
Copy link

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.

f(x) &= a\prime + b\dprime + c\trprime \\
f\prime(x) &= x^2 + 1
f(x) &= a^\prime + b^\dprime + c^\trprime \\
f^\prime(x) &= x^2 + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct to me, but for full parity with xelatex, we should also see the short-hand variant.

@@ -1,25 +1,21 @@
\begin[papersize=a7]{document}
\nofolios
\neverindent
\font[family=Libertinus Serif,size=12pt]
Copy link
Contributor

@Omikhleia Omikhleia Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep that line: Llet's have the non-math font as Libertinus Serif, I am not mistaken LaTeX's \usepackage{libertinus} does both things in on package (picking Libertinus as main text font and Libertinus Math as math font). Bare SILE needs more lines here (setting the main text font, loading the math support and setting the math font and its size explicitly) for a similar ouyput.

\use[module=packages.math]
\set[parameter=math.font.size,value=16]
\set[parameter=math.font.family,value=Libertinus Math]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Erm. So we are no longer testing STIX Two Math? We ought, and the output won't be correct in 0.15.9 but will eventually be fixed. No need to remove the case.

f(x) &= a\prime + b\dprime + c\trprime \\
f\prime(x) &= x^2 + 1
f(x) &= a' + b'' + c''' \\
f'(x) &= x^2 + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my misunderstanding in the previous comment, you split the shorthand version. Can we stick closer to the xelatex version?

@Omikhleia
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants