Skip to main content

Module main_tex

Module main_tex 

Source
Expand description

Main .tex discovery for directory inputs.

Equivalent to the binary’s --whatsin=directory mode: given a source directory, return the path of the file the converter should treat as the top-level entrypoint. Lifted from bin/latexml_oxide.rs so embedders (e.g. ar5iv-editor, cortex_worker) can run the same heuristic without shelling out.

Detection order:

  1. 00README.json “sources” entry with usage == "toplevel" (modern arXiv format).
  2. 00README.XXX line tagged toplevelfile (legacy arXiv). Lines tagged ignore exclude the named file from later heuristic scanning (Perl Pack.pm::detect_source unlinks them; we filter the candidate list instead — safer if the directory isn’t a sandbox).
  3. Pack.pm-derived likelihood scoring across every .tex / .txt / .ltx (and, as a fallback, every long-extensioned or extension-less file). Files vetoed by \input / \include references are excluded; \documentclass / \documentstyle and Mac-classic markers boost the score; bibtex / metafont / %auto-ignore / withdrawal sentinels disqualify.

Returns the absolute path of the chosen entry as a PathBuf. The Err arm carries a Perl-canonical Fatal:invalid:not_tex_source style message (matching what the binary printed before this lift).

Functions§

find_main_tex
Discover the main .tex file inside dir, mirroring the binary’s --whatsin=directory heuristic. The returned path is rooted at dir. Errors carry a human-readable diagnostic on Fatal: failure modes (PDF mis-named as TeX, only %auto-ignore files, no TeX at all).
is_pdf_magic