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

Add STIX Two to the list of fonts #347

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions latex2mmlc/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub enum TextTransform {
// Tailed,
}

#[inline]
fn add_offset(c: char, offset: u32) -> char {
debug_assert!(
char::from_u32(c as u32 + offset).is_some(),
Expand Down Expand Up @@ -184,36 +185,25 @@ impl TextTransform {
_ => c,
},
TextTransform::Fraktur => match c {
'A'..='B' => add_offset(c, 0x1D4C3),
'D'..='G' => add_offset(c, 0x1D4C3),
'A'..='B' | 'D'..='G' | 'J'..='Q' | 'S'..='Y' => add_offset(c, 0x1D4C3),
'H'..='I' => add_offset(c, 0x20C4),
'J'..='Q' => add_offset(c, 0x1D4C3),
'S'..='Y' => add_offset(c, 0x1D4C3),
'a'..='z' => add_offset(c, 0x1D4BD),
'C' => 'ℭ',
'R' => 'ℜ',
'Z' => 'ℨ',
_ => c,
},
TextTransform::Script => match c {
'C'..='D' => add_offset(c, 0x1D45B),
'A' | 'C'..='D' | 'G' | 'J'..='K' | 'N'..='Q' | 'S'..='Z' => add_offset(c, 0x1D45B),
'E'..='F' => add_offset(c, 0x20EB),
'J'..='K' => add_offset(c, 0x1D45B),
'N'..='Q' => add_offset(c, 0x1D45B),
'S'..='Z' => add_offset(c, 0x1D45B),
'a'..='d' => add_offset(c, 0x1D455),
'h'..='n' => add_offset(c, 0x1D455),
'p'..='z' => add_offset(c, 0x1D455),
'A' => '𝒜',
'a'..='d' | 'f' | 'h'..='n' | 'p'..='z' => add_offset(c, 0x1D455),
'B' => 'ℬ',
'G' => '𝒢',
'H' => 'ℋ',
'I' => 'ℐ',
'L' => 'ℒ',
'M' => 'ℳ',
'R' => 'ℛ',
'e' => 'ℯ',
'f' => '𝒻',
'g' => 'ℊ',
'o' => 'ℴ',
_ => c,
Expand Down Expand Up @@ -274,25 +264,20 @@ impl TextTransform {
_ => c,
},
TextTransform::DoubleStruck => match c {
'A'..='B' => add_offset(c, 0x1D4F7),
'D'..='G' => add_offset(c, 0x1D4F7),
'I'..='M' => add_offset(c, 0x1D4F7),
'A'..='B' | 'D'..='G' | 'I'..='M' | 'O' | 'S'..='Y' => add_offset(c, 0x1D4F7),
'P'..='Q' => add_offset(c, 0x20C9),
'S'..='Y' => add_offset(c, 0x1D4F7),
'a'..='z' => add_offset(c, 0x1D4F1),
'0'..='9' => add_offset(c, 0x1D7A8),
'C' => 'ℂ',
'H' => 'ℍ',
'N' => 'ℕ',
'O' => '𝕆',
'R' => 'ℝ',
'Z' => 'ℤ',
_ => c,
},
TextTransform::Italic => match c {
'A'..='Z' => add_offset(c, 0x1D3F3),
'a'..='g' => add_offset(c, 0x1D3ED),
'i'..='z' => add_offset(c, 0x1D3ED),
'a'..='g' | 'i'..='z' => add_offset(c, 0x1D3ED),
'Α'..='Ω' => add_offset(c, 0x1D351),
'α'..='ω' => add_offset(c, 0x1D34B),
'h' => 'ℎ',
Expand Down
Binary file added playground/STIXTwoMath-Regular.woff2
Binary file not shown.
7 changes: 4 additions & 3 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ <h3>LaTeX input:</h3>
<h3>Math font:</h3>
<div class="options">
<select name="math-font" id="math-font">
<option value="latin-modern">Latin Modern Math</option>
<option value="libertinus">Libertinus Math</option>
<option value="Latin Modern Math">Latin Modern Math</option>
<option value="Libertinus Math">Libertinus Math</option>
<option value="STIX Two Math">STIX Two Math</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -113,7 +114,7 @@ <h2 id="what-is-this">What is this?</h2>
by your browser. For example, try this input:
</p>
<pre class="copyable"><code>p\big(z;f(\theta)\big) =
\sum_{i=1}^K \gamma_i \mathcal{N}\big(z; f_i(\theta), \Sigma_i\big),
\sum_{i=1}^K \gamma_i\,\mathcal{N}\big(z; f_i(\theta), \Sigma_i\big),
\quad\text{where }\sum_{i=1}^K \gamma_i = 1</code></pre>
<p>
Recent versions of all the major browsers support MathML
Expand Down
14 changes: 8 additions & 6 deletions playground/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ document.addEventListener('DOMContentLoaded', () => {
const fontSelect = document.getElementById('math-font');
const styleElement = document.getElementById('math-font-style');

const fontMap = {
'latin-modern': 'Latin Modern Math',
'libertinus': 'Libertinus Math'
const fontFeaturesMap = {
'Libertinus Math': 'ss09',
'STIX Two Math': 'ss04',
};

// Update the style rule when selection changes
fontSelect.addEventListener('change', function() {
styleElement.textContent = `math { font-family: "${fontMap[this.value]}", math; }`;
const featureSettings = fontFeaturesMap[this.value]
? `font-feature-settings: "${fontFeaturesMap[this.value]}";`
: '';
styleElement.textContent = `math { font-family: "${this.value}", math; ${featureSettings} }`;
});
});

8 changes: 7 additions & 1 deletion playground/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ body {

@font-face {
font-family: Libertinus Math;
src: url('./LibertinusMath-Regular.woff2') format('woff2'),
src: url('./LibertinusMath-Regular.woff2') format('woff2');
font-display: swap;
}

@font-face {
font-family: STIX Two Math;
src: url('./STIXTwoMath-Regular.woff2') format('woff2');
font-display: swap;
}

Expand Down