UNPKG

myst-cli

Version:
32 lines (31 loc) 1.21 kB
import { makeExecutable, silentLogger } from 'myst-cli-utils'; import which from 'which'; export function isLatexmkAvailable() { return which.sync('latexmk', { nothrow: true }); } export function isMakeglossariesAvailable() { return which.sync('makeglossaries', { nothrow: true }); } export function isTlmgrAvailable() { return which.sync('tlmgr', { nothrow: true }); } export async function searchForPackage(session, sty, opts) { var _a; if (!isTlmgrAvailable()) { session.log.warn('tlmgr is not available, unable to search for LaTeX packages.'); return; } const searchCommand = `tlmgr search --global --file "/${sty}"`; const log = silentLogger(); session.log.debug(`Running command to search for package: "${sty}":\n\n ${searchCommand}\n\n`); try { const result = await makeExecutable(searchCommand, log, opts)(); session.log.debug(result); const libs = (_a = result.match(/\n([^\s]*):\n/g)) === null || _a === void 0 ? void 0 : _a.map((p) => p.trim().slice(0, -1)); return libs; } catch (error) { session.log.debug('Error searching for LaTeX packages from tlmgr'); return undefined; } }