1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use itertools::Itertools;

use crate::prelude::*;

/// Title and author, if y'all want more, please put up an issue.
#[derive(Debug, Clone)]
pub struct Metadata {
    pub(crate) class: DocumentClass,
    pub(crate) title: String,
    pub(crate) author: Vec<String>,
    pub maketitle: bool,
    pub tableofcontents: bool,
    pub date: bool,
}
impl AsLatex for Metadata {
    fn to_string(&self) -> String {
        let title_author = format!(
            "\\title{{{}}}\n\\author{{{}}}\n",
            self.title,
            self.author.iter().join(r"\\ \and ")
        );
        match self.class {
            DocumentClass {
                typ: DocumentClassType::Beamer,
                ..
            } => {
                // todo!()
                format!(
                    "{title_author}\n{}\n",
                    if self.date { r"\date{\today}" } else { "" },
                )
            }
            _ => {
                format!(
                    "{title_author}\n{}\n{}\n{}\n",
                    if self.date { r"\today" } else { "" },
                    if self.maketitle { r"\maketitle" } else { "" },
                    if self.tableofcontents {
                        r"\tableofcontents"
                    } else {
                        ""
                    },
                )
            }
        }
    }
}
impl Metadata {
    pub fn new(class: DocumentClass, title: &str, author: &[&str]) -> Self {
        Self {
            class,
            title: title.to_string(),
            author: author.iter().map(|x| x.to_string()).collect(),
            maketitle: true,
            tableofcontents: false,
            date: true,
        }
    }
}