From 367bade807fe3505a58da0ebb54c7e684e0ff56e Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 4 Aug 2020 17:50:30 +0200 Subject: [PATCH] Add ToMathML trait and implementation for greek letters --- src/format/mathml.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++ src/format/mod.rs | 1 + src/lib.rs | 1 + 3 files changed, 52 insertions(+) create mode 100644 src/format/mathml.rs create mode 100644 src/format/mod.rs diff --git a/src/format/mathml.rs b/src/format/mathml.rs new file mode 100644 index 0000000..9051e4c --- /dev/null +++ b/src/format/mathml.rs @@ -0,0 +1,50 @@ +use crate::tokens::Greek; + +pub trait ToMathML { + fn to_mathml(&self) -> String; +} + +impl ToMathML for Greek { + fn to_mathml(&self) -> String { + let inner = match self { + Greek::Alpha => "α", + Greek::Beta => "β", + Greek::Gamma => "γ", + Greek::BigGamma => "Γ", + Greek::Delta => "δ", + Greek::BigDelta => "Δ", + Greek::Epsilon => "ε", + Greek::VarEpsilon => "ε", + Greek::Zeta => "ζ", + Greek::Eta => "η", + Greek::Theta => "θ", + Greek::BigTheta => "Θ", + Greek::VarTheta => "θ", + Greek::Iota => "ι", + Greek::Kappa => "κ", + Greek::Lambda => "λ", + Greek::BigLambda => "Λ", + Greek::Mu => "μ", + Greek::Nu => "ν", + Greek::Xi => "ξ", + Greek::BigXi => "Ξ", + Greek::Pi => "π", + Greek::BigPi => "Π", + Greek::Rho => "ρ", + Greek::Sigma => "σ", + Greek::BigSigma => "Σ", + Greek::Tau => "τ", + Greek::Upsilon => "υ", + Greek::Phi => "φ", + Greek::BigPhi => "Φ", + Greek::VarPhi => "φ", + Greek::Chi => "χ", + Greek::Psi => "ψ", + Greek::BigPsi => "Ψ", + Greek::Omega => "ω", + Greek::BigOmega => "Ω", + }; + + format!("{}", inner) + } +} diff --git a/src/format/mod.rs b/src/format/mod.rs new file mode 100644 index 0000000..6b8555d --- /dev/null +++ b/src/format/mod.rs @@ -0,0 +1 @@ +pub mod mathml; diff --git a/src/lib.rs b/src/lib.rs index 6481938..472c9c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ use crate::parsing::tokenizer::Tokenizer; use crate::parsing::tree_parser::TreeParser; pub mod elements; +pub mod format; pub mod parsing; pub mod tokens; pub(crate) mod utils;