Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/tools/impl/tinytex-info.ts
12921 views
1
/*
2
* tools-info.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*/
6
7
import { expandPath, safeExistsSync } from "../../core/path.ts";
8
import { join } from "../../deno_ral/path.ts";
9
import { getenv } from "../../core/env.ts";
10
11
import { existsSync } from "../../deno_ral/fs.ts";
12
import { os as platformOs } from "../../deno_ral/platform.ts";
13
14
export function hasTinyTex(): boolean {
15
const binDir = tinyTexBinDir();
16
if (!binDir) {
17
return false; // No bin directory found
18
}
19
20
// Check for tlmgr binary (critical package manager)
21
const tlmgrBinary = platformOs === "windows" ? "tlmgr.bat" : "tlmgr";
22
const tlmgrPath = join(binDir, tlmgrBinary);
23
return safeExistsSync(tlmgrPath);
24
}
25
26
export function tinyTexInstallDir(): string | undefined {
27
switch (platformOs) {
28
case "windows": {
29
let appDir = getenv("APPDATA", undefined);
30
// use ProgramData if APPDATA is not set or contains spaces or non-ASCII characters
31
if (!appDir || !appDir.match(/^[!-~]+$/)) {
32
appDir = getenv("ProgramData", undefined);
33
}
34
return expandPath(join(appDir, "TinyTeX"));
35
}
36
case "linux":
37
return expandPath("~/.TinyTeX");
38
case "darwin":
39
return expandPath("~/Library/TinyTeX");
40
default:
41
return undefined;
42
}
43
}
44
45
export function tinyTexBinDir(): string | undefined {
46
const basePath = tinyTexInstallDir();
47
if (basePath) {
48
switch (platformOs) {
49
case "windows": {
50
// TeX Live 2023 use windows now. Previous version were using win32
51
const winPath = join(basePath, "bin\\win32\\");
52
if (safeExistsSync(winPath)) return winPath;
53
return join(basePath, "bin\\windows\\");
54
}
55
case "linux": {
56
const linuxPath = join(basePath, `bin/${Deno.build.arch}-linux`);
57
if (safeExistsSync(linuxPath)) return linuxPath;
58
return undefined;
59
}
60
case "darwin": {
61
const darwinPath = join(basePath, "bin/universal-darwin");
62
if (safeExistsSync(darwinPath)) return darwinPath;
63
return undefined;
64
}
65
default:
66
return undefined;
67
}
68
} else {
69
return undefined;
70
}
71
}
72
73