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 000000000..d19efb345 Binary files /dev/null and b/tests/ref/issue-4662-math-mode-language-for-raw.png differ 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)