Coverage for src / local_deep_research / exporters / latex_exporter.py: 100%
29 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 23:55 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 23:55 +0000
1"""LaTeX export service.
3This module provides the LaTeXExporter class that wraps the existing
4LaTeXExporter implementation from text_optimization.citation_formatter.
5"""
7from typing import Optional
9from loguru import logger
11from .base import BaseExporter, ExportOptions, ExportResult
12from .registry import ExporterRegistry
15@ExporterRegistry.register
16class LaTeXExporter(BaseExporter):
17 """LaTeX exporter using the existing LaTeXExporter implementation.
19 This exporter converts markdown content to LaTeX format suitable for
20 compilation with pdflatex or similar LaTeX processors.
21 """
23 def __init__(self):
24 """Initialize LaTeX exporter."""
25 # Import here to avoid circular imports
26 from ..text_optimization.citation_formatter import (
27 LaTeXExporter as LegacyLaTeXExporter,
28 )
30 self._legacy = LegacyLaTeXExporter()
32 @property
33 def format_name(self) -> str:
34 return "latex"
36 @property
37 def file_extension(self) -> str:
38 return ".tex"
40 @property
41 def mimetype(self) -> str:
42 return "text/plain"
44 def export(
45 self,
46 markdown_content: str,
47 options: Optional[ExportOptions] = None,
48 ) -> ExportResult:
49 """Convert markdown content to LaTeX.
51 Args:
52 markdown_content: The markdown text to convert
53 options: Optional export options (title, metadata)
55 Returns:
56 ExportResult with LaTeX content as UTF-8 bytes, filename, and mimetype
58 Raises:
59 ValueError: If content exceeds maximum size limit
60 """
61 try:
62 # Check content size limit to prevent OOM errors
63 self._validate_content_size(markdown_content)
65 options = options or ExportOptions()
67 content = self._legacy.export_to_latex(markdown_content)
68 filename = self._generate_safe_filename(options.title)
70 logger.info(
71 f"Generated LaTeX in memory, size: {len(content)} bytes"
72 )
74 return ExportResult(
75 content=content.encode("utf-8"),
76 filename=filename,
77 mimetype=self.mimetype,
78 )
80 except Exception:
81 logger.exception("Error generating LaTeX")
82 raise