Skip to main content

kpsewhich

Function kpsewhich 

Source
pub fn kpsewhich(candidates: &[&str]) -> Option<String>
Expand description

search for a list of candidate names via the external kpsewhich utility returning the first path that is found

Memoized (hits AND misses) per thread, keyed by the candidate list (Principle 5, closed by the 2026-07-02 perf audit): repeated lookups of the same missing asset (e.g. a figure referenced by many \includegraphics) otherwise re-probe kpathsea each time — a full fork-exec per probe on the subprocess-kpsewhich backend (portable builds without linked libkpathsea), a cheaper but nonzero library walk on the in-process backend. Results are stable for a fixed texmf tree (the same assumption kpathsea’s own ls-R cache makes); the memo clears per conversion via clear_kpsewhich_memo.

With neither backend (no TeX installation) every lookup answers None, silently, as Perl’s pathname_kpsewhich does without a kpsewhich (Pathname.pm:395-403); a TeX installation is optional here. Each conversion’s log names the backend (Info:kpathsea:backend, Converter::initialize_session), so a resolver that never came up is not mistaken for a missing file (issue #304).