Skip to main content

Module pathname

Module pathname 

Source
Expand description

helper methods for file system paths

Structs§

ConfinementGuard
Keeps a conversion confined on this thread; dropping it restores what was there before.
ConfinementSnapshot
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).
InputConfinement
The roots a confined conversion reads from besides the TeX installation, as the front end knows them.
PathnameFindOptions
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-level LaTeXML::Package::FindFile_aux, which calls pathname_kpsewhich after pathname_find returns empty. Keep this struct directory-search-only for parity.
TrimmedRoot
A root variable whose trailing separator a [crate::Kpaths] construction trimmed.

Enums§

KpathseaBackend
Which kpathsea backend this process resolved. Reported by kpathsea_backend so 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’ canonicalize puts 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 containing texmf-dist (i.e. a real TeX Live root — Debian’s /usr and other yearless layouts return None). Shared by the kpathsea backend agreement probe above; latexml_engine::dump_paths keys its dump-year detection off the same variable. The ambient kpsewhich -var-value=SELFAUTOPARENT output, memoized for the process so select_kpaths and latexml_engine::dump_paths share one spawn.
ambient_kpsewhich_version
The ambient kpsewhich --version banner (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 (in latexml_engine; the year-based latex-dump staleness check in turn consumes that detected year) — so kpsewhich is spawned at most once. Returns None if 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::canonicalize as a path the rest of the system can read: on Windows std returns the verbatim form (\\?\C:\dir\f.tex), which is dropped back to C:\dir\f.tex when 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 — \graphicspath entries \\?\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, at initialize_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 roots and the TeX installation until the guard drops. An environment TEXINPUTS directory 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; None unconfined.
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, as canonical reads it, where Perl’s pathname_canonical reads 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’s pathname_type preserves 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 pathname using the options search configuration. Mirrors Perl pathname_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.STY referenced as PASJ95.sty) — Perl’s regex pair pushes both strict and /i matches and returns the strict ones if any exist, otherwise the case-insensitive matches. kpsewhich is the caller’s responsibility (see LaTeXML::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: Perl pathname_is_absolute, File::Spec’s file_name_is_absolute. On Windows a rooted path without a drive (/figs, \\figs) counts, as File::Spec::Win32 counts it, where Path::is_absolute asks for a drive; a drive-relative C:figs does not.
is_confined
Whether a conversion on this thread is confined.
is_contained
pathname relative to base when it lies underneath it (both made absolute against the cwd first), else None. Port of Perl’s pathname_is_contained (Util/Pathname.pm L179-186); a result that stays absolute (no common root: another Windows drive) is not contained either.
is_contained_resolved
is_contained whatever the spelling of either path: pathname’s directory and all of base resolved (both made absolute against the working directory first). A symbolic link inside base that leads out of it is outside.
is_kpse_path_var
Whether name is an environment variable that sets a kpathsea search path: every variable of kpathsea’s format table (kpsewhich --help-formats: the …INPUTS and …FONTS families, TEXBIB, TEXPICTS, TEXPSHEADERS, …), TEXMFDOTDIR and VARTEXFONTS (which the format paths expand outside the $TEXMF trees), and each of them in kpathsea’s per-program form (TEXINPUTS_latex, TEXINPUTS.latex). TEXMFCNF, OSFONTDIR and the TEXMF… 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 KPSE initialization so the answer is always the real one.
kpsewhich
search for a list of candidate names via the external kpsewhich utility returning the first path that is found
kpsewhich_tex_input
kpsewhich for names TeX opens with \openin (\IfFileExists, graphics.sty’s \Gin@getbase): only TeX’s input path is searched (web2c’s \openin asks kpathsea’s kpse_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 directory dir; None when either is missing. Both are canonicalized by std, so on Windows both keep the verbatim prefix canonicalize drops only under 260 characters, and a long path compares like a short one.
own_behalf
Run f with 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; None unconfined.
refuse
Error:refused_file for name, once per name looked for (a Warning, once, inside probing): 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 path lies 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’s name under whatever variants it tries (x.tex, then x): a variant refused on the way is reported, as name, only when the lookup finds nothing (\IfFileExists{/dev/null} tries /dev/null.tex first). An enclosing lookup’s name wins.
resolved
pathname made 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 directory resolved, 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 a and b name the same existing file (both canonicalized, 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), at path, 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
path without a leading Windows verbatim prefix (either spelling), for display.
tex_tool_command
A command for a TeX tool (kpsewhich, pdflatex, texlua, …) given texmf_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 kpsewhich spawns.
trim_texmf_root
A TEXMF root value without its trailing directory separators, or None when 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