tex Module (stx.tex)
scitex-tex — LaTeX helpers (export, preview, vector formatting) — standalone.
- scitex.tex.export_tex(writer_doc, output_path, document_class='article', packages=None, preamble=None, image_dir=None, export_images=True, journal_preset=None, class_options=None, use_bibtex=False)[source]
Export a SciTeX writer document to LaTeX format.
- Parameters:
writer_doc (dict) – SciTeX writer document structure containing: - blocks: List of document blocks (headings, paragraphs, captions, etc.) - metadata: Document metadata (title, author, etc.) - images: Image references with binary data - references: Bibliography entries
output_path (str | Path) – Output path for the .tex file.
document_class (str) – LaTeX document class (article, report, book, etc.). Overridden if journal_preset is specified.
packages (list[str] | None) – Additional LaTeX packages to include.
preamble (str | None) – Additional preamble content.
image_dir (str | Path | None) – Directory to save extracted images. If None, uses “{output_stem}_figures/” next to the output .tex file. Set export_images=False to skip image export.
export_images (bool) – Whether to export images to files. Default True.
journal_preset (str | None) – Use a journal-specific preset: “ieee”, “elsevier”, “springer”, “aps”, “mdpi”, “acm”. Sets document_class and required packages.
class_options (list[str] | None) – Document class options (e.g., [“12pt”, “twocolumn”]).
use_bibtex (bool) – If True, generate bibliography{} instead of thebibliography. Creates a .bib file alongside the .tex file.
- Returns:
The path to the written .tex file.
- Return type:
Path
Examples
>>> from scitex.msword import load_docx >>> from scitex.tex import export_tex >>> doc = load_docx("manuscript.docx") >>> export_tex(doc, "manuscript.tex") PosixPath('manuscript.tex')
>>> # Export for IEEE conference >>> export_tex(doc, "manuscript.tex", journal_preset="ieee")
>>> # Export with custom image directory >>> export_tex(doc, "manuscript.tex", image_dir="./figures")
- scitex.tex.compile_tex(tex_path, output_dir=None, compiler='pdflatex', runs=2, clean=True, timeout=120)[source]
Compile a LaTeX file to PDF.
- Parameters:
tex_path (str | Path) – Path to the .tex file.
output_dir (str | Path | None) – Output directory for PDF. If None, uses same directory as tex file.
compiler (str) – LaTeX compiler to use: “pdflatex”, “xelatex”, “lualatex”, or “latexmk”. Default is “pdflatex”.
runs (int) – Number of compilation passes (for references/ToC). Default is 2. Ignored if compiler is “latexmk”.
clean (bool) – Remove auxiliary files (.aux, .log, .out, etc.) after compilation. Default is True.
timeout (int) – Timeout in seconds for each compilation pass. Default is 120.
- Returns:
Compilation result with success status, PDF path, and logs.
- Return type:
Examples
>>> from scitex.tex import compile_tex >>> result = compile_tex("manuscript.tex") >>> if result.success: ... print(f"PDF created: {result.pdf_path}") ... else: ... print(f"Errors: {result.errors}")
>>> # Use latexmk for automatic multi-pass compilation >>> result = compile_tex("manuscript.tex", compiler="latexmk")
Notes
Requires LaTeX to be installed on the system (texlive, miktex, etc.).
- class scitex.tex.CompileResult(success, pdf_path, exit_code, stdout, stderr, log_content='', errors=None, warnings=None)[source]
Bases:
objectResult of LaTeX compilation.
- pdf_path
Path to generated PDF, or None if failed.
- Type:
Path | None
- scitex.tex.preview(tex_str_list, enable_fallback=True)[source]
Generate a preview of LaTeX strings with automatic fallback.
- Parameters:
- Returns:
Figure containing the previews
- Return type:
Examples
>>> tex_strings = ["x^2", r"\sum_{i=1}^n i", r"\alpha + \beta"] >>> fig = preview(tex_strings) >>> scitex.plt.show()
Notes
If LaTeX rendering fails, this function automatically falls back to mathtext or unicode alternatives while preserving the preview layout.
- scitex.tex.to_vec(v_str, enable_fallback=True, fallback_strategy='auto')[source]
Convert a string to LaTeX vector notation with automatic fallback.
- Parameters:
- Returns:
LaTeX representation of the vector with automatic fallback
- Return type:
Examples
>>> vector = to_vec("AB") >>> print(vector) # LaTeX: \overrightarrow{\mathrm{AB}}
>>> vector = to_vec("AB") # Falls back to unicode if LaTeX fails >>> print(vector) # Unicode: A⃗B or AB⃗
Notes
If LaTeX rendering fails, this function automatically falls back to: - mathtext: Uses matplotlib’s built-in math rendering - unicode: Uses Unicode vector symbols (⃗) - plain: Returns plain text with “vec()” notation