omd2tex.objects#

class omd2tex.objects.Caption(text: list | str)[source]#

Bases: BaseClass

static attach_caption(elements) List[source]#

Attach caption objects to the preceding element as metadata.

class omd2tex.objects.SplitLine(text: str = '')[source]#

Bases: BaseClass

to_latex() str[source]#

Render a horizontal rule using configured width.

classmethod make_beamer(elements_list: List) List[source]#

Split elements into beamer frames based on divider elements.

class omd2tex.objects.Equation(equation: str)[source]#

Bases: BaseClass

to_latex() str[source]#

Render the equation to LaTeX with or without numbering.

class omd2tex.objects.Paragraph(text: str, parse: bool = True)[source]#

Bases: BaseClass

to_latex() str[source]#

Render the paragraph to LaTeX, optionally parsing markdown constructs.

static change_letters_for_equations(text: str, dict_file: str = '', surround_func=<function Paragraph.<lambda>>) str[source]#

Replace symbols in equations using a mapping file and wrapper.

Parameters:
  • text – Input equation text.

  • dict_file – Optional path to a JSON mapping file; defaults to bundled formulas.

  • surround_func – Callable applied to mapped values.

Returns:

Transformed text with mapped symbols.

static highlight_text1(text: str) str[source]#

Convert HTML superscript/subscript markers to LaTeX equivalents.

static highlight_text2(text: str) str[source]#

Convert markdown emphasis markers to LaTeX formatting.

static replace_inline_code(text: str) tuple[str, list][source]#

Replace inline code segments with placeholders preserving content.

static replace_inline_equation(text: str) tuple[str, list][source]#

Replace inline equations with placeholders preserving content.

static replace_outline_equation(text: str) tuple[str, list][source]#

Replace outline equations with placeholders preserving content.

static restore_placeholders(text: str, inline_equations=[], inline_codes=[], outline_equations=[]) str[source]#

Restore code and equation placeholders into the provided text.

static latinify_lines(lines: str, probability=0.05, seed=None, change_dict='') str[source]#

Randomly replace characters based on latinify mapping and probability.

static eq_ru_letter_workaround(text: str) str[source]#

Wrap Cyrillic characters in equations with text mode to avoid errors.

static text_errors_workaround(text: str) str[source]#

Normalize known problematic characters and dashes.

static process_references(text: str) str[source]#

Convert wiki-style references to LaTeX cref calls using global mapping.

static process_citations(text: str) str[source]#

Normalize citation markers to LaTeX \cite{} commands.

Supports patterns like ![[ @cite|text ]], [[ @cite ]], and \cite{@cite}, returning formatted citations or empty strings when source entries are missing.

Parameters:

text – Input string possibly containing various citation syntaxes.

Returns:

Text with citation patterns replaced by LaTeX citations; returns empty strings when citations are missing.

static escape_latex_special_chars(text: str) str[source]#

Escape unescaped LaTeX special characters in the provided text.

Parameters:

text (str) – Входная строка с LaTeX-выражениями

Returns:

Строка с экранированными специальными символами LaTeX

Return type:

str

static remove_all_highlight(text: str) str[source]#

Strip all markdown-style highlighting and emphasis markers.

static merge_items(items: list) list[source]#

Merge adjacent Paragraph instances when parsing flags match.

class omd2tex.objects.CodeBlock(blocktype: str, blocklines: list)[source]#

Bases: BaseClass

classmethod create(blocktype: str, blocklines: list) BaseClass[source]#

Factory method to create and render a code block element.

to_latex() str[source]#

Render the code block to LaTeX.

class omd2tex.objects.Reference(ref_text: str)[source]#

Bases: BaseClass

to_latex() str[source]#

Render reference placeholder; no direct LaTeX output.

static identify_elements_reference(elements: list) list[source]#

Update reference mappings for supported element types.

Parameters:

elements – List of parsed elements to inspect.

Returns:

New list with reference metadata registered.

static attach_reference(elements)[source]#

Attach the last seen reference object to the preceding element.

Parameters:

elements – Sequence of elements that may include Reference instances.

Returns:

List where references are assigned to prior elements when present.

class omd2tex.objects.Headline(level: int, text: str)[source]#

Bases: BaseClass

to_latex() str[source]#

Render the object to LaTeX markup.

Returns:

LaTeX string representation.

class omd2tex.objects.Table(lines: List[str])[source]#

Bases: BaseClass

to_latex() str[source]#

Render the table to LaTeX longtblr format.

class omd2tex.objects.Image(filename: str, parrentdir: str, caption: str = '', width: int | None = None, height: int | None = None, dir: str | None = None)[source]#

Bases: BaseClass

to_latex() str[source]#

Render the image as a LaTeX figure block respecting settings.

class omd2tex.objects.Quote(quotelines: List[str], filename: str = '', parrentdir='', filedepth=0, quotedepth=0)[source]#

Bases: BaseClass

to_latex() str[source]#

Convert the quote and its elements to LaTeX.

Parameters:

None

Returns:

LaTeX string for the quote environment with proper indentation.

classmethod create(quotelines: List[str], filename: str = '', parrentdir='', filedepth=0, quotedepth=0) BaseClass[source]#

Factory to create and process quote content in one step.

Parameters:
  • quotelines – Raw quote lines including leading markers.

  • filename – Source filename for context.

  • parrentdir – Parent directory path for nested includes.

  • filedepth – Current file recursion depth.

  • quotedepth – Current quote recursion depth.

Returns:

Processed element resulting from quote interpretation.

class omd2tex.objects.Footnote[source]#

Bases: BaseClass

collection = {}#
classmethod append(key: str, text: str | List[str]) None[source]#

Add a footnote to the shared collection converting markdown to LaTeX.

Parameters:
  • key – Footnote identifier.

  • text – Footnote text as string or list of lines.

Returns:

None

Side Effects:

Mutates the class-level collection mapping.

to_default() None[source]#

Reset the shared footnote collection to defaults.

change_footnote_keys(text: str) str[source]#

Replace footnote keys in text with unique generated identifiers.

Parameters:

text – Input text containing footnote markers.

Returns:

Text with footnote keys rewritten to unique values.

class omd2tex.objects.Enumerate(text: str, depth: int, number: int = 0, complete: bool = False, reference=None)[source]#

Bases: List

to_latex_item() str[source]#

Render an enumerated item with adjusted counter.

to_latex() str[source]#

Render an enumerate environment with optional keep-with-next fix.

class omd2tex.objects.Bullet(text: str, depth: int, number: int = 0, complete: bool = False, reference=None)[source]#

Bases: List

to_latex_item() str[source]#

Render a bullet list item.

to_latex() str[source]#

Render a bullet list environment.

class omd2tex.objects.Check(text: str, depth: int, number: int = 0, complete: bool = False, reference=None)[source]#

Bases: List

to_latex_item() str[source]#

Render a checklist item using box symbols.

to_latex() str[source]#

Render a checklist as an itemize environment.

class omd2tex.objects.List(text: str, depth: int, number: int = 0, complete: bool = False, reference=None)[source]#

Bases: BaseClass

to_latex_item() str[source]#

Render a single list item to LaTeX.

Returns:

LaTeX string representing the list item content.

to_latex() str[source]#

Render the list and merged nested items to LaTeX.

Returns:

LaTeX string for the list content, including merged sublists when present.

append(item: List) None[source]#

Append another list item at the same depth.

Parameters:

item – List item to append; must match depth.

Returns:

None

Raises:

TypeError – If item type or depth is incompatible.

static append_items(items: list) list[source]#

Group consecutive list items of equal depth.

Parameters:

items – Sequence of parsed elements possibly containing List instances.

Returns:

List with grouped List items aggregated by depth.

merge(item: List) None[source]#

Merge a deeper nested item under the current list element.

Parameters:

item – Nested List item.

Returns:

None

Raises:

TypeError – If provided item is not deeper than the current one.

static merge_items(items: list) list[source]#

Merge subsequent deeper list items into preceding parents.

Parameters:

items – Sequence of elements containing List instances.

Returns:

List where nested items are attached to their appropriate parents.

static indent(text: str, depth: int) str[source]#

Indent text by a multiple of four spaces based on depth.

Parameters:
  • text – String to indent.

  • depth – Nesting level to determine indentation.

Returns:

Indented text string.

class omd2tex.objects.Preamble[source]#

Bases: BaseClass

to_latex() str[source]#

Generate LaTeX preamble string based on document class.

class omd2tex.objects.Citation(key: str)[source]#

Bases: BaseClass

citation_list = []#
to_latex() str[source]#

Render citation content into LaTeX filecontents and bibliography declaration.

classmethod to_latex_preamble() str[source]#

Concatenate LaTeX preamble entries for all registered citations.

class omd2tex.objects.File(filename: str | None = None, parrentdir: str | None = None, filedepth: int = 0)[source]#

Bases: BaseClass

from_file(filename: str) File[source]#

Parse markdown from disk into this File instance.

from_elements(list: List) File[source]#

Populate this file from an existing list of elements.

from_text(text: str) File[source]#

Parse markdown text directly into this File instance.

check()[source]#

Print parsed elements and their LaTeX output for debugging.

to_latex()[source]#

Render contained elements to a combined LaTeX string.

class omd2tex.objects.Document(filename: str = '', settings: Dict[str, Any] | str = None, preamble: str = None)[source]#

Bases: BaseClass

from_file(filename: str) Document[source]#

Load and parse a markdown file into a Document.

from_text(text: str) Document[source]#

Create a document from raw markdown text.

from_elements(list: list) Document[source]#

Build a document from preconstructed elements.

check() None[source]#

Print contained file diagnostics and reset global state.

to_latex() str[source]#

Render the document to a full LaTeX string with preamble and body.

to_latex_file(filename: str = '') None[source]#

Write the rendered LaTeX document to a file.

Parameters:

filename – Optional override for output filename; defaults to derived from markdown name.

Returns:

None

Side Effects:

Writes LaTeX files to disk and may create makefiles.

to_latex_project(filename='') None[source]#

Create a full LaTeX project directory with includes and assets.

Parameters:

filename – Optional override for main filename.

Returns:

None

Raises:

ValueError – If the document or file is not initialized before export.

Side Effects:

Writes multiple files/directories and copies theme assets when needed.

class omd2tex.objects.Makefile[source]#

Bases: object

classmethod to_string() str[source]#

Generate Makefile content tailored to citation and reference usage.

classmethod to_file(directory='.') str[source]#

Записывает Makefile в указанную директорию

Parameters:

directory – Target directory where Makefile should be written.

Returns:

Path to the generated Makefile.

Side Effects:

Writes a Makefile to disk.