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
impl ContentBuilder
Sourcepub fn build_document(&self) -> &str
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());Sourcepub fn set_document_class(
&mut self,
document_class: DocumentClass,
options: Vec<Box<dyn ToString>>,
)
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}Sourcepub fn use_package(&mut self, package: &str, options: Vec<Box<dyn ToString>>)
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}Sourcepub fn add_literal(&mut self, text: &str)
pub fn add_literal(&mut self, text: &str)
Sourcepub fn begin_document(&mut self)
pub fn begin_document(&mut self)
Begins the document environment.
§Example
let mut builder = ContentBuilder::new();
builder.begin_document();Generated LaTeX:
\begin{document}Sourcepub fn end_document(&mut self)
pub fn end_document(&mut self)
Ends the document environment.
§Example
let mut builder = ContentBuilder::new();
builder.end_document();Generated LaTeX:
\end{document}Sourcepub fn title<S: StringOrBuilder>(&mut self, title: S)
pub fn title<S: StringOrBuilder>(&mut self, title: S)
Sourcepub fn maketitle(&mut self)
pub fn maketitle(&mut self)
Adds the \maketitle command to the document.
§Example
let mut builder = ContentBuilder::new();
builder.maketitle();Generated LaTeX:
\maketitleSourcepub fn text_bold<S: StringOrBuilder>(&mut self, text: S)
pub fn text_bold<S: StringOrBuilder>(&mut self, text: S)
Sourcepub fn text_italic<S: StringOrBuilder>(&mut self, text: S)
pub fn text_italic<S: StringOrBuilder>(&mut self, text: S)
Sourcepub fn text_underline<S: StringOrBuilder>(&mut self, text: S)
pub fn text_underline<S: StringOrBuilder>(&mut self, text: S)
Sourcepub fn new_line(&mut self)
pub fn new_line(&mut self)
Adds a new line to the document.
§Example
let mut builder = ContentBuilder::new();
builder.new_line();Generated LaTeX:
\\Sourcepub fn label<S: StringOrBuilder>(&mut self, label: S)
pub fn label<S: StringOrBuilder>(&mut self, label: S)
Sourcepub fn section<S: StringOrBuilder>(&mut self, title: S)
pub fn section<S: StringOrBuilder>(&mut self, title: S)
Sourcepub fn subsection<S: StringOrBuilder>(&mut self, title: S)
pub fn subsection<S: StringOrBuilder>(&mut self, title: S)
Sourcepub fn subsubsection<S: StringOrBuilder>(&mut self, title: S)
pub fn subsubsection<S: StringOrBuilder>(&mut self, title: S)
Sourcepub fn paragraph<S: StringOrBuilder>(&mut self, text: S)
pub fn paragraph<S: StringOrBuilder>(&mut self, text: S)
Sourcepub fn subparagraph<S: StringOrBuilder>(&mut self, text: S)
pub fn subparagraph<S: StringOrBuilder>(&mut self, text: S)
Sourcepub fn footnote<S: StringOrBuilder>(&mut self, text: S)
pub fn footnote<S: StringOrBuilder>(&mut self, text: S)
Sourcepub fn cite<S: StringOrBuilder, V: StringOrBuilder>(
&mut self,
citation: S,
subcitation: Option<V>,
)
pub fn cite<S: StringOrBuilder, V: StringOrBuilder>( &mut self, citation: S, subcitation: Option<V>, )
Sourcepub fn ref_label<S: StringOrBuilder>(&mut self, label: S)
pub fn ref_label<S: StringOrBuilder>(&mut self, label: S)
Sourcepub fn text_color<S: StringOrBuilder, V: StringOrBuilder>(
&mut self,
text: S,
color: V,
color_model: Option<ColorModel>,
)
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}Sourcepub fn hspace<S: StringOrBuilder>(&mut self, length: S)
pub fn hspace<S: StringOrBuilder>(&mut self, length: S)
Sourcepub fn vspace<S: StringOrBuilder>(&mut self, length: S)
pub fn vspace<S: StringOrBuilder>(&mut self, length: S)
Sourcepub fn include<S: StringOrBuilder>(&mut self, filename: S)
pub fn include<S: StringOrBuilder>(&mut self, filename: S)
Sourcepub fn input<S: StringOrBuilder>(&mut self, filename: S)
pub fn input<S: StringOrBuilder>(&mut self, filename: S)
Sourcepub fn clear_page(&mut self)
pub fn clear_page(&mut self)
Adds a \clearpage command to the document.
§Example
let mut builder = ContentBuilder::new();
builder.clear_page();Generated LaTeX:
\clearpageSourcepub fn new_page(&mut self)
pub fn new_page(&mut self)
Adds a \newpage command to the document.
§Example
let mut builder = ContentBuilder::new();
builder.new_page();Generated LaTeX:
\newpageSourcepub fn line_break(&mut self)
pub fn line_break(&mut self)
Adds a \linebreak command to the document.
§Example
let mut builder = ContentBuilder::new();
builder.line_break();Generated LaTeX:
\linebreakSourcepub fn page_break(&mut self)
pub fn page_break(&mut self)
Adds a \pagebreak command to the document.
§Example
let mut builder = ContentBuilder::new();
builder.page_break();Generated LaTeX:
\pagebreakSourcepub fn no_indent(&mut self)
pub fn no_indent(&mut self)
Adds a \noindent command to the document.
§Example
let mut builder = ContentBuilder::new();
builder.no_indent();Generated LaTeX:
\noindentSourcepub fn centering(&mut self)
pub fn centering(&mut self)
Adds a \centering command to the document.
§Example
let mut builder = ContentBuilder::new();
builder.centering();Generated LaTeX:
\centeringSourcepub fn itemize<S: StringOrBuilder>(&mut self, content: S)
pub fn itemize<S: StringOrBuilder>(&mut self, content: S)
Sourcepub fn env<S: StringOrBuilder>(&mut self, env: Environment<'_>, content: S)
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}