-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add math styling module #20
base: main
Are you sure you want to change the base?
Conversation
A bit more context: #5 (comment). |
'A'..='Z' => 0x1D3BF, | ||
'a'..='z' => 0x1D3B9, | ||
'Α'..='Ρ' => 0x1D317, | ||
'ϴ' => 0x1D2C5, | ||
'Σ'..='Ω' => 0x1D317, | ||
'∇' => 0x1B4BA, | ||
'α'..='ω' => 0x1D311, | ||
'∂' => 0x1B4D9, | ||
'ϵ' => 0x1D2E7, | ||
'ϑ' => 0x1D30C, | ||
'ϰ' => 0x1D2EE, | ||
'ϕ' => 0x1D30A, | ||
'ϱ' => 0x1D2EF, | ||
'ϖ' => 0x1D30B, | ||
'Ϝ' | 'ϝ' => 0x1D3EE, | ||
'0'..='9' => 0x1D79E, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to somehow use characters (e.g., '𝐀'
) instead of codepoints on the right hand sides here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment the right hand side is just a delta to add to the original codepoint. I can't quite remember why exactly I did it this way instead of just mapping directly to the new codepoint, in which case we could use characters instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The delta allows the pattern to be 'A'..='Z'
instead of 26 individual ones.
Tho I guess it could be inlined to something like
'A'..='Z' => std::char::from_u32((c as u32) - ('A' as u32) + ('𝐀' as u32))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh of course, for some reason I thought 'A'..='Z' => '𝐀'..='𝐙'
would work 😅.
Regarding the implementation, as well as having many |
Regardless of my above comments, @laurmaedje will have to approve moving those functions before we merge this PR. |
The issue I had with something like this is that some of the styles will output multiple characters. I also considered implementing the |
Can you not return
Instead, maybe |
Also, you can implement |
Looks like there's quite a bit more going on here than in typst-layout/src/math/text.rs, e.g. the looped and chancery stuff. Would that somehow be exposed in Typst or is it for completeness? |
Regarding EcoString: I wouldn't add a dependency on it here. Doesn't seem worth it to me. |
src/styling.rs
Outdated
/// assert_eq!(['ⅈ', '\0'], to_style('i', MathStyle::DoubleStruckItalic)); | ||
/// assert_eq!(['𝓴', '\u{fe01}'], to_style('k', MathStyle::RoundhandBold)); | ||
/// ``` | ||
pub fn to_style(c: char, style: MathStyle) -> [char; 2] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [char: 2]
approach where \0
has special meaning seems a bit easy to misuse to me. Maybe it could return a custom iterator type instead? Then to string impl would be trivial to do yourself (s.chars().flat_map(|c| to_style(c, style)).collect()
. I would probably even remove the trait then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree an iterator is much nicer. I've basically mimicked to_uppercase
and ToUppercase
from std
. I also got rid of the trait.
Yes, I plan to expose these in Typst as well. At this point in time it is just for completeness though. For the Arabic ones I plan to add to Variants the functions As for the chancery/roundhand stuff, we'd add |
224e505
to
9bc35ae
Compare
I've changed the
Since I've removed the trait for now, this no longer applies.
I think in my previous reply to this I misunderstood what you were saying, sorry. I've done that now. Also, I was wondering whether to make the I also need to double check Arabic, as for the normal style the math symbols have separate codepoints (unlike latin where the upright serif for math is the same as the standard codepoints), I think. |
Maybe I did not understand the purpose of |
I agree that we shouldn't have |
When you say not having |
I hadn't seen that those are public. Feels slightly duplicate to me with the enum. It's nice to have have in the type that they return just one char. I guess it depends a bit on how you plan to use them in Typst. But, even if we keep separate functions, I think it would make more sense for the ones that can return multiple chars to return |
This PR adds functions and the related infrastructure needed to take a character/string and a style in math (e.g. blackboard-bold, monospace), and return it in styled form. It is implemented under the feature
styling
, which I've added as a default.Moving this to Codex was brought up briefly on Discord, and whilst it doesn't directly fall under "naming Unicode symbols", I think it still fits quite nicely in this crate. I may have jumped the gun a little on this, but it wasn't much work to do. Hopefully this PR starts some more thorough discussion of this idea. I also think that moving this outside of the main typst repo will be an improvement and make it more maintainable.