From d06f3f180cd06d11f45c439180027f57287f4f84 Mon Sep 17 00:00:00 2001 From: Jakob Peters Date: Sun, 11 Aug 2024 13:15:30 -0700 Subject: [PATCH] Implement math mode language for `raw` (#4687) --- crates/typst/src/text/raw.rs | 16 +++++++++++----- .../issue-4662-math-mode-language-for-raw.png | Bin 0 -> 381 bytes tests/suite/text/raw.typ | 4 ++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 tests/ref/issue-4662-math-mode-language-for-raw.png diff --git a/crates/typst/src/text/raw.rs b/crates/typst/src/text/raw.rs index e8cb3b997..fcf59c255 100644 --- a/crates/typst/src/text/raw.rs +++ b/crates/typst/src/text/raw.rs @@ -145,9 +145,10 @@ pub struct RawElem { /// The language to syntax-highlight in. /// /// Apart from typical language tags known from Markdown, this supports the - /// `{"typ"}` and `{"typc"}` tags for - /// [Typst markup]($reference/syntax/#markup) and - /// [Typst code]($reference/syntax/#code), respectively. + /// `{"typ"}`, `{"typc"}`, and `{"typm"}` tags for + /// [Typst markup]($reference/syntax/#markup), + /// [Typst code]($reference/syntax/#code), and + /// [Typst math]($reference/syntax/#math), respectively. /// /// ````example /// ```typ @@ -288,7 +289,11 @@ impl RawElem { syntax.file_extensions.iter().map(|s| s.as_str()).collect(), ) }) - .chain([("Typst", vec!["typ"]), ("Typst (code)", vec!["typc"])]) + .chain([ + ("Typst", vec!["typ"]), + ("Typst (code)", vec!["typc"]), + ("Typst (math)", vec!["typm"]), + ]) .collect() } } @@ -344,11 +349,12 @@ impl Packed { let foreground = theme.settings.foreground.unwrap_or(synt::Color::BLACK); let mut seq = vec![]; - if matches!(lang.as_deref(), Some("typ" | "typst" | "typc")) { + if matches!(lang.as_deref(), Some("typ" | "typst" | "typc" | "typm")) { let text = lines.iter().map(|(s, _)| s.clone()).collect::>().join("\n"); let root = match lang.as_deref() { Some("typc") => syntax::parse_code(&text), + Some("typm") => syntax::parse_math(&text), _ => syntax::parse(&text), }; diff --git a/tests/ref/issue-4662-math-mode-language-for-raw.png b/tests/ref/issue-4662-math-mode-language-for-raw.png new file mode 100644 index 0000000000000000000000000000000000000000..d19efb34511cb9b84347c1616fba10f5002dbc56 GIT binary patch literal 381 zcmV-@0fPRCP)fG_zzvbf3>!bEJi~s-the<%eo`tmFP^A bQvY}Z+GPm$`Ovs+00000NkvXXu0mjfxsu%~ literal 0 HcmV?d00001 diff --git a/tests/suite/text/raw.typ b/tests/suite/text/raw.typ index 1807e71ad..0de349629 100644 --- a/tests/suite/text/raw.typ +++ b/tests/suite/text/raw.typ @@ -585,6 +585,10 @@ if true { } ``` +--- issue-4662-math-mode-language-for-raw --- +// Test lang: "typm" syntax highlighting without enclosing dollar signs +#raw("pi^2", lang: "typm") + --- issue-2259-raw-color-overwrite --- // Test that the color of a raw block is not overwritten #show raw: set text(fill: blue)