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). confined is whether the conversion will read confined (OXIDIZED_DESIGN_DIVERGENCES #1183: an archive input, --paranoid-input, the cortex worker): then only a file that opens inside dir is a candidate or a .bbl, and a link leading out of it counts for nothing; unconfined, a link is followed, as Perl’s detection does.
find_top_level_texs
Ordered list of top-level .tex files: the main document first, then any Supplementary-Material documents that ship alongside it. find_main_tex returns element 0 of this list; embedders that want to convert the whole submission (main + supplements, appended in order — arXiv’s multi-top-level model, submit_legacy_differences) drive off the full list.
is_pdf_magic
main_tex_in
find_main_tex; report warns of a 00README entry outside dir (readme_entry) — the language server’s detection passes false, as its warnings would only pile up unreported.
readme_entry
The file name a 00README marks top-level, inside dir; None when it is not a file (., a folder), or, with a Warning:archive:path, when name is absolute, has a .. or resolves outside dir (Perl Util/Pack.pm detect_source L78, L93; OXIDIZED_DESIGN_DIVERGENCES #1166).
readme_text
The text of the 00README file name in dir; confined, only when it opens inside it (as collect_tex_files keeps a file).