fabricatio_typst.rust

Classes

BibManager

Functions

comment(→ str)

Adds comment prefix // to each line of the string.

convert_all_tex_math(→ str)

Converts all supported TeX math expressions in a string to Typst format.

extract_body(→ Optional[str])

Extracts the body content enclosed by exactly two wrapper strings.

extract_sections(→ list[tuple[str, str]])

Extracts sections from markdown-style text by header level.

fix_misplaced_labels(→ str)

Fixes misplaced labels in a string by moving them outside display math blocks.

replace_thesis_body(→ Optional[str])

Replaces the body content enclosed by two wrapper strings.

split_out_metadata(→ tuple[Optional[Any], str])

Splits metadata (YAML front matter) from a Typst document string.

strip_comment(→ str)

Removes leading and trailing comment lines from a multi-line string.

tex_to_typst(→ str)

Converts a raw LaTeX string to Typst format.

to_metadata(→ str)

Converts a Python object to a YAML string with comment formatting.

uncomment(→ str)

Removes comment prefix // from each line of the string.

Package Contents

class fabricatio_typst.rust.BibManager
get_cite_key_by_title(title: str) str | None

Find the cite key of an article with given title.

get_cite_key_by_title_fuzzy(title: str) str | None
get_cite_key_fuzzy(query: str) str | None

Find the corresponding cite key of an article with given query string using fuzzy matcher.

list_titles(is_verbatim: bool = False) list[str]
get_author_by_key(key: str) list[str] | None
get_year_by_key(key: str) int | None
get_abstract_by_key(key: str) str | None
get_title_by_key(key: str) str | None
get_field_by_key(key: str, field: str) str | None
fabricatio_typst.rust.comment(string: str) str

Adds comment prefix // to each line of the string.

Parameters:

string – The input string to comment.

Returns:

A string with // prepended to each line.

fabricatio_typst.rust.convert_all_tex_math(string: str) str

Converts all supported TeX math expressions in a string to Typst format.

Handles $…$, $$…$$, (…), and […] delimiters.

Parameters:

string – The input string containing TeX math expressions.

Returns:

A PyResult containing the string with converted math expressions.

fabricatio_typst.rust.extract_body(string: str, wrapper: str) str | None

Extracts the body content enclosed by exactly two wrapper strings.

Parameters:
  • string – The string containing the wrapped body.

  • wrapper – The wrapper string that marks the beginning and end.

Returns:

The body content if exactly one match found, None otherwise.

fabricatio_typst.rust.extract_sections(string: str, level: int = 1, section_char: str = '#') list[tuple[str, str]]

Extracts sections from markdown-style text by header level.

Parameters:
  • string – The markdown text to parse.

  • level – The header level to extract (e.g., 1 for #, 2 for ##).

  • section_char – Optional character to use as header marker (default: #).

Returns:

A list of tuples containing (header_text, section_content).

fabricatio_typst.rust.fix_misplaced_labels(string: str) str

Fixes misplaced labels in a string by moving them outside display math blocks.

Labels in the format <label> that appear inside […] blocks are moved to outside the block.

Parameters:

string – The input string to fix.

Returns:

A string with misplaced labels moved outside display math blocks.

fabricatio_typst.rust.replace_thesis_body(string: str, wrapper: str, new_body: str) str | None

Replaces the body content enclosed by two wrapper strings.

Parameters:
  • string – The original string containing the wrapped body.

  • wrapper – The wrapper string that marks the beginning and end.

  • new_body – The new body content to insert.

Returns:

The string with the body replaced, or None if wrapper not found.

fabricatio_typst.rust.split_out_metadata(string: str) tuple[Any | None, str]

Splits metadata (YAML front matter) from a Typst document string.

Extracts leading comment lines as YAML metadata and returns the remaining content.

Parameters:

string – The input string with potential YAML front matter.

Returns:

A tuple of (parsed metadata as Python object or None, remaining string content).

fabricatio_typst.rust.strip_comment(string: str) str

Removes leading and trailing comment lines from a multi-line string.

Parameters:

string – The input string to strip comments from.

Returns:

A string with leading and trailing comment lines removed.

fabricatio_typst.rust.tex_to_typst(string: str) str

Converts a raw LaTeX string to Typst format.

Parameters:

string – The raw LaTeX string to convert.

Returns:

A PyResult containing the converted Typst string.

fabricatio_typst.rust.to_metadata(data: Any) str

Converts a Python object to a YAML string with comment formatting.

Parameters:

data – The Python object to convert.

Returns:

A PyResult containing the YAML string with // comments.

fabricatio_typst.rust.uncomment(string: str) str

Removes comment prefix // from each line of the string.

Parameters:

string – The input string to uncomment.

Returns:

A string with comment prefixes removed from each line.