summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst/src/text/raw.rs16
-rw-r--r--tests/ref/issue-4662-math-mode-language-for-raw.pngbin0 -> 381 bytes
-rw-r--r--tests/suite/text/raw.typ4
3 files changed, 15 insertions, 5 deletions
diff --git a/crates/typst/src/text/raw.rs b/crates/typst/src/text/raw.rs
index e8cb3b99..fcf59c25 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<RawElem> {
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::<Vec<_>>().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 00000000..d19efb34
--- /dev/null
+++ b/tests/ref/issue-4662-math-mode-language-for-raw.png
Binary files differ
diff --git a/tests/suite/text/raw.typ b/tests/suite/text/raw.typ
index 1807e71a..0de34962 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)