Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/render/latexmk/latexmk.ts
3587 views
1
/*
2
* latexmk.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import {
8
kLatexAutoInstall,
9
kLatexAutoMk,
10
kLatexClean,
11
kLatexInputPaths,
12
kLatexMaxRuns,
13
kLatexMinRuns,
14
kLatexOutputDir,
15
kLatexTinyTex,
16
kOutputExt,
17
} from "../../../config/constants.ts";
18
import { Format } from "../../../config/types.ts";
19
import { isLatexPdfEngine, pdfEngine } from "../../../config/pdf.ts";
20
21
import { PandocOptions, RenderFlags, RenderOptions } from "../types.ts";
22
import { OutputRecipe } from "../types.ts";
23
import { generatePdf } from "./pdf.ts";
24
import { LatexmkOptions } from "./types.ts";
25
import { texToPdfOutputRecipe } from "../output-tex.ts";
26
import { join } from "../../../deno_ral/path.ts";
27
28
export function useQuartoLatexmk(
29
format: Format,
30
flags?: RenderFlags,
31
) {
32
// check writer and extension
33
const to = format.pandoc.to;
34
const ext = format.render[kOutputExt] || "html";
35
36
// Check whether explicitly disabled
37
if (format.render[kLatexAutoMk] === false) {
38
return false;
39
}
40
41
// if we are creating pdf output
42
if (["beamer", "pdf"].includes(to || "") && ext === "pdf") {
43
const engine = pdfEngine(format.pandoc, format.render, flags);
44
return isLatexPdfEngine(engine);
45
}
46
47
// default to false
48
return false;
49
}
50
51
export function quartoLatexmkOutputRecipe(
52
input: string,
53
finalOutput: string,
54
options: RenderOptions,
55
format: Format,
56
): OutputRecipe {
57
// output dir
58
const outputDir = format.render[kLatexOutputDir];
59
60
const generate = (
61
input: string,
62
format: Format,
63
pandocOptions: PandocOptions,
64
): Promise<string> => {
65
// Resolve any tex input paths
66
const texInputDirs: string[] = [];
67
if (format.render[kLatexInputPaths]) {
68
texInputDirs.push(...format.render[kLatexInputPaths]!);
69
}
70
71
// determine latexmk options
72
const mkOptions: LatexmkOptions = {
73
input,
74
engine: pdfEngine(format.pandoc, format.render, pandocOptions.flags),
75
autoInstall: format.render[kLatexAutoInstall],
76
autoMk: format.render[kLatexAutoMk],
77
minRuns: format.render[kLatexMinRuns],
78
maxRuns: format.render[kLatexMaxRuns],
79
tinyTex: format.render[kLatexTinyTex],
80
texInputDirs,
81
outputDir: outputDir === null ? undefined : outputDir,
82
clean: !options.flags?.debug && format.render[kLatexClean] !== false,
83
quiet: pandocOptions.flags?.quiet,
84
};
85
86
// run latexmk
87
return generatePdf(mkOptions);
88
};
89
90
const computePath = (texStem: string, inputDir: string, format: Format) => {
91
const mkOutputdir = format.render[kLatexOutputDir];
92
return mkOutputdir
93
? join(mkOutputdir, texStem + ".pdf")
94
: join(inputDir, texStem + ".pdf");
95
};
96
97
return texToPdfOutputRecipe(
98
input,
99
finalOutput,
100
options,
101
format,
102
"latex",
103
{
104
generate,
105
computePath,
106
},
107
outputDir,
108
);
109
}
110
111