Registry / RepositoryTypeScriptRustPython
Rollpie
ReadmeFiles
Versions
Info
Download
0.4.01085.8 KB2026-10-160.3.21087.6 KB2026-10-160.3.11087.5 KB2026-10-160.3.0117.8 KB2026-10-160.2.1106.1 KB2026-10-150.2.0105.5 KB2026-10-15
Version
0.3.1
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-10-16
Size
1087.5 KB
Downloads
24
Checksum
656aa128e98955e746555e14f8366cdca6c6761d61e1b74fa77a4797476f12dd
Dependencies
rust/[email protected]
rust/[email protected]

style.rs

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! Settings for the page layout and for typesetting
//!
//! Every length is in PDF points (72 points to an inch).

/// The number of heading depths. From part to subparagraph
pub const LEVEL: usize = 7;


/// Settings for typesetting
#[derive(Debug, Clone, PartialEq)]
pub struct Style {
    pub page_width: f64,
    pub page_height: f64,
    pub margin_top: f64,
    pub margin_bottom: f64,
    pub margin_left: f64,
    pub margin_right: f64,
    /// The font size of the body text
    pub size: f64,
    /// The distance from one baseline to the next
    pub leading: f64,
    /// The indent at the start of a paragraph
    pub indent: f64,
    /// The space between paragraphs
    pub paragraph_skip: f64,
    /// The space between words, and its stretch and shrink. Ratios to the body font size
    pub space: f64,
    pub space_stretch: f64,
    pub space_shrink: f64,
    /// How much the space between characters of Japanese text can stretch and shrink. Ratios
    /// to the body font size
    pub wide_stretch: f64,
    pub wide_shrink: f64,
    /// The size of headings. Ratios to the body text
    pub heading_size: [f64; LEVEL],
    /// The space before a heading
    pub heading_before: [f64; LEVEL],
    /// The space after a heading
    pub heading_after: [f64; LEVEL],
    /// The space between the number and the heading (em)
    pub heading_gap: f64,
    /// The indent of a list, and the space between the label and the contents
    pub list_indent: f64,
    pub list_gap: f64,
    /// The space between list items
    pub list_skip: f64,
    /// The indent on the left and right of a quotation
    pub quote_indent: f64,
    /// The size of footnotes, the space between them and the body text, and the length of the
    /// rule that separates them
    pub footnote_size: f64,
    pub footnote_gap: f64,
    pub footnote_rule: f64,
    /// The space between a float and the body text
    pub float_gap: f64,
    /// The fraction of a page that floats may use
    pub float_fraction: f64,
    /// The space between a caption and the figure
    pub caption_gap: f64,
    /// The padding on the left and right of a table cell, and the padding above and below
    pub cell_padding: f64,
    pub cell_lead: f64,
    /// The thickness of rules
    pub rule_width: f64,
    /// The thickness of lines such as fraction bars
    pub line_width: f64,
    /// How strict line breaking is. The larger the value, the looser the lines it allows
    pub tolerance: f64,
    /// The penalty when only the last line of a paragraph is left for the next page
    pub last_line_penalty: f64,
    /// The penalty when only the first line of a paragraph is left at the end of a page
    pub first_line_penalty: f64,
    /// Whether to show page numbers
    pub page_number: bool,
    /// The length of bonds in chemical structures (em)
    pub bond_length: f64,
}


impl Default for Style {
    fn default() -> Style {
        let size = 10.0;

        Style {
            page_width: 595.28,
            page_height: 841.89,
            margin_top: 80.0,
            margin_bottom: 80.0,
            margin_left: 72.0,
            margin_right: 72.0,
            size,
            leading: size * 1.7,
            indent: size,
            paragraph_skip: 0.0,
            space: 0.333,
            space_stretch: 0.167,
            space_shrink: 0.111,
            wide_stretch: 0.08,
            wide_shrink: 0.04,
            heading_size: [2.074, 1.728, 1.44, 1.2, 1.0, 1.0, 1.0],
            heading_before: [36.0, 30.0, 20.0, 16.0, 13.0, 11.0, 11.0],
            heading_after: [24.0, 20.0, 11.0, 9.0, 8.0, 4.0, 4.0],
            heading_gap: 0.7,
            list_indent: 20.0,
            list_gap: 6.0,
            list_skip: 3.0,
            quote_indent: 24.0,
            footnote_size: 8.0,
            footnote_gap: 14.0,
            footnote_rule: 120.0,
            float_gap: 14.0,
            float_fraction: 0.7,
            caption_gap: 8.0,
            cell_padding: 5.0,
            cell_lead: 3.0,
            rule_width: 0.5,
            line_width: 0.6,
            tolerance: 4.0,
            last_line_penalty: 300.0,
            first_line_penalty: 300.0,
            page_number: true,
            bond_length: 3.0,
        }
    }
}


/// The width in which the body text is set
pub fn body_width(style: &Style) -> f64 {
    style.page_width - style.margin_left - style.margin_right
}


/// The height in which the body text is set
pub fn body_height(style: &Style) -> f64 {
    style.page_height - style.margin_top - style.margin_bottom
}


/// Reads the options given to `\documentclass`
pub fn apply(style: &mut Style, option: &[String]) {
    for one in option {
        match one.as_str() {
            "a4paper" => {
                style.page_width = 595.28;
                style.page_height = 841.89;
            }
            "a5paper" => {
                style.page_width = 419.53;
                style.page_height = 595.28;
            }
            "b5paper" => {
                style.page_width = 498.9;
                style.page_height = 708.66;
            }
            "letterpaper" => {
                style.page_width = 612.0;
                style.page_height = 792.0;
            }
            "landscape" => {
                std::mem::swap(&mut style.page_width, &mut style.page_height);
            }
            "9pt" | "10pt" | "11pt" | "12pt" | "14pt" => {
                let size: f64 = one.trim_end_matches("pt").parse().unwrap_or(10.0);
                style.size = size;
                style.leading = size * 1.7;
                style.indent = size;
            }
            _ => {}
        }
    }
}