Skip to main content

Kpathsea

Struct Kpathsea 

Source
pub struct Kpathsea { /* private fields */ }
Expand description

A configured kpathsea instance.

Implementations§

Source§

impl Kpathsea

Source

pub fn set_output_directory(&mut self, dir: Option<String>)

The output directory that stands for TEXMF_OUTPUT_DIRECTORY in the checks of Kpathsea::name_ok, instead of the environment’s: LuaTeX sets the variable from -output-directory.

Source

pub fn name_ok( &self, name: &str, access: Access, extended: bool, ) -> Result<(), Refusal>

Checks that file name may be opened for access, like kpsewhich -safe-in-name and its siblings; extended is LuaTeX’s extended check, which also accepts the cache trees.

Source§

impl Kpathsea

Source

pub fn new(options: Options) -> Result<Self, Error>

Initializes kpathsea from the process environment.

Examples found in repository?
examples/kpsewhich.rs (line 13)
4fn main() {
5    let args: Vec<String> = std::env::args().collect();
6    let fmt = match args.get(1).map(String::as_str) {
7        Some("lua") => FileFormat::Lua,
8        Some("fmt") => FileFormat::Fmt,
9        Some("otf") => FileFormat::OpenType,
10        Some("tfm") => FileFormat::Tfm,
11        _ => FileFormat::Tex,
12    };
13    let mut k = Kpathsea::new(Options::lualatex()).unwrap();
14    let t = std::time::Instant::now();
15    let found = k.find_file(&args[2], fmt);
16    eprintln!("path: {:?}", k.search_path(fmt));
17    println!("{found:?} ({:?})", t.elapsed());
18}
More examples
Hide additional examples
examples/kpsetime.rs (line 8)
4fn main() {
5    let t = std::time::Instant::now();
6    let mut o = Options::lualatex();
7    o.cache_dir = Some(std::env::temp_dir().join("retex-kpse-test"));
8    let mut k = Kpathsea::new(o).unwrap();
9    let init = t.elapsed();
10    let t = std::time::Instant::now();
11    for n in [
12        "latex.ltx",
13        "article.cls",
14        "size10.clo",
15        "lmroman10-regular.otf",
16        "ltluatex.lua",
17    ] {
18        let f = if n.ends_with(".otf") {
19            FileFormat::OpenType
20        } else if n.ends_with(".lua") {
21            FileFormat::Lua
22        } else {
23            FileFormat::Tex
24        };
25        let _ = k.find_file(n, f);
26    }
27    println!("init {init:?}, 5 lookups {:?}", t.elapsed());
28}
Source

pub fn with_env(options: Options, env: Box<dyn Env>) -> Result<Self, Error>

Initializes kpathsea with a custom environment.

Source

pub fn progname(&self) -> &str

The program name.

Source

pub fn engine(&self) -> &str

The engine name.

Source

pub fn cache_dir(&self) -> Option<&Path>

The directory of retex’s cache files, if any.

Source

pub fn installed_names(&self, suffix: &str) -> Vec<String>

The names of the files ending with suffix in the ls-R databases (each once, sorted): what is installed, for suggestions.

Source

pub fn var_value(&self, name: &str) -> Option<String>

Returns the expanded value of variable name, like kpsewhich -var-value. Braces are not expanded.

Source

pub fn search_path(&mut self, format: FileFormat) -> &[String]

The fully expanded search path for format, one element per entry. Elements may start with !! and contain //.

Examples found in repository?
examples/kpsewhich.rs (line 16)
4fn main() {
5    let args: Vec<String> = std::env::args().collect();
6    let fmt = match args.get(1).map(String::as_str) {
7        Some("lua") => FileFormat::Lua,
8        Some("fmt") => FileFormat::Fmt,
9        Some("otf") => FileFormat::OpenType,
10        Some("tfm") => FileFormat::Tfm,
11        _ => FileFormat::Tex,
12    };
13    let mut k = Kpathsea::new(Options::lualatex()).unwrap();
14    let t = std::time::Instant::now();
15    let found = k.find_file(&args[2], fmt);
16    eprintln!("path: {:?}", k.search_path(fmt));
17    println!("{found:?} ({:?})", t.elapsed());
18}
Source

pub fn find_file(&mut self, name: &str, format: FileFormat) -> Option<PathBuf>

Finds the first file matching name in the search path of format, like kpsewhich -format=… name.

Examples found in repository?
examples/kpsewhich.rs (line 15)
4fn main() {
5    let args: Vec<String> = std::env::args().collect();
6    let fmt = match args.get(1).map(String::as_str) {
7        Some("lua") => FileFormat::Lua,
8        Some("fmt") => FileFormat::Fmt,
9        Some("otf") => FileFormat::OpenType,
10        Some("tfm") => FileFormat::Tfm,
11        _ => FileFormat::Tex,
12    };
13    let mut k = Kpathsea::new(Options::lualatex()).unwrap();
14    let t = std::time::Instant::now();
15    let found = k.find_file(&args[2], fmt);
16    eprintln!("path: {:?}", k.search_path(fmt));
17    println!("{found:?} ({:?})", t.elapsed());
18}
More examples
Hide additional examples
examples/kpsetime.rs (line 25)
4fn main() {
5    let t = std::time::Instant::now();
6    let mut o = Options::lualatex();
7    o.cache_dir = Some(std::env::temp_dir().join("retex-kpse-test"));
8    let mut k = Kpathsea::new(o).unwrap();
9    let init = t.elapsed();
10    let t = std::time::Instant::now();
11    for n in [
12        "latex.ltx",
13        "article.cls",
14        "size10.clo",
15        "lmroman10-regular.otf",
16        "ltluatex.lua",
17    ] {
18        let f = if n.ends_with(".otf") {
19            FileFormat::OpenType
20        } else if n.ends_with(".lua") {
21            FileFormat::Lua
22        } else {
23            FileFormat::Tex
24        };
25        let _ = k.find_file(n, f);
26    }
27    println!("init {init:?}, 5 lookups {:?}", t.elapsed());
28}

Trait Implementations§

Source§

impl Debug for Kpathsea

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.