rust_texas/document/
metadata.rs1use itertools::Itertools;
2
3use crate::prelude::*;
4
5#[derive(Debug, Clone)]
7pub struct Metadata {
8 pub(crate) class: DocumentClass,
9 pub(crate) title: String,
10 pub(crate) author: Vec<String>,
11 pub maketitle: bool,
12 pub tableofcontents: bool,
13 pub date: bool,
14}
15impl AsLatex for Metadata {
16 fn to_string(&self) -> String {
17 let title_author = format!(
18 "\\title{{{}}}\n\\author{{{}}}\n",
19 self.title,
20 self.author.iter().join(r"\\ \and ")
21 );
22 match self.class {
23 DocumentClass {
24 typ: DocumentClassType::Beamer,
25 ..
26 } => {
27 format!(
29 "{title_author}\n{}\n",
30 if self.date { r"\date{\today}" } else { "" },
31 )
32 }
33 _ => {
34 format!(
35 "{title_author}\n{}\n{}\n{}\n",
36 if self.date { r"\today" } else { "" },
37 if self.maketitle { r"\maketitle" } else { "" },
38 if self.tableofcontents {
39 r"\tableofcontents"
40 } else {
41 ""
42 },
43 )
44 }
45 }
46 }
47}
48impl Metadata {
49 pub fn new(class: DocumentClass, title: &str, author: &[&str]) -> Self {
50 Self {
51 class,
52 title: title.to_string(),
53 author: author.iter().map(|x| x.to_string()).collect(),
54 maketitle: true,
55 tableofcontents: false,
56 date: false,
57 }
58 }
59}