docling-project/docling · error · ImportError
The 'pylatexenc' package is required to process LaTeX files.
Error message
The 'pylatexenc' package is required to process LaTeX files. Install it with `pip install 'docling-slim[format-latex]'`.
What it means
LatexDocumentBackend.__init__ raises ImportError before super().__init__() when pylatexenc is not installed, chaining the original import error. LaTeX support is an optional extra in docling-slim; the message names the exact extra to install.
Source
Thrown at docling/backend/latex/backend.py:66
from docling.backend.latex.engines.tectonic import TectonicEngine
class LatexDocumentBackend(
DeclarativeDocumentBackend,
MacroHandlerMixin,
EnvironmentHandlerMixin,
MathHandlerMixin,
TextHelperMixin,
TableHelperMixin,
):
def __init__(
self,
in_doc: InputDocument,
path_or_stream: Union[BytesIO, Path],
options: Optional[LatexBackendOptions] = None,
):
if not _PYLATEXENC_AVAILABLE:
raise ImportError(_INSTALL_HINT) from _PYLATEXENC_IMPORT_ERROR
if options is None:
options = LatexBackendOptions()
super().__init__(in_doc, path_or_stream, options)
self.options = LatexBackendOptions.model_validate(self.options)
self.labels: dict[str, bool] = {}
self._custom_macros: dict[str, str] = {}
self._custom_macro_num_args: dict[str, int] = {}
self._input_stack: set[str] = set()
self._tectonic_engine: TectonicEngine | None = None
self._tikz_executor: concurrent.futures.ThreadPoolExecutor | None = None
self._tikz_futures: list[concurrent.futures.Future] = []
self.latex_text = decode_latex_content(self.path_or_stream)
def is_valid(self) -> bool:
text = self.latex_text.strip()
if not text:
return False
return TrueView on GitHub (pinned to 61d76f1ff3)
Solutions
- Install the extra: pip install 'docling-slim[format-latex]'
- Or install full docling
- Add the extra to the deployment's dependency manifest so rebuilds keep it
Example fix
# before pip install docling-slim # after pip install 'docling-slim[format-latex]'
Defensive patterns
Strategy: validation
Validate before calling
try:
import pylatexenc # noqa: F401
except ImportError:
raise RuntimeError("Install: pip install 'docling-slim[format-latex]'") Try / catch
try:
result = converter.convert(src)
except ImportError as exc:
if 'pylatexenc' in str(exc):
install_or_skip('docling-slim[format-latex]')
raise Prevention
- Add the format-latex extra wherever LaTeX conversion is enabled
- Probe optional imports at startup for all accepted formats
When it happens
Trigger: Converting .tex files (InputFormat.LATEX) in an environment where docling-slim was installed without the format-latex extra, so `import pylatexenc` fails.
Common situations: Minimal deployment images; adding LaTeX conversion to an existing slim-based service without updating dependencies; lockfiles regenerated without the extra.
Related errors
- The 'mail-parser' package is required to process email files
- The 'beautifulsoup4' package is required to process HTML fil
- The 'marko' package is required to process Markdown files. I
- The 'python-oxmsg' package is required to process Outlook .m
- whisper is not installed. Please install it via `pip install
AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14).
Data as JSON: /api/errors/f3ee97c5597b7fab.
Report an issue: GitHub.