Crate rustex

Source
Expand description

§RusTeX

A library to make simple auto-generated LaTeX files in Rust.

§Quick start

To use RusTeX, add the crate to your Cargo.toml.

[dependencies]
rustex = "0.1.0"

§Implemented Features

§Components

  • Package
  • Command
  • Chapter
  • Section
  • Enumerate
  • Table
  • Figure
  • Text
  • Label
  • PageBreak

§Formatting

  • Markdown bold
  • Markdown italic
  • Color text

§Example

A full example with the resulting PDF file is accessible in the example folder of the repository.

  1. Start by creating a base Document
const DOCUMENT_NAME: &str = "generated_tex/main.tex";
const DOCUMENT_CLASS: ClassType = ClassType::Report;
const FONT_SIZE: &str = "12pt";

let doc_file: File = File::create(DOCUMENT_NAME).unwrap();

let doc_class: DocumentClass = DocumentClass::new(
    DOCUMENT_CLASS,
    vec![FONT_SIZE]
);

let mut doc: Document = Document::new(doc_file, doc_class);
  1. Add some Packages
let packages = vec![
    Package::new(
        "babel",
        vec!["english"]
    ),
    Package::new(
        "geometry",
        vec!["margin=2.5cm"]
    ),
    Package::new(
        "fontenc",
        vec!["T1"]
    )
];

doc.add_packages(packages);
  1. Add some global Commands
let commands = vec![
    Command::new(r"\title{Title}"),
    Command::new(r"\author{Author}"),
    Command::new(r"\date{YYYY / MM / DD}"),
    Command::new(r"\setlength{\tabcolsep}{18pt}")
];

doc.add_global_commands(commands);
  1. Then you can add different Items

    • Any Item can be added to a Document
    • Any Item can be added to a Container
    • A Container is an Item, so they can be nested
    • Items are displayed by order that they have been added
    let mut section_1: Section = Section::new(
        "Section",             // Section name
        SectionType::Section,  // Section type
        true,                  // Display section number
        "sec_1"                // Label
    );
    
    let paragraph_1 = Text::new(
        "Lorem ipsum dolor sit amet, **consectetur** adipiscing elit. Integer congue nisi condimentum
        lacus vulputate cursus. _Curabitur_ bibendum orci ac nibh vestibulum ultrices. Aenean pulvinar
        mattis lectus, sed vehicula leo pellentesque eget. Sed sed quam sit amet nulla lacinia mollis.
        Maecenas dignissim, augue quis suscipit pellentesque, ipsum turpis facilisis eros, eu aliquam
        erat massa sit amet ex."
    );
    
    section_1.add_item(paragraph_1);
    doc.add_item(section_1);

Structs§

Block
A transparent object that contains Items A Block object is not displayed. Its only purpose is to group other Items. Example: A Block can be composed of a Text and a Figure and be added to an Enumerate. This way, the text and the figure will be placed under the same \item in the enumerate.
Chapter
A Container object that contains Items and displays them in a chapter. Refer to chapter in LaTeX documentation for more information.
Command
An object to add any LaTeX commands to an Item or a Document.
Document
The base of the generated LaTeX file. Containers and Items can be added to the Document object. Packages and global Commands are located before the \begin{document} line. Other Items are located between the \begin{document} and \end{document} lines.
DocumentClass
Defines the class of the Document.
Enumerate
An object that can list Items. Refer to enumerate in LaTeX documentation for more information.
Figure
An object that can display images, graphics, etc. Refer to figure in LaTeX documentation for more information.
HorizontalLine
A horizontal line that can be added to a Table
Package
An object to import libraries to your LaTeX file.
PageBreak
An object to add a page jump to a Document.
Section
A Container object that contains Items and displays them in a section. Refer to section in LaTeX documentation for more information.
Table
An object that can contain different TableComponents in rows and columns. Refer to table in LaTeX documentation for more information.
TableRow
A row that can be added to a Table
Text
An Item that wraps strings. Can be used as paragraphs, as captions, etc. Supports Markdown bold formatting (**bold**) Supports Markdown italic formatting (_bold_) Supports Color text formatting (#blue{text})

Enums§

ClassType
Defines the type of a DocumentClass object.
SectionType
Can be passed to a Section component to define its type.

Traits§

Container
An object that can contain Items. A Container is an Item, so it can be nested.
Item
A component that can be added to a Document or a Container
TableComponent
A component that can be added to a Table