Skip to content

Commit 5a1f79a

Browse files
authored
Merge pull request #2428 from quarto-dev/feature/tinytex-stbl
TinyTeX improvements
2 parents d0feab1 + ea94c97 commit 5a1f79a

21 files changed

+412
-168
lines changed

news/changelog-1.2.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
- Support formats `bibtex`, `biblatex`, and `csljson`. When rendered to one of these formats any citations within the document will be rendered as the specified bibliography format.
7777
- Always add citeproc filter if `citeproc: true` is specified, even if there isn't a bibliography or references in the document (#2294)
7878

79+
## TinyTex
80+
81+
- `quarto install tool tinytex` will now install TinyTex even if a system installation of TeX is detected.
82+
- `quarto install tool tinytex` will no longer add TinyTex to the system path by default.
83+
- When rendering PDFs, Quarto will prefer an existing installation of TinyTex over a system Tex installation
84+
- To prevent Quarto from using an installation of TinyTex (if you'd prefer the system installation be used), set `latex-tinytex: false` in your project or document front matter.
85+
- To install TinyTex system wide, using the `--update-path` flag when installing (this will add TinyTex to the system path)
86+
7987
## Miscellaneous
8088

8189
- Render: ability to compose `--to all` with other formats (e.g. `--to all,json`)

src/command/install/cmd.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const installCommand = new Command()
2828
"--embed <extensionId>",
2929
"Embed this extension within another extension (used when authoring extensions).",
3030
)
31+
.option(
32+
"--update-path",
33+
"Update system path when a tool is installed",
34+
)
3135
.description(
3236
"Installs an extension or global dependency.",
3337
)
@@ -57,7 +61,7 @@ export const installCommand = new Command()
5761
)
5862
.action(
5963
async (
60-
options: { prompt?: boolean; embed?: string },
64+
options: { prompt?: boolean; embed?: string; updatePath?: boolean },
6165
type: string,
6266
target?: string,
6367
) => {
@@ -80,7 +84,12 @@ export const installCommand = new Command()
8084
// Install a tool
8185
if (target) {
8286
// Use the tool name
83-
await updateOrInstallTool(target, "install", options.prompt);
87+
await updateOrInstallTool(
88+
target,
89+
"install",
90+
options.prompt,
91+
options.updatePath,
92+
);
8493
} else {
8594
// Not provided, give the user a list to choose from
8695
const allTools = await loadTools();
@@ -91,7 +100,7 @@ export const installCommand = new Command()
91100
const toolTarget = await selectTool(allTools, "install");
92101
if (toolTarget) {
93102
info("");
94-
await installTool(toolTarget);
103+
await installTool(toolTarget, options.updatePath);
95104
}
96105
}
97106
}

src/command/remove/cmd.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export const removeCommand = new Command()
3939
"--embed <extensionId>",
4040
"Remove this extension from within another extension (used when authoring extensions).",
4141
)
42+
.option(
43+
"--update-path",
44+
"Update system path when a tool is installed",
45+
)
4246
.description(
4347
"Removes an extension or global dependency.",
4448
)
@@ -64,7 +68,7 @@ export const removeCommand = new Command()
6468
)
6569
.action(
6670
async (
67-
options: { prompt?: boolean; embed?: string },
71+
options: { prompt?: boolean; embed?: string; updatePath?: boolean },
6872
type: string,
6973
target?: string,
7074
) => {
@@ -130,7 +134,7 @@ export const removeCommand = new Command()
130134
// Process tool
131135
if (target) {
132136
// Explicitly provided
133-
await removeTool(target, options.prompt);
137+
await removeTool(target, options.prompt, options.updatePath);
134138
} else {
135139
// Not provided, give the user a list to choose from
136140
const allTools = await loadTools();

src/command/render/latexmk/latex.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
kLatexBodyMessageOptions,
2020
kLatexHeaderMessageOptions,
2121
} from "./types.ts";
22+
import { texLiveCmd, TexLiveContext } from "./texlive.ts";
2223

2324
export interface LatexCommandReponse {
2425
log: string;
@@ -43,6 +44,7 @@ export async function hasLatexDistribution() {
4344
export async function runPdfEngine(
4445
input: string,
4546
engine: PdfEngine,
47+
texLive: TexLiveContext,
4648
outputDir?: string,
4749
texInputDirs?: string[],
4850
pkgMgr?: PackageManager,
@@ -85,6 +87,7 @@ export async function runPdfEngine(
8587
pkgMgr,
8688
cwd,
8789
texInputDirs,
90+
texLive,
8891
},
8992
quiet,
9093
);
@@ -100,6 +103,7 @@ export async function runPdfEngine(
100103
// Run the index generation engine (currently hard coded to makeindex)
101104
export async function runIndexEngine(
102105
input: string,
106+
texLive: TexLiveContext,
103107
engine?: string,
104108
args?: string[],
105109
pkgMgr?: PackageManager,
@@ -119,6 +123,7 @@ export async function runIndexEngine(
119123
{
120124
cwd,
121125
pkgMgr,
126+
texLive,
122127
},
123128
quiet,
124129
);
@@ -134,6 +139,7 @@ export async function runBibEngine(
134139
engine: string,
135140
input: string,
136141
cwd: string,
142+
texLive: TexLiveContext,
137143
pkgMgr?: PackageManager,
138144
texInputDirs?: string[],
139145
quiet?: boolean,
@@ -153,6 +159,7 @@ export async function runBibEngine(
153159
pkgMgr,
154160
cwd,
155161
texInputDirs,
162+
texLive,
156163
},
157164
quiet,
158165
);
@@ -166,6 +173,7 @@ export interface LatexCommandContext {
166173
pkgMgr?: PackageManager;
167174
cwd?: string;
168175
texInputDirs?: string[];
176+
texLive: TexLiveContext;
169177
}
170178

171179
async function runLatexCommand(
@@ -174,8 +182,10 @@ async function runLatexCommand(
174182
context: LatexCommandContext,
175183
quiet?: boolean,
176184
): Promise<ProcessResult> {
185+
const fullLatexCmd = texLiveCmd(latexCmd, context.texLive);
186+
177187
const runOptions: Deno.RunOptions = {
178-
cmd: [latexCmd, ...args],
188+
cmd: [fullLatexCmd.fullPath, ...args],
179189
stdout: "piped",
180190
stderr: "piped",
181191
};

src/command/render/latexmk/latexmk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
kLatexMaxRuns,
1414
kLatexMinRuns,
1515
kLatexOutputDir,
16+
kLatexTinyTex,
1617
kOutputExt,
1718
} from "../../../config/constants.ts";
1819
import { Format } from "../../../config/types.ts";
@@ -75,6 +76,7 @@ export function quartoLatexmkOutputRecipe(
7576
autoMk: format.render[kLatexAutoMk],
7677
minRuns: format.render[kLatexMinRuns],
7778
maxRuns: format.render[kLatexMaxRuns],
79+
tinyTex: format.render[kLatexTinyTex],
7880
texInputDirs,
7981
outputDir: outputDir === null ? undefined : outputDir,
8082
clean: !options.flags?.debug && format.render[kLatexClean] !== false,

src/command/render/latexmk/pdf.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { kLatexHeaderMessageOptions, LatexmkOptions } from "./types.ts";
1414
import { dirAndStem } from "../../../core/path.ts";
1515
import { ProcessResult } from "../../../core/process.ts";
1616

17-
import { hasTexLive } from "./texlive.ts";
17+
import { hasTexLive, TexLiveContext, texLiveContext } from "./texlive.ts";
1818
import { runBibEngine, runIndexEngine, runPdfEngine } from "./latex.ts";
1919
import { PackageManager, packageManager } from "./pkgmgr.ts";
2020
import {
@@ -51,14 +51,18 @@ export async function generatePdf(mkOptions: LatexmkOptions): Promise<string> {
5151
const allowUpdate = await hasTexLive();
5252
mkOptions.autoInstall = mkOptions.autoInstall && allowUpdate;
5353

54+
// Create the TexLive context for this compilation
55+
const texLive = await texLiveContext(mkOptions.tinyTex !== false);
56+
5457
// The package manager used to find and install packages
55-
const pkgMgr = packageManager(mkOptions);
58+
const pkgMgr = packageManager(mkOptions, texLive);
5659

5760
// Render the PDF, detecting whether any packages need to be installed
5861
const response = await initialCompileLatex(
5962
mkOptions.input,
6063
mkOptions.engine,
6164
pkgMgr,
65+
texLive,
6266
mkOptions.outputDir,
6367
mkOptions.texInputDirs,
6468
mkOptions.quiet,
@@ -70,6 +74,7 @@ export async function generatePdf(mkOptions: LatexmkOptions): Promise<string> {
7074
workingDir,
7175
stem,
7276
pkgMgr,
77+
texLive,
7378
mkOptions.engine.indexEngine,
7479
mkOptions.engine.indexEngineOpts,
7580
mkOptions.quiet,
@@ -80,6 +85,7 @@ export async function generatePdf(mkOptions: LatexmkOptions): Promise<string> {
8085
mkOptions.input,
8186
mkOptions.engine.bibEngine || "citeproc",
8287
pkgMgr,
88+
texLive,
8389
mkOptions.outputDir,
8490
mkOptions.texInputDirs,
8591
mkOptions.quiet,
@@ -99,6 +105,7 @@ export async function generatePdf(mkOptions: LatexmkOptions): Promise<string> {
99105
pkgMgr,
100106
mkOptions.minRuns || 1,
101107
maxRuns,
108+
texLive,
102109
mkOptions.outputDir,
103110
mkOptions.texInputDirs,
104111
mkOptions.quiet,
@@ -125,6 +132,7 @@ async function initialCompileLatex(
125132
input: string,
126133
engine: PdfEngine,
127134
pkgMgr: PackageManager,
135+
texLive: TexLiveContext,
128136
outputDir?: string,
129137
texInputDirs?: string[],
130138
quiet?: boolean,
@@ -135,6 +143,7 @@ async function initialCompileLatex(
135143
const response = await runPdfEngine(
136144
input,
137145
engine,
146+
texLive,
138147
outputDir,
139148
texInputDirs,
140149
pkgMgr,
@@ -232,6 +241,7 @@ async function makeIndexIntermediates(
232241
dir: string,
233242
stem: string,
234243
pkgMgr: PackageManager,
244+
texLive: TexLiveContext,
235245
engine?: string,
236246
args?: string[],
237247
quiet?: boolean,
@@ -247,6 +257,7 @@ async function makeIndexIntermediates(
247257
try {
248258
const response = await runIndexEngine(
249259
indexFile,
260+
texLive,
250261
engine,
251262
args,
252263
pkgMgr,
@@ -291,6 +302,7 @@ async function makeBibliographyIntermediates(
291302
input: string,
292303
engine: string,
293304
pkgMgr: PackageManager,
305+
texLive: TexLiveContext,
294306
outputDir?: string,
295307
texInputDirs?: string[],
296308
quiet?: boolean,
@@ -350,6 +362,7 @@ async function makeBibliographyIntermediates(
350362
bibCommand,
351363
auxBibPath,
352364
cwd,
365+
texLive,
353366
pkgMgr,
354367
texInputDirs,
355368
quiet,
@@ -457,6 +470,7 @@ async function recompileLatexUntilComplete(
457470
pkgMgr: PackageManager,
458471
minRuns: number,
459472
maxRuns: number,
473+
texLive: TexLiveContext,
460474
outputDir?: string,
461475
texInputDirs?: string[],
462476
quiet?: boolean,
@@ -488,6 +502,7 @@ async function recompileLatexUntilComplete(
488502
const result = await runPdfEngine(
489503
input,
490504
engine,
505+
texLive,
491506
outputDir,
492507
texInputDirs,
493508
pkgMgr,

src/command/render/latexmk/pkgmgr.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import * as ld from "../../../core/lodash.ts";
99

1010
import { ProcessResult } from "../../../core/process.ts";
1111

12-
import { findPackages, installPackages, updatePackages } from "./texlive.ts";
12+
import {
13+
findPackages,
14+
installPackages,
15+
TexLiveContext,
16+
updatePackages,
17+
} from "./texlive.ts";
1318
import { LatexmkOptions } from "./types.ts";
1419

1520
export interface PackageManager {
@@ -19,7 +24,10 @@ export interface PackageManager {
1924
updatePackages(all: boolean, self: boolean): Promise<ProcessResult>;
2025
}
2126

22-
export function packageManager(mkOptions: LatexmkOptions): PackageManager {
27+
export function packageManager(
28+
mkOptions: LatexmkOptions,
29+
texLive: TexLiveContext,
30+
): PackageManager {
2331
let lastPkgs: string[] = [];
2432
return {
2533
autoInstall: mkOptions.autoInstall === undefined
@@ -34,6 +42,7 @@ export function packageManager(mkOptions: LatexmkOptions): PackageManager {
3442
// Attempt to install the packages
3543
await installPackages(
3644
pkgs,
45+
texLive,
3746
mkOptions.engine.tlmgrOpts,
3847
mkOptions.quiet,
3948
);
@@ -52,13 +61,15 @@ export function packageManager(mkOptions: LatexmkOptions): PackageManager {
5261
return updatePackages(
5362
all,
5463
self,
64+
texLive,
5565
mkOptions.engine.tlmgrOpts,
5666
mkOptions.quiet,
5767
);
5868
},
5969
searchPackages: (searchTerms: string[]) => {
6070
return findPackages(
6171
searchTerms,
72+
texLive,
6273
mkOptions.engine.tlmgrOpts,
6374
mkOptions.quiet,
6475
);

0 commit comments

Comments
 (0)