use std::fmt::Display;
use crate::prelude::*;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DocumentClassType {
Article,
Amsart,
Part,
Report,
Book,
Beamer,
}
impl Display for DocumentClassType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match &self {
Self::Article => "article",
Self::Part => "part",
Self::Report => "report",
Self::Book => "book",
Self::Amsart => "amsart",
Self::Beamer => "beamer",
}
)?;
Ok(())
}
}
impl From<&str> for DocumentClassType {
fn from(value: &str) -> Self {
match value {
"article" => Self::Article,
"part" => Self::Part,
"book" => Self::Book,
"report" => Self::Report,
"amsart" => Self::Amsart,
"beamer" => Self::Beamer,
_ => Self::Article,
}
}
}
#[derive(Debug, Clone)]
pub struct DocumentClass {
pub(crate) typ: DocumentClassType,
pub(crate) opt: Vec<String>,
}
impl DocumentClass {
pub fn new(typ: &str) -> Self {
Self {
typ: typ.into(),
opt: vec![],
}
}
}
impl AsLatex for DocumentClass {
fn to_string(&self) -> String {
let options = self
.opt
.iter()
.map(|s| format!("{}, ", s))
.collect::<String>();
format!("\\documentclass[{}]{{{}}}", options, self.typ.to_string())
}
}
impl Opt for DocumentClass {
fn add_option(&mut self, opt: &str) {
self.opt.push(opt.to_string())
}
}