latexify/lib.rs
1#![deny(missing_debug_implementations, missing_copy_implementations)]
2#![warn(missing_docs, rustdoc::missing_crate_level_docs)]
3#![doc = include_str!("../readme.md")]
4#![doc(html_logo_url = "https://raw.githubusercontent.com/oovm/shape-rs/dev/projects/images/Trapezohedron.svg")]
5#![doc(html_favicon_url = "https://raw.githubusercontent.com/oovm/shape-rs/dev/projects/images/Trapezohedron.svg")]
6
7use core::fmt::Write;
8
9mod for_3rd;
10mod for_std;
11
12// noinspection SpellCheckingInspection
13/// A trait for LaTeX representation.
14pub trait Latexify {
15 /// The context of LaTeX representation.
16 type Context;
17 /// Write LaTeX representation to the formatter.
18 ///
19 /// # Examples
20 ///
21 /// ```
22 /// use latexify::Latexify;
23 /// # fn main() -> std::fmt::Result {
24 /// let mut buffer = String::new();
25 /// Latexify::fmt(&0, &mut buffer)?;
26 /// println!("{}", buffer); // 0
27 /// //
28 /// # Ok(())
29 /// # }
30 /// ```
31 fn fmt<W: Write>(&self, c: &Self::Context, f: &mut W) -> core::fmt::Result;
32 /// Get the LaTeX string of raw object.
33 ///
34 /// # Examples
35 ///
36 /// ```
37 /// use latexify::Latexify;
38 /// 0.to_latex(); // "0"
39 /// ```
40 fn to_latex(&self, config: &Self::Context) -> String {
41 let mut s = String::new();
42 Latexify::fmt(self, config, &mut s).unwrap();
43 s
44 }
45}