omd2tex.objects.paragraph module#

class omd2tex.objects.paragraph.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.