pub struct Latex {
formula: String,
size_pt: f32,
position: Option<Position>,
alignment: Alignment,
inline: bool,
}Expand description
A LaTeX formula element that renders mathematical expressions using MicroTeX.
§Examples
Basic usage:
use genpdfi_extended::elements;
let formula = elements::Latex::new(r#"E = mc^2"#, 12.0);With alignment:
use genpdfi_extended::elements;
use genpdfi_extended::Alignment;
let formula = elements::Latex::new(r#"\[E = mc^2\]"#, 14.0)
.with_alignment(Alignment::Center);Fields§
§formula: StringThe LaTeX formula source code
size_pt: f32Font size in “pseudo” points (equivalent to text font size)
position: Option<Position>Optional explicit position (overrides alignment)
alignment: AlignmentHorizontal alignment when not positioned explicitly
inline: boolWhether to render inline (within text flow) or as a block
Implementations§
Source§impl Latex
impl Latex
Sourcepub fn with_position(self, position: Position) -> Self
pub fn with_position(self, position: Position) -> Self
Sets explicit positioning, overriding alignment.
Sourcepub fn with_alignment(self, alignment: Alignment) -> Self
pub fn with_alignment(self, alignment: Alignment) -> Self
Sets horizontal alignment (used when position is not explicitly set).
Sourcepub fn inline(self) -> Self
pub fn inline(self) -> Self
Marks this formula for inline rendering (integrated into text flow).
Sourcefn render_to_scaled_svg(&self) -> Result<String, Error>
fn render_to_scaled_svg(&self) -> Result<String, Error>
Renders the LaTeX formula to SVG using MicroTeX and applies scaling. Uses a global singleton MicroTeX instance (initialized only once).
Trait Implementations§
Source§impl Element for Latex
impl Element for Latex
Source§fn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style,
) -> Result<RenderResult, Error>
fn render( &mut self, context: &Context, area: Area<'_>, style: Style, ) -> Result<RenderResult, Error>
Renders this element to the given area using the given style and font cache. Read more
Source§fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
Draws a frame around this element using the given line style.
Auto Trait Implementations§
impl Freeze for Latex
impl RefUnwindSafe for Latex
impl Send for Latex
impl Sync for Latex
impl Unpin for Latex
impl UnwindSafe for Latex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<E> IntoBoxedElement for Ewhere
E: Element + 'static,
impl<E> IntoBoxedElement for Ewhere
E: Element + 'static,
Source§fn into_boxed_element(self) -> Box<dyn Element>
fn into_boxed_element(self) -> Box<dyn Element>
Creates a boxed element from this element.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
Convert this type into
T, using the provided data to resolve any offsets.