Expand description
helper methods for file system paths
Structs§
- Confinement
Guard - Keeps a conversion confined on this thread; dropping it restores what was there before.
- Confinement
Snapshot - A confined conversion as a render worker takes it over: its roots, the names refused and the search directories dropped already (each reported once for the run).
- Input
Confinement - The roots a confined conversion reads from besides the TeX installation, as the front end knows them.
- Pathname
Find Options - configuration for filesystem search.
Mirrors Perl
LaTeXML::Util::Pathname::pathname_find’s named-arg options; kpsewhich-fallback is NOT one of them — that lives in higher-levelLaTeXML::Package::FindFile_aux, which callspathname_kpsewhichafterpathname_findreturns empty. Keep this struct directory-search-only for parity. - Trimmed
Root - A root variable whose trailing separator a [
crate::Kpaths] construction trimmed.
Enums§
- Kpathsea
Backend - Which kpathsea backend this process resolved. Reported by
kpathsea_backendso a host-resolution problem is diagnosable from the log instead of surfacing only as indistinguishable “can’t find file” errors.
Constants§
- TEXMF_
ROOT_ VARS - The TEXMF tree roots that texmf.cnf joins with
/into the search paths. Search-path specs (TEXINPUTS,TEXMFCNF,TEXMF, …) are not roots: their//is kpathsea’s recursive search, written on purpose. - WINDOWS_
VERBATIM_ PREFIXES - The verbatim prefix Windows’
canonicalizeputs before a path (\\?\C:\…), and its forward-slash spelling once the separators are normalised (//?/C:/…). A path prefix, not a TeX token: the kernel token-spelling pin counts it here, once.
Functions§
- absolute
- convert a (possibly relative) file path to an absolute one
- ambient_
kpsewhich_ selfautoparent - The ambient
kpsewhich -var-value=SELFAUTOPARENT, memoized, validated to be a directory containingtexmf-dist(i.e. a real TeX Live root — Debian’s/usrand other yearless layouts returnNone). Shared by the kpathsea backend agreement probe above;latexml_engine::dump_pathskeys its dump-year detection off the same variable. The ambientkpsewhich -var-value=SELFAUTOPARENToutput, memoized for the process soselect_kpathsandlatexml_engine::dump_pathsshare one spawn. - ambient_
kpsewhich_ version - The ambient
kpsewhich --versionbanner (full stdout), memoized for the process. It is a global property of the host TeX install, and several consumers read it — kpathsea backend selection (select_kpaths) and ambient-year detection (inlatexml_engine; the year-based latex-dump staleness check in turn consumes that detected year) — sokpsewhichis spawned at most once. ReturnsNoneif kpsewhich is absent or the call fails. - candidate_
pathnames - It’s presumably cheep to concatinate all the pathnames, relative to the cost of testing for files, and this simplifies overall.
- canonical
- Canonicalize a pathname by simplifying redundant separators,
.and..components. Matches Perl’s pathname_canonical from Pathname.pm. - canonicalize
std::fs::canonicalizeas a path the rest of the system can read: on Windows std returns the verbatim form (\\?\C:\dir\f.tex), which is dropped back toC:\dir\f.texwhen that names the same file (a drive path; a\\?\UNC\…share or an over-long path keeps it). Kept verbatim, the prefix reached the source directory and every path built from it —\graphicspathentries\\?\C:\…\tmp/figs/that matched no file, EPS candidates listed twice, locators printed as//?/C:/….- clear_
kpsewhich_ memo - Clear the per-thread kpsewhich memo. Called at the start of every
conversion (
reset_conversion_state, atinitialize_report): the persistent (non-harness) cortex_worker runs many papers per thread, and a cached cwd-relative MISS from paper A (kpathsea’s path spec includes.) would wrongly persist into paper B (PR_READINESS should-fix 12). - clear_
nocase_ dir_ cache - Drop the thread-local case-insensitive directory listing cache.
Called at each conversion start (
crate::reset_conversion_state) so a long-lived worker never carries a cached listing across conversions even within a coarse filesystem mtime tick. - concat
- combine a directory and a base name into a full path
- confine
- Confine this thread’s reads to
rootsand the TeX installation until the guard drops. An environmentTEXINPUTSdirectory outside them is not read; the session says so once per directory, pointing to--path. - confinement_
snapshot - This thread’s confinement, to carry into a render worker;
Noneunconfined. - cwd
- returns the current working directory
- cwd_
allowed - Whether this conversion may search the working directory: only when it lies in a document or operator root.
- directory
- obtain the directory portion of a pathname (via
Path::parent) Matches Perl’s pathname_directory. - dot_
relative .//x(and././/x) as TeX opens it:x, relative to the working directory, ascanonicalreads it, where Perl’spathname_canonicalreads the absolute/x(KNOWN_PERL_ERRORS #1343; 1801.09240’s\input{\djfolder /dj}).- extension
- obtain the extension portion of a pathname (via
Path::extension). Perl’spathname_typepreserves case; callers that need a lowercased form should apply.to_ascii_lowercase()themselves. - file_
name - transform to a canonical file name, via
Path::file_name - file_
stem - transform to a base name (via
Path::file_stem) Note: Perl’s pathname_name returns the stem without extension and without case change. - find
- find the requested
pathnameusing theoptionssearch configuration. Mirrors Perlpathname_find(LaTeXML/Util/Pathname.pm L376-392): directory search with strict-case match preferred, falling back to a case-insensitive directory scan. The fallback is required for arxiv papers shipping uppercase filenames (e.g.PASJ95.STYreferenced asPASJ95.sty) — Perl’s regex pair pushes both strict and/imatches and returns the strict ones if any exist, otherwise the case-insensitive matches. kpsewhich is the caller’s responsibility (seeLaTeXML::Package::FindFile_aux). - findall
- Find all matching files (like pathname_findall). Port of Perl’s pathname_findall($pathname, %options).
- init_
kpathsea - Construct the process-wide kpathsea handle NOW, on the calling thread, before any other thread exists that might read the environment.
- is_
absolute - Whether
path, canonical (a leading~expanded), is absolute: Perlpathname_is_absolute, File::Spec’sfile_name_is_absolute. On Windows a rooted path without a drive (/figs,\\figs) counts, asFile::Spec::Win32counts it, wherePath::is_absoluteasks for a drive; a drive-relativeC:figsdoes not. - is_
confined - Whether a conversion on this thread is confined.
- is_
contained pathnamerelative tobasewhen it lies underneath it (both made absolute against the cwd first), elseNone. Port of Perl’spathname_is_contained(Util/Pathname.pmL179-186); a result that stays absolute (no common root: another Windows drive) is not contained either.- is_
contained_ resolved is_containedwhatever the spelling of either path:pathname’s directory and all ofbaseresolved(both made absolute against the working directory first). A symbolic link insidebasethat leads out of it is outside.- is_
kpse_ path_ var - Whether
nameis an environment variable that sets a kpathsea search path: every variable of kpathsea’s format table (kpsewhich --help-formats: the…INPUTSand…FONTSfamilies,TEXBIB,TEXPICTS,TEXPSHEADERS, …),TEXMFDOTDIRandVARTEXFONTS(which the format paths expand outside the$TEXMFtrees), and each of them in kpathsea’s per-program form (TEXINPUTS_latex,TEXINPUTS.latex).TEXMFCNF,OSFONTDIRand theTEXMF…tree variables are the installation’s own configuration, trusted as the installation (docs/release/SAFETY.md). - is_
literaldata - checks if the path starts with the “literal:” protocol
- is_
nasty - check if pathname contains dangerous pieces
- is_raw
- Check whether a pathname is a raw TeX source or definition file. Perl: pathname_is_raw
- is_
readable_ file - A path TeX could open as a file: it exists and is not a directory (kpathsea’s
READABLE). - is_
reloadable - check whether a pathname is reloadable as a TeX definition
- is_url
- checks if the path is a conforming URL string
- kpathsea_
backend - The backend this process resolved, with a short reason. Forces the
KPSEinitialization so the answer is always the real one. - kpsewhich
- search for a list of candidate names via the external
kpsewhichutility returning the first path that is found - kpsewhich_
tex_ input kpsewhichfor names TeX opens with\openin(\IfFileExists, graphics.sty’s\Gin@getbase): only TeX’s input path is searched (web2c’s\openinasks kpathsea’skpse_tex_format), not first the format a name’s suffix suggests, which for a suffix kpathsea does not know (.pdf,.png) is that same search done twice.- make
- Compose a pathname from dir, name, type components. Port of Perl’s pathname_make(%pieces).
- opens_
inside - Whether the existing
path, as the system opens it (every link followed, a link before a..first), lies in the existing directorydir;Nonewhen either is missing. Both are canonicalized by std, so on Windows both keep the verbatim prefixcanonicalizedrops only under 260 characters, and a long path compares like a short one. - own_
behalf - Run
fwith confinement lifted: the engine’s own reads on its own behalf (the compiled schema, its resources), never a name a document gave. - prewarm_
kpathsea - Force-initialize the kpathsea global state and warm up the per- format suffix tables.
- probing
- Run
f, a test of whether a file exists (\IfFileExists,\openin,\pdffilesize): a name refused on the way is a Warning and the document takes its not-found branch; a refused read stays an Error (DG 2026-11-26). The severity follows the construct, never whether the file exists. - protocol
- Note that this returns ONLY recognized protocols!
- read_
allowed - Whether this conversion may read
path(relative to the working directory, as the system opens it). Always true when unconfined. A name is judged by where it lies, as written, and by its root’s links; one with a..part, where it lands. - read_
roots - A confined conversion’s read roots (absolute, canonical): its document and operator roots, whose links must stay
inside them, and the TeX installation’s, matched by spelling;
Noneunconfined. - refuse
Error:refused_fileforname, once per name looked for (a Warning, once, insideprobing): it names a file outside every root. Inside a lookup (requested_as) the refusal waits for the lookup’s outcome and is the lookup’s name, whatever variants (x.tex,x) it tried.- refused_
exists - Whether
path, a name the roots refuse as the system opens it, names a file: a refusal is an Error (or a test’s Warning) only for a file that exists, and a missing one keeps the missing file’s outcome. Any letter case counts, for every refused name alike (most lookups fall back to a case-insensitive match, kpathsea’s casefold; an absolute name has none, and is refused the same way so that a refusal never depends on the file system’s case sensitivity). Only “a file” or “none” is learnt of outside, in the log. - refused_
inside - Whether
pathlies in a document or operator root but is refused there: it, or a directory on its way, is a link leading out of the root or dangling (the root’s own contents, so this tells nothing of what lies outside). - relative
- Make a pathname relative to a base directory. Port of Perl’s pathname_relative($pathname, $base).
- requested_
as - Run
f, a lookup of the document’snameunder whatever variants it tries (x.tex, thenx): a variant refused on the way is reported, asname, only when the lookup finds nothing (\IfFileExists{/dev/null}tries/dev/null.texfirst). An enclosing lookup’s name wins. - resolved
pathnamemade absolute with every directory that exists named as the file system names it: symbolic links followed and, on Windows, 8.3 short names expanded (RUNNER~1→runneradmin) and letters cased as stored. The longest existing prefix is resolved and the components that do not exist yet are kept as written, so a directory about to be made resolves like one that is already there. Two paths in this form agree however each was obtained —current_dir,canonicalize, a command-line argument — which a lexical comparison does not: the rc3 Windows release guards compared a destination not yet made, kept lexical (C:/Users/RUNNER~1/…), with the canonical form of its existing parent (C:/Users/runneradmin/…), so an image inside the document’s folder looked outside it.- resolved_
directory_ of pathname’s directoryresolved, its last component kept as written: a file that is itself a symbolic link keeps its own name, as a copy over it replaces the link and never writes through it.- resume
- Confine a render worker’s thread as its parent was (
confinement_snapshot): a refusal its parent reported is not reported again, and the session’s notices are the parent’s. - same_
file - Whether
aandbname the same existing file (bothcanonicalized, so links and spellings agree); false when either does not exist. - search_
dir_ allowed - Whether a search directory a document names
dir(\graphicspath,\input@path), atpath, may be searched: when not, one Warning per directory and the caller drops it. - split
- Split the pathname into components (dir,name,type). If pathname is absolute, dir starts with volume or ‘/’
- strip_
windows_ verbatim_ prefix pathwithout a leading Windows verbatim prefix (either spelling), for display.- tex_
tool_ command - A command for a TeX tool (
kpsewhich,pdflatex,texlua, …) giventexmf_root_env: a root ending in/would make it walk the whole tree and resolve nothing (issue #950). Sets nothing when no root has one. - texmf_
root_ env - The TEXMF root variables set now with a trailing separator, each with its trimmed value (issue #950): what a
spawned TeX tool must be given, as the kpathsea crate gives the linked library and its own
kpsewhichspawns. - trim_
texmf_ root - A TEXMF root
valuewithout its trailing directory separators, orNonewhen there is none to trim. - trimmed_
texmf_ roots - The TEXMF root variables whose trailing separator the kpathsea crate trimmed (>= 0.3.6, issue #950), for the
conversion log. Forces the kpathsea initialization, like
kpathsea_backend. - url_
split - Simple logic for splitting a URL into protocol://base/path