Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/config/pdf.ts
6449 views
1
/*
2
* pdf.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
// union of metadata and command line flags which determine
9
import { FormatPandoc, FormatRender, PandocFlags, PdfEngine } from "./types.ts";
10
import {
11
kCiteMethod,
12
kLatexMakeIndex,
13
kLatexMakeIndexOpts,
14
kLatexTlmgrOpts,
15
kPdfEngine,
16
kPdfEngineOpt,
17
kPdfEngineOpts,
18
} from "./constants.ts";
19
20
export function bibEngine(defaults: FormatPandoc, flags?: PandocFlags) {
21
return flags?.natbib
22
? "natbib"
23
: flags?.biblatex
24
? "biblatex"
25
: defaults[kCiteMethod] === "natbib"
26
? "natbib"
27
: defaults[kCiteMethod] == "biblatex"
28
? "biblatex"
29
: undefined;
30
}
31
32
export function pdfEngine(
33
defaults: FormatPandoc,
34
render: FormatRender,
35
flags?: PandocFlags,
36
): PdfEngine {
37
// determine pdfengine
38
const pdfEngine =
39
(flags?.pdfEngine || defaults[kPdfEngine] as string || "pdflatex");
40
41
// collect all engine opts
42
const pdfEngineOpts = defaults[kPdfEngineOpts] || [];
43
if (defaults[kPdfEngineOpt]) {
44
pdfEngineOpts.push(defaults[kPdfEngineOpt] as string);
45
}
46
if (flags?.pdfEngineOpts) {
47
pdfEngineOpts.push(...flags?.pdfEngineOpts);
48
}
49
50
// index options
51
const indexEngine = render[kLatexMakeIndex];
52
const indexEngineOpts = render[kLatexMakeIndexOpts] || [];
53
if (flags?.makeIndexOpts) {
54
indexEngineOpts?.push(...flags?.makeIndexOpts);
55
}
56
57
// tlmgr options
58
const tlmgrOpts = render[kLatexTlmgrOpts] || [];
59
if (flags?.tlmgrOpts) {
60
tlmgrOpts?.push(...flags?.tlmgrOpts);
61
}
62
63
return {
64
pdfEngine,
65
pdfEngineOpts,
66
bibEngine: bibEngine(defaults, flags),
67
indexEngine,
68
indexEngineOpts,
69
tlmgrOpts,
70
};
71
}
72
73
export function isLatexPdfEngine(engine: PdfEngine) {
74
return ["pdflatex", "xelatex", "lualatex", "latexmk"].includes(
75
engine.pdfEngine,
76
);
77
}
78
79