#latex #document #generate #tex #elements #class #mustafif

tex-rs

用于在 Rust 中创建 LaTeX 文档的库

10 个版本

0.2.8 2022年4月19日
0.2.7 2022年4月18日
0.2.3 2022年3月24日
0.2.1 2022年2月16日
0.1.0 2022年2月11日

#1858文本处理


4 个 crate(3 个直接) 中使用

MIT 许可协议

35KB
839

Tex-rs
开始开发时间:2022年2月
许可协议:MIT
作者:Mustafif Khan | MKProjects
这个 crate 是为了使用附加文档元素的概念来生成 LaTeX 文档的库。下面的例子展示了如何使用这个库

use tex_rs::*;
use std::path::Path;

fn main() {
    use std::path::PathBuf;
let mut latex = latex::Latex::new();
    latex.set_class(Class::Book);
    latex.set_metadata(Metadata::default());
    latex.add_package("dramatist".to_owned());

    let mut part_one = Part::new("Part 1");
    let section_one = Section::new("Section 1");

    let mut part_two = Part::new("Part 2");
    let mut chapter = Chapter::new("Chapter");
    let text = Text::new("text in part 2", TextType::Roman);

    part_one.attach(Element::from(section_one)).unwrap();
    chapter.attach(Element::from(text)).unwrap();
    part_two.attach(Element::from(chapter)).unwrap();

    let mut env = Environment::new("equation");
    env.attach_string("x^2 + y^2 = z^2".to_owned());

    part_two.attach(Element::from(env)).unwrap();

    let mut list = List::new(ListMode::Enumerate, &vec!["item 1".to_owned(), "item 2".to_owned(), "item 3".to_owned()]);

    part_two.attach(Element::from(list)).unwrap();

    latex.set_elements(elements![part_one, part_two]);

    latex.write(Path::new("simple.tex").to_path_buf()).unwrap()
}

依赖项

~6–18MB
~215K SLoC