math-core 0.6.2__tar.gz → 0.6.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. {math_core-0.6.2 → math_core-0.6.4}/Cargo.lock +9 -9
  2. {math_core-0.6.2 → math_core-0.6.4}/Cargo.toml +2 -2
  3. {math_core-0.6.2 → math_core-0.6.4}/PKG-INFO +1 -1
  4. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/Cargo.toml +2 -2
  5. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/README.md +4 -0
  6. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/character_class.rs +36 -6
  7. math_core-0.6.4/crates/math-core/src/color_defs.rs +98 -0
  8. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/commands.rs +696 -37
  9. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/environments.rs +47 -4
  10. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/error.rs +83 -20
  11. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/lexer.rs +22 -31
  12. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/lib.rs +1 -0
  13. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/parser.rs +1012 -325
  14. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/predefined.rs +33 -2
  15. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/specifications.rs +15 -3
  16. math_core-0.6.4/crates/math-core/src/split_on_ascii.rs +44 -0
  17. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/text_parser.rs +106 -12
  18. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/token.rs +93 -14
  19. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/token_queue.rs +29 -0
  20. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/tests/conversion_test.rs +222 -4
  21. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/tests/error_test.rs +34 -4
  22. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/Cargo.toml +1 -1
  23. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/arena.rs +19 -3
  24. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/ast.rs +188 -78
  25. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/attribute.rs +40 -8
  26. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/lib.rs +2 -2
  27. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/symbol.rs +334 -189
  28. math_core-0.6.2/crates/math-core/src/color_defs.rs +0 -100
  29. {math_core-0.6.2 → math_core-0.6.4}/LICENSE +0 -0
  30. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/examples/browser_test.rs +0 -0
  31. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/examples/equations.rs +0 -0
  32. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/examples/minijinja.rs +0 -0
  33. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/atof.rs +0 -0
  34. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/src/html_utils.rs +0 -0
  35. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/tests/custom_cmd_test.rs +0 -0
  36. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core/tests/wiki_test.rs +0 -0
  37. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core-python/Cargo.toml +0 -0
  38. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core-python/README.md +0 -0
  39. {math_core-0.6.2 → math_core-0.6.4}/crates/math-core-python/src/lib.rs +0 -0
  40. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/README.md +0 -0
  41. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/fmt.rs +0 -0
  42. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/itoa.rs +0 -0
  43. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/length.rs +0 -0
  44. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/super_char.rs +0 -0
  45. {math_core-0.6.2 → math_core-0.6.4}/crates/mathml-renderer/src/table.rs +0 -0
  46. {math_core-0.6.2 → math_core-0.6.4}/pyproject.toml +0 -0
  47. {math_core-0.6.2 → math_core-0.6.4}/python/math_core/__init__.py +0 -0
  48. {math_core-0.6.2 → math_core-0.6.4}/python/math_core/_math_core_rust.pyi +0 -0
  49. {math_core-0.6.2 → math_core-0.6.4}/python/math_core/py.typed +0 -0
@@ -90,9 +90,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
90
90
 
91
91
  [[package]]
92
92
  name = "bitflags"
93
- version = "2.11.1"
93
+ version = "2.13.0"
94
94
  source = "registry+https://github.com/rust-lang/crates.io-index"
95
- checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
95
+ checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
96
96
  dependencies = [
97
97
  "serde_core",
98
98
  ]
@@ -358,7 +358,7 @@ dependencies = [
358
358
 
359
359
  [[package]]
360
360
  name = "math-core"
361
- version = "0.6.2"
361
+ version = "0.6.4"
362
362
  dependencies = [
363
363
  "ariadne",
364
364
  "insta",
@@ -378,7 +378,7 @@ dependencies = [
378
378
 
379
379
  [[package]]
380
380
  name = "math-core-cli"
381
- version = "0.6.2"
381
+ version = "0.6.4"
382
382
  dependencies = [
383
383
  "ariadne",
384
384
  "clap",
@@ -391,7 +391,7 @@ dependencies = [
391
391
 
392
392
  [[package]]
393
393
  name = "math-core-python"
394
- version = "0.6.2"
394
+ version = "0.6.4"
395
395
  dependencies = [
396
396
  "ariadne",
397
397
  "math-core",
@@ -401,7 +401,7 @@ dependencies = [
401
401
 
402
402
  [[package]]
403
403
  name = "math-core-renderer-internal"
404
- version = "0.6.2"
404
+ version = "0.6.4"
405
405
  dependencies = [
406
406
  "bitflags",
407
407
  "dtoa",
@@ -414,7 +414,7 @@ dependencies = [
414
414
 
415
415
  [[package]]
416
416
  name = "math-core-wasm"
417
- version = "0.6.2"
417
+ version = "0.6.4"
418
418
  dependencies = [
419
419
  "ariadne",
420
420
  "js-sys",
@@ -427,9 +427,9 @@ dependencies = [
427
427
 
428
428
  [[package]]
429
429
  name = "memchr"
430
- version = "2.8.0"
430
+ version = "2.8.1"
431
431
  source = "registry+https://github.com/rust-lang/crates.io-index"
432
- checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
432
+ checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
433
433
 
434
434
  [[package]]
435
435
  name = "memo-map"
@@ -7,13 +7,13 @@ resolver = "2"
7
7
  edition = "2024"
8
8
  rust-version = "1.91"
9
9
  license = "MIT"
10
- version = "0.6.2"
10
+ version = "0.6.4"
11
11
  repository = "https://github.com/tmke8/math-core"
12
12
 
13
13
  [workspace.dependencies]
14
14
  rustc-hash = "2.1.2"
15
15
  serde = { version = "1.0.228", features = ["derive"] }
16
- memchr = "2.8.0"
16
+ memchr = "2.8.1"
17
17
  strum = "0.28.0"
18
18
  strum_macros = "0.28.0"
19
19
  static_assertions = "1.1.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: math-core
3
- Version: 0.6.2
3
+ Version: 0.6.4
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -19,7 +19,7 @@ categories = ["science"]
19
19
  exclude = ["/src/snapshots", "/tests/snapshots"]
20
20
 
21
21
  [dependencies]
22
- mathml-renderer = { path = "../mathml-renderer", package = "math-core-renderer-internal", version = "0.6.2" }
22
+ mathml-renderer = { path = "../mathml-renderer", package = "math-core-renderer-internal", version = "0.6.4" }
23
23
  serde = { workspace = true, optional = true }
24
24
  serde-tuple-vec-map = { version = "1.0.1", optional = true }
25
25
  phf = { version = "0.13.1", features = ["macros"] }
@@ -32,7 +32,7 @@ ariadne = { workspace = true, optional = true }
32
32
 
33
33
  [dev-dependencies]
34
34
  math-core = { path = ".", features = ["serde", "ariadne"] }
35
- mathml-renderer = { path = "../mathml-renderer", package = "math-core-renderer-internal", version = "0.6.2", features = ["serde"] }
35
+ mathml-renderer = { path = "../mathml-renderer", package = "math-core-renderer-internal", version = "0.6.4", features = ["serde"] }
36
36
  insta = { version = "1.47.2", features = ["default", "ron"] }
37
37
  regex = "1.12.3"
38
38
  minijinja = "2.20.0"
@@ -234,6 +234,10 @@ Note: at the time of this writing (June 2025), none of the following libraries r
234
234
  - [Temml](https://github.com/ronkok/Temml): a fork of [KaTeX](https://katex.org/) which removed the HTML output of KaTeX and kept only on the MathML output. *Temml* produces much higher quality MathML output than KaTeX. The differences to this library are:
235
235
  - *Temml* is written in JavaScript, with all the pros and cons that result from that
236
236
  - *Temml* is much more willing to work around browser bugs to get consistent rendering, with specific CSS hacks for each browser; *math-core* does this to a much lesser degree. Even if you don’t include the CSS from `mathfixes.css`, math-core’s output will look mostly good.
237
+ - [LaTeXML](https://dlmf.nist.gov/LaTeXML/): a suite of LaTeX-to-XML converters, including `latexmlmath`, which generates MathML from standalone math snippets
238
+ - *LaTeXML* attempts to implement *all* of LaTeX, not just the math typesetting
239
+ - *LaTeXML* is used by arXiv to publish accessible HTML versions of their reports, most of which were originally targetted for LaTeX itself
240
+ - *LaTeXML* is written in Perl 5, with all the pros and cons that result from that
237
241
 
238
242
  ## Acknowledgments
239
243
  This code was originally forked from https://github.com/osanshouo/latex2mathml. The basic architecture of a lexer and a parser remains, but all the details have drastically changed and the supported portion of LaTeX commands has drastically increased.
@@ -1,10 +1,12 @@
1
1
  use mathml_renderer::{
2
2
  arena::Arena,
3
- ast::Node,
4
- attribute::{MathSpacing, OpAttrs, RowAttr, Style, TextTransform},
3
+ ast::{Node, RowAttrs},
4
+ attribute::{MathSpacing, OpAttrs, Style, TextTransform},
5
5
  symbol::{self, MathMLOperator, OrdCategory, OrdLike, Rel, RelCategory},
6
6
  };
7
7
 
8
+ use crate::token::ForceStretchy;
9
+
8
10
  #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
9
11
  pub enum Class {
10
12
  /// `mathord`
@@ -47,6 +49,7 @@ pub enum MathVariant {
47
49
  #[derive(Clone, Copy, Debug, PartialEq, Eq)]
48
50
  pub enum Stretchy {
49
51
  /// The operator is always stretchy (e.g. `(`, `)`).
52
+ /// (Or, it's [`ForceStretchy::Pretend`].)
50
53
  Always = 1,
51
54
  /// The operator is only stretchy as a pre- or postfix operator (e.g. `|`).
52
55
  PrePostfix,
@@ -91,13 +94,19 @@ impl StretchableOp {
91
94
  /// operator isn't stretchable.
92
95
  pub const fn from_ord(ord: OrdLike) -> Option<Self> {
93
96
  let (stretchy, spacing) = match ord.category() {
94
- OrdCategory::F | OrdCategory::G => (Stretchy::Always, DelimiterSpacing::Zero),
97
+ OrdCategory::F | OrdCategory::G | OrdCategory::FG => {
98
+ (Stretchy::Always, DelimiterSpacing::Zero)
99
+ }
95
100
  OrdCategory::FGandForceDefault => {
96
101
  (Stretchy::PrePostfix, DelimiterSpacing::InfixRelation)
97
102
  }
98
103
  OrdCategory::K => (Stretchy::Never, DelimiterSpacing::Zero),
99
104
  OrdCategory::KButUsedToBeB => (Stretchy::Never, DelimiterSpacing::Other),
100
- OrdCategory::D | OrdCategory::E | OrdCategory::I | OrdCategory::IK => {
105
+ OrdCategory::D
106
+ | OrdCategory::E
107
+ | OrdCategory::DE
108
+ | OrdCategory::I
109
+ | OrdCategory::IK => {
101
110
  return None;
102
111
  }
103
112
  };
@@ -117,7 +126,25 @@ impl StretchableOp {
117
126
  stretchy: Stretchy::AlwaysAsymmetric,
118
127
  spacing: DelimiterSpacing::Relation,
119
128
  }),
120
- RelCategory::Default => None,
129
+ RelCategory::Default | RelCategory::DandForceDefault => None,
130
+ }
131
+ }
132
+
133
+ /// Creates a `StretchableOp` from a [`ForceStretchy`] if it's stretchable.
134
+ /// Used with `ForceOpen`/`ForceClose`.
135
+ pub const fn from_force_stretchy(op: MathMLOperator, stretch: ForceStretchy) -> Option<Self> {
136
+ match stretch {
137
+ ForceStretchy::Yes => Some(StretchableOp {
138
+ op,
139
+ stretchy: Stretchy::Never,
140
+ spacing: DelimiterSpacing::Zero,
141
+ }),
142
+ ForceStretchy::Pretend => Some(StretchableOp {
143
+ op,
144
+ stretchy: Stretchy::Always,
145
+ spacing: DelimiterSpacing::Zero,
146
+ }),
147
+ ForceStretchy::No => None,
121
148
  }
122
149
  }
123
150
  }
@@ -172,7 +199,10 @@ pub fn fenced<'arena>(
172
199
  let nodes = arena.push_slice(&content);
173
200
  Node::Row {
174
201
  nodes,
175
- attr: style.map(RowAttr::Style),
202
+ attrs: RowAttrs {
203
+ style,
204
+ ..RowAttrs::DEFAULT
205
+ },
176
206
  }
177
207
  }
178
208
 
@@ -0,0 +1,98 @@
1
+ static COLORS: phf::Map<&'static str, (u8, u8, u8)> = phf::phf_map! {
2
+ // RGB
3
+ "red" => (255, 0, 0),
4
+ "green" => (3, 255, 0),
5
+ "blue" => (0, 0, 255),
6
+ // CMYK (sRGB approximation)
7
+ "cyan" => (0, 185, 242),
8
+ "magenta" => (251, 49, 153),
9
+ "yellow" => (255, 235, 61),
10
+ "black" => (0, 0, 0),
11
+ // Grayscale
12
+ "gray" => (128, 128, 128),
13
+ "white" => (255, 255, 255),
14
+ "darkgray" => (64, 64, 64),
15
+ "lightgray" => (191, 191, 191),
16
+ // Other
17
+ "brown" => (191, 128, 63),
18
+ "lime" => (191, 255, 4),
19
+ "olive" => (159, 140, 24),
20
+ "orange" => (255, 128, 1),
21
+ "pink" => (255, 191, 191),
22
+ "purple" => (191, 1, 64),
23
+ "teal" => (0, 128, 128),
24
+ "violet" => (128, 0, 128),
25
+ // dvipsnames
26
+ "Apricot" => (255, 184, 130),
27
+ "Aquamarine" => (28, 191, 193),
28
+ "Bittersweet" => (208, 76, 23),
29
+ "Black" => (44, 46, 53),
30
+ "Blue" => (16, 38, 148),
31
+ "BlueGreen" => (20, 188, 188),
32
+ "BlueViolet" => (45, 52, 151),
33
+ "BrickRed" => (196, 49, 25),
34
+ "Brown" => (119, 34, 6),
35
+ "BurntOrange" => (255, 142, 39),
36
+ "CadetBlue" => (99, 114, 157),
37
+ "CarnationPink" => (252, 129, 188),
38
+ "Cerulean" => (0, 173, 231),
39
+ "CornflowerBlue" => (72, 187, 232),
40
+ "Cyan" => (0, 185, 242),
41
+ "Dandelion" => (255, 185, 76),
42
+ "DarkOrchid" => (158, 80, 143),
43
+ "Emerald" => (0, 177, 160),
44
+ "ForestGreen" => (18, 159, 87),
45
+ "Fuchsia" => (131, 55, 148),
46
+ "Goldenrod" => (255, 219, 87),
47
+ "Gray" => (155, 156, 159),
48
+ "Green" => (0, 171, 79),
49
+ "GreenYellow" => (225, 229, 123),
50
+ "JungleGreen" => (0, 177, 157),
51
+ "Lavender" => (253, 160, 204),
52
+ "LimeGreen" => (136, 201, 70),
53
+ "Magenta" => (251, 49, 153),
54
+ "Mahogany" => (180, 50, 30),
55
+ "Maroon" => (186, 49, 50),
56
+ "Melon" => (255, 157, 123),
57
+ "MidnightBlue" => (0, 104, 150),
58
+ "Mulberry" => (168, 62, 158),
59
+ "NavyBlue" => (8, 111, 189),
60
+ "OliveGreen" => (63, 126, 49),
61
+ "Orange" => (255, 124, 55),
62
+ "OrangeRed" => (255, 46, 88),
63
+ "Orchid" => (172, 114, 185),
64
+ "Peach" => (255, 147, 88),
65
+ "Periwinkle" => (106, 122, 191),
66
+ "PineGreen" => (5, 141, 116),
67
+ "Plum" => (135, 41, 150),
68
+ "ProcessBlue" => (0, 187, 242),
69
+ "Purple" => (143, 69, 163),
70
+ "RawSienna" => (158, 60, 14),
71
+ "Red" => (255, 46, 23),
72
+ "RedOrange" => (255, 92, 49),
73
+ "RedViolet" => (168, 44, 114),
74
+ "Rhodamine" => (252, 88, 170),
75
+ "RoyalBlue" => (0, 115, 192),
76
+ "RoyalPurple" => (72, 57, 158),
77
+ "RubineRed" => (253, 48, 136),
78
+ "Salmon" => (255, 144, 138),
79
+ "SeaGreen" => (71, 196, 160),
80
+ "Sepia" => (93, 22, 1),
81
+ "SkyBlue" => (80, 207, 226),
82
+ "SpringGreen" => (196, 220, 110),
83
+ "Tan" => (225, 157, 117),
84
+ "TealBlue" => (17, 184, 184),
85
+ "Thistle" => (222, 132, 191),
86
+ "Turquoise" => (16, 190, 210),
87
+ "Violet" => (61, 60, 159),
88
+ "VioletRed" => (252, 90, 171),
89
+ "White" => (255, 255, 255),
90
+ "WildStrawberry" => (255, 55, 105),
91
+ "Yellow" => (255, 235, 61),
92
+ "YellowGreen" => (146, 208, 116),
93
+ "YellowOrange" => (255, 159, 43),
94
+ };
95
+
96
+ pub fn get_color(name: &str) -> Option<(u8, u8, u8)> {
97
+ COLORS.get(name).copied()
98
+ }