Skip to content

Add math.accent support for flac and dtls OpenType features - #5202

Merged
laurmaedje merged 3 commits into
typst:mainfrom
mkorje:math-accents-dtls-flac
Oct 30, 2024
Merged

laurmaedje merged 3 commits into
typst:mainfrom
mkorje:math-accents-dtls-flac

Conversation

@mkorje

@mkorje mkorje commented Oct 14, 2024 •

Copy link
Copy Markdown
Collaborator

Closes #5201.

While implementing this, I also changed the logic for the ssty_table to use the GlyphwiseSubsts<'a> struct. This saves some code duplication and is more consistent anyways. Also, from the spec, it could be implemented as a single substitution. So this change also ensures ssty variants will work in fonts where this is the case.

The only font I can find that supports the flac OpenType feature is Cambria Math. I tested it locally, and it is all working. Though it (my probably dodgy copy) had a bug I needed to manually fix so the horizontal variants of some of the flac variants would be used. See the example below.
test

--- math-accent-flattened ---
// Test flattened accent glyph variants.
#show math.equation: set text(font: "Cambria Math")
$hat(a) hat(A)$
$tilde(w) tilde(W)$
$grave(i) grave(j)$
$grave(I) grave(J)$

EDIT: Also fixes #2860.

@mkorje

mkorje commented Oct 14, 2024 •

Copy link
Copy Markdown
Collaborator Author

The changes made making ssty_table use the GlyphwiseSubsts<'a> struct fixes #2860 as well. As per #2860 (comment), Libertinus Math is such a font where the ssty lookup is a single substitution lookup.

Could add a test for this if Libertinus Math is added to https://github.com/typst/typst-dev-assets.

In the future we should pass single chars in math through the shaper.

Comment thread crates/typst/src/math/accent.rs Resolved
Re: 'ℜ',
Im: 'ℑ',
dotless: [i: '𝚤', j: '𝚥'],
dotless: [i: 'ı', j: 'ȷ'],

@mkorje mkorje Oct 18, 2024 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This change makes this character act more in line with other Latin characters in math. (Some) Single characters in math are converted to their italic math variants, so the dotless i and j should as well. See the example below.

$ 𝑗 upright(𝑗) italic(𝑗) bb(𝑗) med
  𝚤 upright(𝚤) italic(𝚤) bb(𝚤) \
  j upright(j) italic(j) bb(j) med
  ı upright(ı) italic(ı) bb(ı) $

test

Comment thread crates/typst/src/math/accent.rs Outdated
Comment on lines +119 to +121
// Try replace a glyph with its dotless variant.
if let MathFragment::Glyph(ref mut glyph) = &mut base {
glyph.make_dotless_form(ctx)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(Moving part of the old conversation here.) Are there any situations where you'd want an accent above i or j with the dot still? If this is basically never, it'd be much nicer to automatically replace them with their dotless variants.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Some orthographies keep the dots of the i and j when accented, but I don’t know if there are equivalent math notations. There is at least one question on tex.stackexchange where this was desired https://tex.stackexchange.com/questions/181384/diacritics-above-dotted-i-i-with-tittle (though since you need to explicitly use \imath and \jmath to drop the dot in LaTeX, it is unlikely to have many questions asking about how to keep the dots).

@mkorje mkorje left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've made the changes so that $bb(dotless.i)$ (along with all the other variants) work as expected, following @khaledhosny comments to switch if the font has the dtls OpenType feature.

See the example below.

$ dotless.i dotless.j med
  upright(dotless.i) upright(dotless.j) \
  sans(dotless.i) sans(dotless.j) med
  bold(dotless.i) bold(dotless.j) \
  bb(dotless.i) bb(dotless.j) med
  cal(dotless.i) cal(dotless.j) \
  frak(dotless.i) frak(dotless.j) med
  mono(dotless.i) mono(dotless.j) \ 

  bold(frak(dotless.i)) upright(sans(dotless.j)) med
  italic(bb(dotless.i)) frak(sans(dotless.j)) $

test

However, the only "issue" is that if the font does not have a dotless variant of the glyph, it will sometimes fall back to the glyph with the dot (this depends on the order in which variants and styles are applied). This feels in some ways like bad and unexpected behaviour, but at the same time I can see this as being fairly reasonable. I think it'd also increase the code's complexity a fair bit to check whether the glyph exists in the dtls alphabet beforehand.

Because we're not exactly switching the alphabets, and only attempt to replace a glyph if it has a value in the dtls table, we get the glyph with the dot sometimes instead of a 'tofu'. Should we instead forcibly apply the switch, and so end up with a missing glyph in these situations?

@mkorje
mkorje force-pushed the math-accents-dtls-flac branch from 67bf88d to 9108e92 Compare October 28, 2024 05:36
Comment thread crates/typst-layout/src/math/accent.rs Resolved
Comment thread crates/typst-layout/src/math/accent.rs Resolved
@mkorje
mkorje force-pushed the math-accents-dtls-flac branch from 9108e92 to 5e040ee Compare October 29, 2024 03:47
@laurmaedje
laurmaedje added this pull request to the merge queue Oct 30, 2024
@laurmaedje

Copy link
Copy Markdown
Member

Thank you!

I think it'd also increase the code's complexity a fair bit to check whether the glyph exists in the dtls alphabet beforehand.

Let's not do that (at least for now) then.

Merged via the queue into typst:main with commit f85faf9 Oct 30, 2024
@mkorje
mkorje deleted the math-accents-dtls-flac branch October 31, 2024 00:05
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
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.

Use flac and dtls OpenType features in math.accent Prime symbol broken with Libertinus Math

4 participants