Struct ContentBuilder

Source
pub struct ContentBuilder { /* private fields */ }
Expand description

A builder for programmatically generating LaTeX documents.

§Example

use rusttex::{ContentBuilder, DocumentClass};
 
let mut builder = ContentBuilder::new();
builder.set_document_class(DocumentClass::Article, options![]);
builder.begin_document();
builder.title("Example Document");
builder.end_document();
 
println!("{}", builder.build_document());

Generated LaTeX:

\documentclass{article}
\begin{document}
\title{Example Document}
\end{document}

Implementations§

Source§

impl ContentBuilder

Source

pub fn new() -> Self

Creates a new ContentBuilder instance.

§Example
let builder = ContentBuilder::new();
Source

pub fn build_document(&self) -> &str

Builds and returns the generated LaTeX document as a string slice.

§Example
let builder = ContentBuilder::new();
println!("{}", builder.build_document());
Source

pub fn set_document_class( &mut self, document_class: DocumentClass, options: Vec<Box<dyn ToString>>, )

Sets the document class for the LaTeX document.

§Parameters
  • document_class: The document class (e.g., DocumentClass::Article).
  • options: A list of options for the document class.
§Example
use rusttex::{ContentBuilder, DocumentClass, options};

let mut builder = ContentBuilder::new();
builder.set_document_class(DocumentClass::Article, options!["a4paper", "twocolumn"]);

Generated LaTeX:

\documentclass[a4paper,twocolumn]{article}
Source

pub fn use_package(&mut self, package: &str, options: Vec<Box<dyn ToString>>)

Adds a LaTeX package to the document.

§Parameters
  • package: The name of the package (e.g., "amsmath").
  • options: A list of options for the package.
§Example
use rusttex::{ContentBuilder, options};

let mut builder = ContentBuilder::new();
builder.use_package("amsmath", options!["fleqn"]);

Generated LaTeX:

\usepackage[fleqn]{amsmath}
Source

pub fn add_literal(&mut self, text: &str)

Adds literal text to the document.

§Parameters
  • text: The text to add.
§Example
let mut builder = ContentBuilder::new();
builder.add_literal("This is some text.");

Generated LaTeX:

This is some text.
Source

pub fn begin_document(&mut self)

Begins the document environment.

§Example
let mut builder = ContentBuilder::new();
builder.begin_document();

Generated LaTeX:

\begin{document}
Source

pub fn end_document(&mut self)

Ends the document environment.

§Example
let mut builder = ContentBuilder::new();
builder.end_document();

Generated LaTeX:

\end{document}
Source

pub fn title<S: StringOrBuilder>(&mut self, title: S)

Sets the title of the document.

§Parameters
  • title: The title text.
§Example
let mut builder = ContentBuilder::new();
builder.title("My Document");

Generated LaTeX:

\title{My Document}
Source

pub fn author<S: StringOrBuilder>(&mut self, author: S)

Sets the author of the document.

§Parameters
  • author: The author text.
§Example
let mut builder = ContentBuilder::new();
builder.author("John Doe");

Generated LaTeX:

\author{John Doe}
Source

pub fn maketitle(&mut self)

Adds the \maketitle command to the document.

§Example
let mut builder = ContentBuilder::new();
builder.maketitle();

Generated LaTeX:

\maketitle
Source

pub fn text_bold<S: StringOrBuilder>(&mut self, text: S)

Adds bold text to the document.

§Parameters
  • text: The text to make bold.
§Example
let mut builder = ContentBuilder::new();
builder.text_bold("Bold Text");

Generated LaTeX:

\textbf{Bold Text}
Source

pub fn text_italic<S: StringOrBuilder>(&mut self, text: S)

Adds italic text to the document.

§Parameters
  • text: The text to italicize.
§Example
let mut builder = ContentBuilder::new();
builder.text_italic("Italic Text");

Generated LaTeX:

\textit{Italic Text}
Source

pub fn text_underline<S: StringOrBuilder>(&mut self, text: S)

Adds underlined text to the document.

§Parameters
  • text: The text to underline.
§Example
let mut builder = ContentBuilder::new();
builder.text_underline("Underlined Text");

Generated LaTeX:

\underline{Underlined Text}
Source

pub fn new_line(&mut self)

Adds a new line to the document.

§Example
let mut builder = ContentBuilder::new();
builder.new_line();

Generated LaTeX:

\\
Source

pub fn label<S: StringOrBuilder>(&mut self, label: S)

Adds a label to the document.

§Parameters
  • label: The label text.
§Example
let mut builder = ContentBuilder::new();
builder.label("sec:intro");

Generated LaTeX:

\label{sec:intro}
Source

pub fn section<S: StringOrBuilder>(&mut self, title: S)

Adds a section to the document.

§Parameters
  • title: The title of the section.
§Example
let mut builder = ContentBuilder::new();
builder.section("Introduction");

Generated LaTeX:

\section{Introduction}
Source

pub fn subsection<S: StringOrBuilder>(&mut self, title: S)

Adds a subsection to the document.

§Parameters
  • title: The title of the subsection.
§Example
let mut builder = ContentBuilder::new();
builder.subsection("Background");

Generated LaTeX:

\subsection{Background}
Source

pub fn subsubsection<S: StringOrBuilder>(&mut self, title: S)

Adds a subsubsection to the document.

§Parameters
  • title: The title of the subsubsection.
§Example
let mut builder = ContentBuilder::new();
builder.subsubsection("Details");

Generated LaTeX:

\subsubsection{Details}
Source

pub fn paragraph<S: StringOrBuilder>(&mut self, text: S)

Adds a paragraph to the document.

§Parameters
  • text: The text of the paragraph.
§Example
let mut builder = ContentBuilder::new();
builder.paragraph("This is a paragraph.");

Generated LaTeX:

\paragraph{This is a paragraph.}
Source

pub fn subparagraph<S: StringOrBuilder>(&mut self, text: S)

Adds a subparagraph to the document.

§Parameters
  • text: The text of the subparagraph.
§Example
let mut builder = ContentBuilder::new();
builder.subparagraph("This is a subparagraph.");

Generated LaTeX:

\subparagraph{This is a subparagraph.}
Source

pub fn footnote<S: StringOrBuilder>(&mut self, text: S)

Adds a footnote to the document.

§Parameters
  • text: The text of the footnote.
§Example
let mut builder = ContentBuilder::new();
builder.footnote("This is a footnote.");

Generated LaTeX:

\footnote{This is a footnote.}
Source

pub fn cite<S: StringOrBuilder, V: StringOrBuilder>( &mut self, citation: S, subcitation: Option<V>, )

Adds a citation to the document.

§Parameters
  • citation: The citation key.
  • subcitation: An optional subcitation.
§Example
let mut builder = ContentBuilder::new();
builder.cite("doe2020", Some("p. 42"));

Generated LaTeX:

\cite[p. 42]{doe2020}
Source

pub fn ref_label<S: StringOrBuilder>(&mut self, label: S)

Adds a reference to a label in the document.

§Parameters
  • label: The label to reference.
§Example
let mut builder = ContentBuilder::new();
builder.ref_label("sec:intro");

Generated LaTeX:

\ref{sec:intro}
Source

pub fn text_color<S: StringOrBuilder, V: StringOrBuilder>( &mut self, text: S, color: V, color_model: Option<ColorModel>, )

Adds colored text to the document.

§Parameters
  • text: The text to color.
  • color: The color to apply.
  • color_model: An optional color model.
§Example
use rusttex::{ContentBuilder, ColorModel};

let mut builder = ContentBuilder::new();
builder.text_color("Colored Text", "red", Some(ColorModel::RGB));

Generated LaTeX:

\textcolor[RGB]{red}{Colored Text}
Source

pub fn hspace<S: StringOrBuilder>(&mut self, length: S)

Adds horizontal space to the document.

§Parameters
  • length: The length of the space.
§Example
let mut builder = ContentBuilder::new();
builder.hspace("1cm");

Generated LaTeX:

\hspace{1cm}
Source

pub fn vspace<S: StringOrBuilder>(&mut self, length: S)

Adds vertical space to the document.

§Parameters
  • length: The length of the space.
§Example
let mut builder = ContentBuilder::new();
builder.vspace("1cm");

Generated LaTeX:

\vspace{1cm}
Source

pub fn include<S: StringOrBuilder>(&mut self, filename: S)

Includes another LaTeX file in the document.

§Parameters
  • filename: The name of the file to include.
§Example
let mut builder = ContentBuilder::new();
builder.include("otherfile");

Generated LaTeX:

\include{otherfile}
Source

pub fn input<S: StringOrBuilder>(&mut self, filename: S)

Inputs another LaTeX file in the document.

§Parameters
  • filename: The name of the file to input.
§Example
let mut builder = ContentBuilder::new();
builder.input("otherfile");

Generated LaTeX:

\input{otherfile}
Source

pub fn clear_page(&mut self)

Adds a \clearpage command to the document.

§Example
let mut builder = ContentBuilder::new();
builder.clear_page();

Generated LaTeX:

\clearpage
Source

pub fn new_page(&mut self)

Adds a \newpage command to the document.

§Example
let mut builder = ContentBuilder::new();
builder.new_page();

Generated LaTeX:

\newpage
Source

pub fn line_break(&mut self)

Adds a \linebreak command to the document.

§Example
let mut builder = ContentBuilder::new();
builder.line_break();

Generated LaTeX:

\linebreak
Source

pub fn page_break(&mut self)

Adds a \pagebreak command to the document.

§Example
let mut builder = ContentBuilder::new();
builder.page_break();

Generated LaTeX:

\pagebreak
Source

pub fn no_indent(&mut self)

Adds a \noindent command to the document.

§Example
let mut builder = ContentBuilder::new();
builder.no_indent();

Generated LaTeX:

\noindent
Source

pub fn centering(&mut self)

Adds a \centering command to the document.

§Example
let mut builder = ContentBuilder::new();
builder.centering();

Generated LaTeX:

\centering
Source

pub fn itemize<S: StringOrBuilder>(&mut self, content: S)

Adds an item to an itemized list in the document.

§Parameters
  • content: The content of the item.
§Example
let mut builder = ContentBuilder::new();
builder.itemize("Item 1");

Generated LaTeX:

\item {Item 1}
Source

pub fn env<S: StringOrBuilder>(&mut self, env: Environment<'_>, content: S)

Adds an environment to the document.

§Parameters
  • env: The environment to add.
  • content: The content of the environment.
§Example
use rusttex::{ContentBuilder, Environment};

let mut builder = ContentBuilder::new();
builder.env(Environment::Abstract, "This is an abstract.");

Generated LaTeX:

\begin{abstract}
This is an abstract.
\end{abstract}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.