mirror of
https://github.com/typst/typst
synced 2025-05-15 09:35:28 +08:00
42 lines
960 B
Rust
42 lines
960 B
Rust
use super::*;
|
|
|
|
/// Forced use of a certain math class.
|
|
///
|
|
/// This is useful to treat certain symbols as if they were of a different
|
|
/// class, e.g. to make a symbol behave like a relation.
|
|
///
|
|
/// ## Example { #example }
|
|
/// ```example
|
|
/// #let loves = math.class(
|
|
/// "relation",
|
|
/// sym.suit.heart,
|
|
/// )
|
|
///
|
|
/// $x loves y and y loves 5$
|
|
/// ```
|
|
///
|
|
/// Display: Class
|
|
/// Category: math
|
|
#[element(LayoutMath)]
|
|
pub struct ClassElem {
|
|
/// The class to apply to the content.
|
|
#[required]
|
|
pub class: MathClass,
|
|
|
|
/// The content to which the class is applied.
|
|
#[required]
|
|
pub body: Content,
|
|
}
|
|
|
|
impl LayoutMath for ClassElem {
|
|
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
|
|
ctx.style(ctx.style.with_class(self.class()));
|
|
let mut fragment = ctx.layout_fragment(&self.body())?;
|
|
ctx.unstyle();
|
|
|
|
fragment.set_class(self.class());
|
|
ctx.push(fragment);
|
|
Ok(())
|
|
}
|
|
}
|