Skip to content
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
40 changes: 29 additions & 11 deletions .github/workflows/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,42 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: "Install harfbuzz"
run: sudo apt-get update && sudo apt-get install -y libharfbuzz-bin
- name: "Subset fonts"
run: make subset
- name: Setup Pages
uses: actions/configure-pages@v5
uses: actions/configure-pages@v6
- name: "Install Rust toolchain"
run: rustup target add wasm32-unknown-unknown
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: qmaru/wasm-pack-action@v0.5.0
- uses: Swatinem/rust-cache@v2
- name: "Run wasm-pack"
- name: "Get wasm-bindgen version"
id: wasm-bindgen-version
run: |
VERSION=$(grep -A 1 'name = "wasm-bindgen"' Cargo.lock | grep version | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version=$VERSION"

- name: "Install wasm-bindgen-cli"
uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli@${{ steps.wasm-bindgen-version.outputs.version }}
- name: "Install wasm-opt"
uses: jaxxstorm/action-install-gh-release@v2.1.0
with:
repo: WebAssembly/binaryen
tag: version_128
binaries-location: binaryen-version_128/bin
chmod: 0755
- name: "Generate playground"
run: |
wasm-pack build --target web --out-dir ../../playground/pkg --no-typescript --no-pack crates/math-core-wasm
- name: "Create comparison page"
make playground
- name: "Generate comparison page"
run: |
make comparison
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
uses: actions/upload-pages-artifact@v4
with:
path: "./playground"

Expand All @@ -57,4 +75,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v5
33 changes: 24 additions & 9 deletions .github/workflows/wasm_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,54 @@ jobs:
name: "cargo test (wasm)"
steps:
- name: "Checkout PR branch"
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
path: pr-branch
- name: "Checkout base branch"
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
ref: ${{ github.base_ref }}
path: base-branch
- name: "Install Rust toolchain"
run: rustup target add wasm32-unknown-unknown
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: qmaru/wasm-pack-action@v0.5.0
- uses: Swatinem/rust-cache@v2
with:
workspaces: "./pr-branch -> target"
- name: "Get wasm-bindgen version"
id: wasm-bindgen-version
working-directory: ./pr-branch
run: |
VERSION=$(grep -A 1 'name = "wasm-bindgen"' Cargo.lock | grep version | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version=$VERSION"

- name: "Install wasm-bindgen-cli"
uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli@${{ steps.wasm-bindgen-version.outputs.version }}
- name: "Install wasm-opt"
uses: jaxxstorm/action-install-gh-release@v2.1.0
with:
repo: WebAssembly/binaryen
tag: version_128
binaries-location: binaryen-version_128/bin
chmod: 0755
- name: "Get wasm size on PR"
working-directory: ./pr-branch
run: |
wasm-pack build --target web --out-dir ../../playground/pkg --no-typescript --no-pack crates/math-core-wasm
make playground
SIZE_BYTES=$(stat -c %s playground/pkg/math_core_wasm_bg.wasm)
echo "Wasm size on PR: $SIZE_BYTES bytes"
echo "PR_SIZE_BYTES=$SIZE_BYTES" >> $GITHUB_ENV
- name: "Get wasm size on base branch"
working-directory: ./base-branch
run: |
wasm-pack build --target web --out-dir ../../playground/pkg --no-typescript --no-pack crates/math-core-wasm
make playground
SIZE_BYTES=$(stat -c %s playground/pkg/math_core_wasm_bg.wasm)
echo "Wasm size on base: $SIZE_BYTES bytes"
echo "BASE_SIZE_BYTES=$SIZE_BYTES" >> $GITHUB_ENV
- name: "Comment on PR with WASM sizes"
uses: actions/github-script@v7
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ node_modules/

pkg/
/playground/comparison.html
/scripts/all_symbols.txt
/playground/fonts/NewCMMath-Book-prime-roundhand-vec-subset.woff2
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ testpage:

comparison:
cat docs/comparison.html | cargo run --bin mathcore -- -c docs/mathcore.toml --inline-del ₮ --block-del ₮₮ --continue-on-error - > playground/comparison.html

subset: allsymbols
hb-subset \
--output-file=playground/fonts/NewCMMath-Book-prime-roundhand-vec-subset.otf \
--text-file=scripts/all_symbols.txt \
--layout-features=ssty,kern,aalt \
--desubroutinize \
playground/fonts/NewCMMath-Book-prime-roundhand-vec.otf

allsymbols:
python3 scripts/generate_symbol_document.py
6 changes: 3 additions & 3 deletions crates/math-core/examples/browser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ fn main() {
<style>
@font-face {{
font-family: "NewComputerModernMath Book";
src: url('./NewCMMath-Book-prime-roundhand-vec.woff2') format('woff2');
src: url('./fonts/NewCMMath-Book-prime-roundhand-vec.woff2') format('woff2');
font-display: swap;
}}
@font-face {{
font-family: "NewComputerModern Book";
src: url("./NewCM10-Book.woff2") format("woff2");
src: url("./fonts/NewCM10-Book.woff2") format("woff2");
font-display: swap;
}}
@font-face {{
font-family: "NewComputerModern Mono";
src: url("./NewCMMono10-Book.woff2") format("woff2");
src: url("./fonts/NewCMMono10-Book.woff2") format("woff2");
font-display: swap;
}}
math {{
Expand Down
26 changes: 13 additions & 13 deletions crates/math-core/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ static FUNCTIONS: phf::Set<&'static str> = phf::phf_set!(
);

static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
" " => MathOrTextMode(&NonBreakingSpace, '\u{A0}'),
" " => MathOrTextMode(&NonBreakingSpace, symbol::NO_BREAK_SPACE),
"#" => Letter(symbol::NUMBER_SIGN, Mode::MathOrText),
"$" => Letter(symbol::DOLLAR_SIGN, Mode::MathOrText),
"%" => Letter(symbol::PERCENT_SIGN, Mode::MathOrText),
"&" => OpAmpersand,
"'" => TextMode(TextToken::Accent(symbol::COMBINING_ACUTE_ACCENT)),
"," => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(3.0)), '\u{2009}'),
"," => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(3.0)), symbol::THIN_SPACE),
"." => TextMode(TextToken::Accent(symbol::COMBINING_DOT_ABOVE)),
":" => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(4.0)), '\u{205F}'),
";" => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(5.0)), '\u{2004}'),
":" => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(4.0)), symbol::MEDIUM_MATHEMATICAL_SPACE),
";" => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(5.0)), symbol::THREE_PER_EM_SPACE),
"=" => TextMode(TextToken::Accent(symbol::COMBINING_MACRON)),
">" => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(4.0)), '\u{205F}'),
">" => MathOrTextMode(&Space(LatexUnit::Mu.length_with_unit(4.0)), symbol::MEDIUM_MATHEMATICAL_SPACE),
"AA" => TextMode(TextToken::Letter('Å')),
"AE" => TextMode(TextToken::Letter('Æ')),
"Alpha" => UprightLetter(symbol::GREEK_CAPITAL_LETTER_ALPHA),
Expand Down Expand Up @@ -223,7 +223,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"cdots" => CustomCmd(0, &predefined::CDOTS),
"cfrac" => Frac(Some(FracAttr::CFracStyle)),
"check" => Accent(symbol::CARON, true, OpAttrs::STRETCHY_FALSE),
"checkmark" => Letter('✓', Mode::Math),
"checkmark" => Letter(symbol::CHECK_MARK, Mode::Math),
"chi" => Letter(symbol::GREEK_SMALL_LETTER_CHI, Mode::Math),
"circ" => ForceBinaryOp(symbol::RING_OPERATOR.as_op()),
"circeq" => Relation(symbol::RING_EQUAL_TO),
Expand Down Expand Up @@ -319,7 +319,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"fallingdotseq" => Relation(symbol::APPROXIMATELY_EQUAL_TO_OR_THE_IMAGE_OF),
"fcmp" => Relation(symbol::Z_NOTATION_SCHEMA_COMPOSITION),
"fint" => Op(symbol::INTEGRAL_AVERAGE_WITH_SLASH),
"flat" => Letter('♭', Mode::Math),
"flat" => Letter(symbol::MUSIC_FLAT_SIGN, Mode::Math),
"forall" => Ord(symbol::FOR_ALL),
"frac" => Frac(None),
"frak" => Transform(MathVariant::Transform(TextTransform::Fraktur)),
Expand Down Expand Up @@ -466,7 +466,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"mathrm" => Transform(MathVariant::Normal),
"mathscr" => Transform(MathVariant::Transform(TextTransform::ScriptRoundhand)),
"mathsf" => Transform(MathVariant::Transform(TextTransform::SansSerif)),
"mathsterling" => Letter('£', Mode::Math),
"mathsterling" => Letter(symbol::POUND_SIGN, Mode::Math),
"mathstrut" => HardcodedMathML(r#"<mpadded width="0" style="visibility:hidden"><mo stretchy="false">(</mo></mpadded>"#),
"mathtt" => Transform(MathVariant::Transform(TextTransform::Monospace)),
"max" => PseudoOperatorLimits("max"),
Expand All @@ -491,7 +491,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"nVdash" => Relation(symbol::DOES_NOT_FORCE),
"nabla" => UprightLetter(symbol::NABLA),
"natnums" => Letter(symbol::DOUBLE_STRUCK_CAPITAL_N, Mode::Math),
"natural" => Letter('♮', Mode::Math),
"natural" => Letter(symbol::MUSIC_NATURAL_SIGN, Mode::Math),
"ne" => Relation(symbol::NOT_EQUAL_TO),
"nearrow" => Relation(symbol::NORTH_EAST_ARROW),
"neg" => Ord(symbol::NOT_SIGN),
Expand Down Expand Up @@ -565,7 +565,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"plusmn" => BinaryOp(symbol::PLUS_MINUS_SIGN),
"pm" => BinaryOp(symbol::PLUS_MINUS_SIGN),
"pmod" => CustomCmd(1, &predefined::PMOD),
"pounds" => Letter('£', Mode::Math),
"pounds" => Letter(symbol::POUND_SIGN, Mode::Math),
"prec" => Relation(symbol::PRECEDES),
"precapprox" => Relation(symbol::PRECEDES_ABOVE_ALMOST_EQUAL_TO),
"preccurlyeq" => Relation(symbol::PRECEDES_OR_EQUAL_TO),
Expand Down Expand Up @@ -611,7 +611,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"rightthreetimes" => ForceBinaryOp(symbol::RIGHT_SEMIDIRECT_PRODUCT.as_op()),
"risingdotseq" => Relation(symbol::IMAGE_OF_OR_APPROXIMATELY_EQUAL_TO),
"rm" => TransformSwitch(MathVariant::Normal),
"rq" => Letter('’', Mode::MathOrText),
"rq" => Letter(symbol::RIGHT_SINGLE_QUOTATION_MARK, Mode::MathOrText),
"rrangle" => Close(symbol::Z_NOTATION_RIGHT_BINDING_BRACKET), // from "stix"
"rrbracket" => Close(symbol::MATHEMATICAL_RIGHT_WHITE_SQUARE_BRACKET),
"rrparenthesis" => Close(symbol::Z_NOTATION_RIGHT_IMAGE_BRACKET),
Expand All @@ -624,7 +624,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"searrow" => Relation(symbol::SOUTH_EAST_ARROW),
"setminus" => BinaryOp(symbol::SET_MINUS),
"sf" => TransformSwitch(MathVariant::Transform(TextTransform::SansSerif)),
"sharp" => Letter('♯', Mode::Math),
"sharp" => Letter(symbol::MUSIC_SHARP_SIGN, Mode::Math),
"sigma" => Letter(symbol::GREEK_SMALL_LETTER_SIGMA, Mode::Math),
"sim" => Relation(symbol::TILDE_OPERATOR),
"simeq" => Relation(symbol::ASYMPTOTICALLY_EQUAL_TO),
Expand Down Expand Up @@ -684,7 +684,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"textsf" => Text(Some(HtmlTextStyle::SansSerif)),
"textstyle" => Style(Style::Text),
"texttt" => Text(Some(HtmlTextStyle::Typewriter)),
"textyen" => TextMode(TextToken::Letter('¥')),
"textyen" => TextMode(TextToken::Letter(symbol::YEN_SIGN)),
"tfrac" => Frac(Some(FracAttr::DisplayStyleFalse)),
"th" => TextMode(TextToken::Letter(symbol::LATIN_SMALL_LETTER_THORN)),
"therefore" => Relation(symbol::THEREFORE),
Expand Down
6 changes: 3 additions & 3 deletions crates/math-core/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ impl<'config, 'source> Lexer<'config, 'source> {
LatexErrKind::DisallowedChar(ch),
)));
}
' ' => Token::Letter('\u{A0}', Mode::MathOrText),
'"' => Token::Letter('”', Mode::MathOrText),
' ' => Token::Letter(symbol::NO_BREAK_SPACE, Mode::MathOrText),
'"' => Token::Letter(symbol::RIGHT_DOUBLE_QUOTATION_MARK, Mode::MathOrText),
'#' => {
if let Some(num) = &mut self.parse_cmd_args {
if let Some(next) = self.peek.1
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<'config, 'source> Lexer<'config, 'source> {
']' => Token::SquareBracketClose,
'^' => Token::Circumflex,
'_' => Token::Underscore,
'`' => Token::Letter('‘', Mode::MathOrText),
'`' => Token::Letter(symbol::LEFT_SINGLE_QUOTATION_MARK, Mode::MathOrText),
'{' => Token::GroupBegin,
'}' => Token::GroupEnd,
'~' => Token::NonBreakingSpace,
Expand Down
28 changes: 28 additions & 0 deletions crates/mathml-renderer/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ pub const TILDE: OrdLike = OrdLike::new('~', OrdCategory::I);
//
// Unicode Block: Latin-1 Supplement
//
pub const NO_BREAK_SPACE: char = '\u{A0}';
// pub const INVERTED_EXCLAMATION_MARK: char = '¡';
// pub const CENT_SIGN: char = '¢';
pub const POUND_SIGN: char = '£';

pub const YEN_SIGN: char = '¥';

pub const SECTION_SIGN: char = '§';
pub const DIAERESIS: MathMLOperator = MathMLOperator('¨');
pub const COPYRIGHT_SIGN: char = '©';
Expand Down Expand Up @@ -364,10 +371,23 @@ pub const GREEK_REVERSED_LUNATE_EPSILON_SYMBOL: char = '϶';
//
// Unicode Block: General Punctuation
//
pub const THREE_PER_EM_SPACE: char = '\u{2004}';

pub const THIN_SPACE: char = '\u{2009}';

pub const DOUBLE_VERTICAL_LINE: OrdLike = OrdLike::new('‖', OrdCategory::FGandForceDefault); // should actually be FG

pub const DAGGER: char = '†';
pub const DOUBLE_DAGGER: char = '‡';
// pub const DOUBLE_LOW_LINE: char = '‗';
pub const LEFT_SINGLE_QUOTATION_MARK: char = '‘';
pub const RIGHT_SINGLE_QUOTATION_MARK: char = '’';
// pub const SINGLE_LOW_9_QUOTATION_MARK: char = '‚';
// pub const SINGLE_HIGH_REVERSED_9_QUOTATION_MARK: char = '‛';
// pub const LEFT_DOUBLE_QUOTATION_MARK: char = '“';
pub const RIGHT_DOUBLE_QUOTATION_MARK: char = '”';
// pub const DOUBLE_LOW_9_QUOTATION_MARK: char = '„';
// pub const DOUBLE_HIGH_REVERSED_9_QUOTATION_MARK: char = '‟';

pub const HORIZONTAL_ELLIPSIS: char = '…';
pub const PRIME: OrdLike = OrdLike::new('′', OrdCategory::E);
Expand All @@ -386,6 +406,8 @@ pub const OVERLINE: MathMLOperator = MathMLOperator('‾');

pub const QUADRUPLE_PRIME: OrdLike = OrdLike::new('⁗', OrdCategory::E);

pub const MEDIUM_MATHEMATICAL_SPACE: char = '\u{205F}';

pub const INVISIBLE_SEPARATOR: OrdLike = OrdLike::new('\u{2063}', OrdCategory::K);

//
Expand Down Expand Up @@ -885,9 +907,15 @@ pub const BLACK_CLUB_SUIT: char = '♣';
// pub const BLACK_DIAMOND_SUIT: char = '♦';
// pub const WHITE_CLUB_SUIT: char = '♧';

pub const MUSIC_FLAT_SIGN: char = '♭';
pub const MUSIC_NATURAL_SIGN: char = '♮';
pub const MUSIC_SHARP_SIGN: char = '♯';

//
// Unicode Block: Dingbats
//
pub const CHECK_MARK: char = '✓';

pub const MALTESE_CROSS: char = '✠';

//
Expand Down
Loading
Loading