Add math stdlib with formulas/plots and polish the docs view.

Ship Num/Formula runtime, bilingual math libs, SVG plots with axes/grid, and view UX for collapsible folders plus centered plots.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-05 11:30:47 +08:00
1 parent a53ebb65ee
commit dcd0cdb8f7
40 files changed
+3553 -276

No files matched your search

+57
View File
@@ -543,6 +543,12 @@ fn view_output_writes_html() {
assert!(index.contains("#ffffff") || index.contains("--surface: #ffffff"));
assert!(index.contains("nav-toggle"));
assert!(!index.contains("Run with input"), "static export should omit live stdin form");
let page = std::fs::read_to_string(dir.join("pages").join("hello.mq.md.html")).unwrap();
assert!(page.contains("katex.min.css"), "view layout should load KaTeX");
assert!(
!page.contains("name=\"stdin\""),
"hello has no input; no preset form"
);
assert!(dir.join("pages").join("hello.mq.md.html").exists());
}
@@ -579,6 +585,57 @@ fn lib_net_encode() {
assert_out("tests/lib/net-encode.mq.md", "a+b");
}
#[test]
fn lib_math_formula() {
assert_out(
"tests/lib/math-formula.mq.md",
"formula\n2*x\n[-1.4142135624, 1.4142135624]\n7",
);
}
#[test]
fn lib_math_formula_chain() {
assert_out(
"tests/lib/math-formula-chain.mq.md",
"formula\n3*2*x\n12",
);
}
#[test]
fn lib_math_random() {
assert_out("tests/lib/math-random.mq.md", "4\n7\n4");
}
#[test]
fn lib_math_zh_num() {
assert_out("tests/lib/数学-数值.mq.md", "num\n0");
}
#[test]
fn lib_math_plot() {
let path = "tests/lib/math-plot.mq.md";
let (code, stdout, stderr) = run(&["run", path]);
assert_eq!(code, 0, "{path} stderr={stderr}");
assert!(
stdout.lines().next() == Some("text"),
"{path} stdout={stdout}"
);
assert!(
stdout.contains("plot:"),
"{path} missing plot: line in {stdout}"
);
let _ = std::fs::remove_file("tests/lib/math-plot-plot-1.svg");
}
#[test]
fn bytecode_lib_math_formula() {
assert_out_backend(
"tests/lib/math-formula.mq.md",
"bytecode",
"formula\n2*x\n[-1.4142135624, 1.4142135624]\n7",
);
}
#[test]
fn bytecode_lib_json() {
assert_out_backend(
+25
View File
@@ -0,0 +1,25 @@
---
title: math formula chain
> lib/math.mq.md
---
# main
`f` =
$$
x^3
$$
*`df` = > diff formula=`f` var=x *
*`ty` = > type `df` *
> print text=`ty`
*`df2` = > diff formula=`df` var=x *
> print text=`df2`
*`y` = > eval formula=`df` var=x value=2 *
> print text=`y`
+27
View File
@@ -0,0 +1,27 @@
---
title: math formula pipeline
> lib/math.mq.md
---
# main
`f` =
$$
x^2 - 2
$$
*`ty` = > type `f` *
> print text=`ty`
*`df` = > diff formula=`f` var=x *
> print text=`df`
*`roots` = > solve formula=`f` var=x *
> print text=`roots`
*`y` = > eval formula=`f` var=x value=3 *
> print text=`y`
+17
View File
@@ -0,0 +1,17 @@
---
title: math plot svg
> lib/math.mq.md
---
# main
`f` =
$$
x^2
$$
*`svg` = > plot formula=`f` var=x min=-2 max=2 *
*`ok` = > type `svg` *
> print text=`ok`
+22
View File
@@ -0,0 +1,22 @@
---
title: math random seed
> lib/math.mq.md
---
# main
> seed value=42
*`a` = > random_int min=1 max=10 *
*`b` = > random_int min=1 max=10 *
> seed value=42
*`c` = > random_int min=1 max=10 *
> print text=`a`
> print text=`b`
> print text=`c`
+16
View File
@@ -0,0 +1,16 @@
---
title: math num + zh
> lib/数学.mq.md
---
# main
*`p` = > 圆周率 *
*`t` = > type `p` *
> print text=`t`
*`s` = > 正弦 value=0 *
> print text=`s`