summaryrefslogtreecommitdiff
path: root/crates/typst-library
diff options
context:
space:
mode:
authorIan Wrzesinski <wrzian@umich.edu>2025-01-22 11:04:01 -0500
committerIan Wrzesinski <wrzian@umich.edu>2025-01-23 16:28:29 -0500
commitfecdc39846959e0dae12e51282bb35d3d417547e (patch)
treeff1188f2424414cf7d44fc2b185fd8f4593bb3bc /crates/typst-library
parentc47b71b4350434a73734789ebde1374b791dc88e (diff)
Use SymbolElem in more places and add `char` cast for content
Diffstat (limited to 'crates/typst-library')
-rw-r--r--crates/typst-library/src/loading/csv.rs16
-rw-r--r--crates/typst-library/src/math/lr.rs9
-rw-r--r--crates/typst-library/src/math/op.rs5
3 files changed, 11 insertions, 19 deletions
diff --git a/crates/typst-library/src/loading/csv.rs b/crates/typst-library/src/loading/csv.rs
index e5dabfaa..1cf656ae 100644
--- a/crates/typst-library/src/loading/csv.rs
+++ b/crates/typst-library/src/loading/csv.rs
@@ -136,18 +136,10 @@ impl Default for Delimiter {
cast! {
Delimiter,
self => self.0.into_value(),
- v: EcoString => {
- let mut chars = v.chars();
- let first = chars.next().ok_or("delimiter must not be empty")?;
- if chars.next().is_some() {
- bail!("delimiter must be a single character");
- }
-
- if !first.is_ascii() {
- bail!("delimiter must be an ASCII character");
- }
-
- Self(first)
+ c: char => if c.is_ascii() {
+ Self(c)
+ } else {
+ bail!("delimiter must be an ASCII character")
},
}
diff --git a/crates/typst-library/src/math/lr.rs b/crates/typst-library/src/math/lr.rs
index 965f5351..7558717a 100644
--- a/crates/typst-library/src/math/lr.rs
+++ b/crates/typst-library/src/math/lr.rs
@@ -1,7 +1,6 @@
-use crate::foundations::{elem, func, Content, NativeElement};
+use crate::foundations::{elem, func, Content, NativeElement, SymbolElem};
use crate::layout::{Length, Rel};
use crate::math::Mathy;
-use crate::text::TextElem;
/// Scales delimiters.
///
@@ -19,7 +18,7 @@ pub struct LrElem {
#[parse(
let mut arguments = args.all::<Content>()?.into_iter();
let mut body = arguments.next().unwrap_or_default();
- arguments.for_each(|arg| body += TextElem::packed(',') + arg);
+ arguments.for_each(|arg| body += SymbolElem::packed(',') + arg);
body
)]
pub body: Content,
@@ -125,9 +124,9 @@ fn delimited(
) -> Content {
let span = body.span();
let mut elem = LrElem::new(Content::sequence([
- TextElem::packed(left),
+ SymbolElem::packed(left),
body,
- TextElem::packed(right),
+ SymbolElem::packed(right),
]));
// Push size only if size is provided
if let Some(size) = size {
diff --git a/crates/typst-library/src/math/op.rs b/crates/typst-library/src/math/op.rs
index 5b3f58be..55696e53 100644
--- a/crates/typst-library/src/math/op.rs
+++ b/crates/typst-library/src/math/op.rs
@@ -1,6 +1,6 @@
use ecow::EcoString;
-use crate::foundations::{elem, Content, NativeElement, Scope};
+use crate::foundations::{elem, Content, NativeElement, Scope, SymbolElem};
use crate::layout::HElem;
use crate::math::{upright, Mathy, THIN};
use crate::text::TextElem;
@@ -38,6 +38,7 @@ macro_rules! ops {
let operator = EcoString::from(ops!(@name $name $(: $value)?));
math.define(
stringify!($name),
+ // Latex also uses their equivalent of `TextElem` here.
OpElem::new(TextElem::new(operator).into())
.with_limits(ops!(@limit $($tts)*))
.pack()
@@ -46,7 +47,7 @@ macro_rules! ops {
let dif = |d| {
HElem::new(THIN.into()).with_weak(true).pack()
- + upright(TextElem::packed(d))
+ + upright(SymbolElem::packed(d))
};
math.define("dif", dif('d'));
math.define("Dif", dif('D'));