Skip to content

Commit 1110222

Browse files
committed
Properly handle latexmk pdf engine
- We need to be passing a pdf engine (e.g. `pdf` by default) when using `latexmk` - But users may also pass an engine using `pdf-engine-opts`, so respect that - flags based upon https://github.com/jgm/pandoc/blob/87f4247d9e95ee545c0654fc06e6e295da360221/src/Text/Pandoc/PDF.hs#L383 - fixes 3359
1 parent 07c2945 commit 1110222

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

src/command/render/latexmk/latex.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export async function hasLatexDistribution() {
4141
}
4242
}
4343

44+
const kLatexMkEngineFlags = [
45+
"-pdf",
46+
"-pdfdvi",
47+
"-pdfps",
48+
"-pdflua",
49+
"-pdfxe",
50+
"-pdf-",
51+
];
52+
4453
// Runs the Pdf engine
4554
export async function runPdfEngine(
4655
input: string,
@@ -65,7 +74,26 @@ export async function runPdfEngine(
6574
});
6675

6776
// build pdf engine command line
68-
const args = ["-interaction=batchmode", "-halt-on-error"];
77+
// ensure that we provide latexmk with its require custom options
78+
// Note that users may control the latexmk engine options, but
79+
// if not specified, we should provide a default
80+
const computeEngineArgs = () => {
81+
if (engine.pdfEngine === "latexmk") {
82+
const engineArgs = ["-interaction=batchmode", "-halt-on-error"];
83+
if (
84+
!engine.pdfEngineOpts || engine.pdfEngineOpts.find((opt) => {
85+
return kLatexMkEngineFlags.includes(opt);
86+
}) === undefined
87+
) {
88+
engineArgs.push("-pdf");
89+
}
90+
engineArgs.push("-quiet");
91+
return engineArgs;
92+
} else {
93+
return ["-interaction=batchmode", "-halt-on-error"];
94+
}
95+
};
96+
const args = computeEngineArgs();
6997

7098
// output directory
7199
if (outputDir !== undefined) {

src/command/render/latexmk/latexmk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function useQuartoLatexmk(
4141
// if we are creating pdf output
4242
if (["beamer", "pdf"].includes(to || "") && ext === "pdf") {
4343
const engine = pdfEngine(format.pandoc, format.render, flags);
44-
return isLatexPdfEngine(engine) && engine.pdfEngine !== "latexmk";
44+
return isLatexPdfEngine(engine);
4545
}
4646

4747
// default to false
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "MEW"
3+
format:
4+
pdf:
5+
pdf-engine: latexmk
6+
---
7+
8+
## Quarto
9+
10+
Quarto enables you to weave together content and executable code into a finished document.
11+
To learn more about Quarto see <https://quarto.org>.
12+
13+
```{r}
14+
1 + 1
15+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "MEW"
3+
format:
4+
pdf:
5+
pdf-engine: latexmk
6+
pdf-engine-opts: ["-pdflua"]
7+
---
8+
9+
## Quarto
10+
11+
Quarto enables you to weave together content and executable code into a finished document.
12+
To learn more about Quarto see <https://quarto.org>.
13+
14+
```{r}
15+
1 + 1
16+
```

0 commit comments

Comments
 (0)