latex-kit 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +21 -2
  2. package/args.js +3 -3
  3. package/boilerplates.d.ts +14 -1
  4. package/boilerplates.js +200 -2
  5. package/build.d.ts +22 -2
  6. package/build.js +230 -95
  7. package/check.js +4 -3
  8. package/cli.js +2 -2
  9. package/commands.js +1 -0
  10. package/config.d.ts +13 -4
  11. package/config.js +1 -1
  12. package/diff.d.ts +2 -2
  13. package/diff.js +3 -3
  14. package/esm/args.js +3 -3
  15. package/esm/boilerplates.d.ts +14 -1
  16. package/esm/boilerplates.js +196 -1
  17. package/esm/build.d.ts +22 -2
  18. package/esm/build.js +231 -98
  19. package/esm/check.js +4 -3
  20. package/esm/cli.js +2 -2
  21. package/esm/commands.js +2 -1
  22. package/esm/config.d.ts +13 -4
  23. package/esm/config.js +1 -1
  24. package/esm/diff.d.ts +2 -2
  25. package/esm/diff.js +3 -3
  26. package/esm/import.js +1 -1
  27. package/esm/index.d.ts +6 -2
  28. package/esm/index.js +5 -2
  29. package/esm/lock.d.ts +24 -0
  30. package/esm/lock.js +50 -0
  31. package/esm/paper-style.d.ts +10 -0
  32. package/esm/paper-style.js +10 -0
  33. package/esm/project-commands.d.ts +4 -0
  34. package/esm/project-commands.js +76 -6
  35. package/esm/project.d.ts +18 -2
  36. package/esm/project.js +92 -5
  37. package/esm/render.js +4 -2
  38. package/esm/scaffold.d.ts +2 -1
  39. package/esm/scaffold.js +1 -1
  40. package/esm/usage.js +28 -7
  41. package/import.js +1 -1
  42. package/index.d.ts +6 -2
  43. package/index.js +24 -2
  44. package/lock.d.ts +24 -0
  45. package/lock.js +57 -0
  46. package/package.json +16 -17
  47. package/paper-style.d.ts +10 -0
  48. package/paper-style.js +13 -0
  49. package/project-commands.d.ts +4 -0
  50. package/project-commands.js +78 -6
  51. package/project.d.ts +18 -2
  52. package/project.js +90 -3
  53. package/render.js +4 -2
  54. package/scaffold.d.ts +2 -1
  55. package/scaffold.js +1 -1
  56. package/usage.js +28 -7
package/build.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BuildError = void 0;
4
+ exports.signerSlug = signerSlug;
5
+ exports.signaturesDir = signaturesDir;
4
6
  exports.buildDocument = buildDocument;
5
7
  exports.buildBlank = buildBlank;
6
8
  const render_1 = require("@latex-kit/render");
@@ -9,6 +11,7 @@ const template_1 = require("@latex-kit/template");
9
11
  const child_process_1 = require("child_process");
10
12
  const crypto_1 = require("crypto");
11
13
  const fs_1 = require("fs");
14
+ const os_1 = require("os");
12
15
  const path_1 = require("path");
13
16
  class BuildError extends Error {
14
17
  diagnostics;
@@ -52,6 +55,42 @@ function gitShortHead(cwd) {
52
55
  return 'no-git';
53
56
  }
54
57
  }
58
+ /** A folder name for a signer: "Avery Example" → "avery-example". */
59
+ function signerSlug(name) {
60
+ return name
61
+ .normalize('NFKD')
62
+ .replace(/[\u0300-\u036f]/g, '')
63
+ .toLowerCase()
64
+ .replace(/[^a-z0-9]+/g, '-')
65
+ .replace(/^-|-$/g, '');
66
+ }
67
+ const IMAGE_EXTENSIONS = ['.pdf', '.png', '.jpg', '.jpeg'];
68
+ /** The signatures folder: option, LATEX_KIT_SIGNATURES, then config. `~` is home. */
69
+ function signaturesDir(project, option) {
70
+ const raw = option ?? process.env.LATEX_KIT_SIGNATURES ?? project.config.signatures ?? null;
71
+ if (!raw)
72
+ return null;
73
+ const expanded = raw === '~' || raw.startsWith('~/') ? (0, path_1.join)((0, os_1.homedir)(), raw.slice(1)) : raw;
74
+ return (0, path_1.resolve)(project.root, expanded);
75
+ }
76
+ /** Every file under a folder, for the cache key. */
77
+ function filesUnder(dir) {
78
+ const out = [];
79
+ const walk = (d) => {
80
+ if (!(0, fs_1.existsSync)(d))
81
+ return;
82
+ for (const name of (0, fs_1.readdirSync)(d).sort()) {
83
+ const p = (0, path_1.join)(d, name);
84
+ if ((0, fs_1.statSync)(p).isDirectory())
85
+ walk(p);
86
+ else
87
+ out.push(p);
88
+ }
89
+ };
90
+ walk(dir);
91
+ return out;
92
+ }
93
+ const posixRel = (root, p) => (0, path_1.relative)(root, p).split(path_1.sep).join(path_1.posix.sep);
55
94
  async function run(job) {
56
95
  const { project, template, variant, options } = job;
57
96
  const diagnostics = job.diagnostics;
@@ -72,103 +111,194 @@ async function run(job) {
72
111
  docId = (0, schema_1.mintDocId)({ prefix: template.meta.docIdPrefix ?? template.name, epoch: Math.floor(Date.now() / 1000) });
73
112
  minted = true;
74
113
  }
75
- const evaluated = (0, template_1.evaluateTemplate)(template.compiled, {
76
- data: job.data,
77
- variant,
78
- locale: job.locale,
79
- docId,
80
- template: template.name,
81
- allowMissing: variant === 'draft' ? !strict : undefined,
82
- loadSnippet,
83
- loadClause: project.loadClause,
84
- });
85
- diagnostics.push(...evaluated.diagnostics);
86
- if ((0, template_1.hasErrors)(diagnostics))
87
- throw new BuildError(`${job.name}: cannot build ${variant}`, diagnostics);
88
- // snippets count as inputs for the build date too
89
- const clauseFiles = evaluated.clauses.map((c) => (0, path_1.resolve)(c.file));
90
- const extra = [...snippets, ...clauseFiles];
91
- const finalEpoch = extra.length ? buildEpoch([...files, ...extra]) : { epoch, reproducible };
92
- // 2. write the .tex next to latex-kit.sty
93
114
  const outDir = options.outDir ?? (0, path_1.join)(project.outDir, job.name);
94
- (0, fs_1.mkdirSync)(outDir, { recursive: true });
95
115
  const job_ = variant === 'final' ? job.name : `${job.name}-${variant}`;
96
- const texPath = (0, path_1.join)(outDir, `${job_}.tex`);
97
- const stamp = `${new Date(finalEpoch.epoch * 1000).toISOString().slice(0, 10)} ${gitShortHead(project.root)}`;
98
- const tex = (0, template_1.wrapDocument)(evaluated.tex, { variant, stamp });
99
- (0, fs_1.writeFileSync)(texPath, tex);
100
- (0, fs_1.writeFileSync)((0, path_1.join)(outDir, 'latex-kit.sty'), template_1.LATEX_KIT_STY);
101
- const result = {
102
- name: job.name,
103
- template: template.name,
104
- variant,
105
- tex: texPath,
106
- pdf: null,
107
- sha256: null,
108
- docId: docId ?? null,
109
- minted: false,
110
- sourceDateEpoch: finalEpoch.epoch,
111
- reproducible: finalEpoch.reproducible,
112
- diagnostics,
113
- };
114
- if (options.texOnly)
115
- return result;
116
- // 3. render
117
- const engine = options.engine ?? template.meta.engine ?? project.config.engine ?? 'lualatex';
118
- const renderOpts = {
119
- file: texPath,
120
- root: project.root,
121
- engine,
122
- backend: options.backend ?? project.config.backend,
123
- image: options.image ?? project.config.image,
124
- platform: options.platform !== undefined ? options.platform : project.config.platform,
125
- sourceDateEpoch: finalEpoch.epoch,
126
- texInputs: [(0, path_1.relative)(project.root, outDir) || '.', (0, path_1.relative)(project.root, template.dir) || '.'],
127
- onOutput: options.onOutput,
128
- };
129
- let rendered;
130
- try {
131
- rendered = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, outDir) });
132
- }
133
- catch (e) {
134
- if (e instanceof render_1.RenderError) {
135
- throw new BuildError(`${job.name}: ${e.message}`, [
136
- ...diagnostics,
137
- ...e.diagnostics.map((d) => (0, template_1.diag)(d.severity, d.message, d.file ? { file: project.rel((0, path_1.join)(outDir, (0, path_1.basename)(d.file))), line: d.line ?? 0, column: 0 } : undefined)),
138
- ]);
116
+ // signed builds: copy signature images next to the .tex for this build only
117
+ const stageDir = (0, path_1.join)(outDir, 'lk-signatures');
118
+ const staged = [];
119
+ let signatureImage;
120
+ const sigDir = variant === 'signed' ? signaturesDir(project, options.signatures) : null;
121
+ if (sigDir) {
122
+ const at = { file: project.rel(sigDir), line: 1, column: 1 };
123
+ if (!(0, fs_1.existsSync)(sigDir)) {
124
+ diagnostics.push((0, template_1.diag)('error', `signatures folder not found: ${project.rel(sigDir)}`, at));
125
+ }
126
+ else {
127
+ const inside = (0, path_1.relative)(project.root, sigDir);
128
+ if (!inside.startsWith('..') && !(0, path_1.isAbsolute)(inside)) {
129
+ diagnostics.push((0, template_1.diag)('warning', 'the signatures folder is inside the project; keep signature images out of the repository', at));
130
+ }
131
+ signatureImage = (signer) => {
132
+ const names = signer.image ? [signer.image] : IMAGE_EXTENSIONS.map((e) => `${signerSlug(signer.name)}${e}`);
133
+ const found = names.find((n) => (0, path_1.basename)(n) === n && (0, fs_1.existsSync)((0, path_1.join)(sigDir, n)));
134
+ if (!found) {
135
+ diagnostics.push((0, template_1.diag)('warning', `no signature image for ${signer.name} in ${project.rel(sigDir)} (looked for ${names.join(', ')}); printed /s/ ${signer.name}`, at));
136
+ return null;
137
+ }
138
+ (0, fs_1.mkdirSync)(stageDir, { recursive: true });
139
+ const target = (0, path_1.join)(stageDir, found);
140
+ (0, fs_1.copyFileSync)((0, path_1.join)(sigDir, found), target);
141
+ if (!staged.includes(target))
142
+ staged.push(target);
143
+ return posixRel(project.root, target);
144
+ };
139
145
  }
140
- throw e;
141
146
  }
142
- result.pdf = rendered.pdf;
143
- result.sha256 = rendered.sha256;
144
- if (options.verify) {
145
- // same output path: some tools (Ghostscript) hash the path into the PDF ID
146
- const again = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, outDir) });
147
- result.verified = again.sha256 === rendered.sha256;
147
+ try {
148
+ return await fill();
148
149
  }
149
- // 4. keep the ID: only after a successful final build
150
- if (minted && job.mintInto) {
151
- (0, schema_1.writeDocId)(job.mintInto, docId);
152
- result.minted = true;
150
+ finally {
151
+ (0, fs_1.rmSync)(stageDir, { recursive: true, force: true });
152
+ }
153
+ async function fill() {
154
+ const evaluated = (0, template_1.evaluateTemplate)(template.compiled, {
155
+ data: job.data,
156
+ variant,
157
+ locale: job.locale,
158
+ docId,
159
+ template: template.name,
160
+ allowMissing: variant === 'draft' ? !strict : undefined,
161
+ loadSnippet,
162
+ loadClause: project.loadClause,
163
+ components: project.components,
164
+ signatureImage,
165
+ signed: job.signed,
166
+ });
167
+ diagnostics.push(...evaluated.diagnostics);
168
+ if ((0, template_1.hasErrors)(diagnostics))
169
+ throw new BuildError(`${job.name}: cannot build ${variant}`, diagnostics);
170
+ // snippets, clauses and components count as inputs for the build date too
171
+ const clauseFiles = evaluated.clauses.map((c) => (0, path_1.resolve)(c.file));
172
+ const componentFiles = evaluated.components.map((n) => project.componentFiles[n]).filter((f) => !!f);
173
+ const extra = [...snippets, ...clauseFiles, ...componentFiles];
174
+ const finalEpoch = extra.length ? buildEpoch([...files, ...extra]) : { epoch, reproducible };
175
+ // 2. write the .tex next to latex-kit.sty
176
+ (0, fs_1.mkdirSync)(outDir, { recursive: true });
177
+ const texPath = (0, path_1.join)(outDir, `${job_}.tex`);
178
+ const stamp = `${new Date(finalEpoch.epoch * 1000).toISOString().slice(0, 10)} ${gitShortHead(project.root)}`;
179
+ const tex = (0, template_1.wrapDocument)(evaluated.tex, { variant, stamp });
180
+ (0, fs_1.writeFileSync)(texPath, tex);
181
+ (0, fs_1.writeFileSync)((0, path_1.join)(outDir, 'latex-kit.sty'), template_1.LATEX_KIT_STY);
182
+ const result = {
183
+ name: job.name,
184
+ template: template.name,
185
+ variant,
186
+ tex: texPath,
187
+ pdf: null,
188
+ sha256: null,
189
+ docId: docId ?? null,
190
+ minted: false,
191
+ sourceDateEpoch: finalEpoch.epoch,
192
+ reproducible: finalEpoch.reproducible,
193
+ engine: null,
194
+ engineReason: null,
195
+ cached: false,
196
+ diagnostics,
197
+ };
198
+ if (options.texOnly)
199
+ return result;
200
+ // 3. render, unless the last build had exactly these inputs
201
+ const choice = options.engine ?? template.meta.engine ?? project.config.engine ?? 'auto';
202
+ let engine;
203
+ let engineReason;
204
+ if (choice === 'auto') {
205
+ const d = (0, render_1.detectEngine)(tex);
206
+ engine = d.engine;
207
+ engineReason = `auto: ${d.reason}`;
208
+ for (const w of d.warnings)
209
+ diagnostics.push((0, template_1.diag)('warning', w, { file: template.compiled.file, line: 1, column: 1 }));
210
+ }
211
+ else {
212
+ engine = choice;
213
+ engineReason = 'chosen';
214
+ }
215
+ result.engine = engine;
216
+ result.engineReason = engineReason;
217
+ const backend = options.backend ?? project.config.backend ?? 'docker';
218
+ const image = project.image(options.image);
219
+ const platform = options.platform !== undefined ? options.platform : project.config.platform;
220
+ const renderOpts = {
221
+ file: texPath,
222
+ root: project.root,
223
+ engine,
224
+ backend,
225
+ image,
226
+ platform,
227
+ sourceDateEpoch: finalEpoch.epoch,
228
+ texInputs: [(0, path_1.relative)(project.root, outDir) || '.', (0, path_1.relative)(project.root, template.dir) || '.'],
229
+ onOutput: options.onOutput,
230
+ };
231
+ // content-addressed: the PDF depends on the .tex, the .sty, the template
232
+ // folder (images, \\input files), signature images, the engine, the image
233
+ // and the build date. Same key → same bytes, so the last PDF is reused.
234
+ const keyInputs = [...filesUnder(template.dir), ...staged].map((f) => [posixRel(project.root, f), sha256((0, fs_1.readFileSync)(f))]);
235
+ const cacheKey = sha256(JSON.stringify({ v: 1, tex: sha256(tex), sty: sha256(template_1.LATEX_KIT_STY), engine, backend, image: backend === 'docker' ? (image ?? 'default') : null, platform: platform ?? null, epoch: finalEpoch.epoch, inputs: keyInputs }));
236
+ const manifestPath = (0, path_1.join)(outDir, `${job_}.manifest.json`);
237
+ const pdfPath = (0, path_1.join)(outDir, `${job_}.pdf`);
238
+ if (!options.force && !options.verify && (0, fs_1.existsSync)(manifestPath) && (0, fs_1.existsSync)(pdfPath)) {
239
+ try {
240
+ const m = JSON.parse((0, fs_1.readFileSync)(manifestPath, 'utf8'));
241
+ const pdfSha = sha256((0, fs_1.readFileSync)(pdfPath));
242
+ if (m.cacheKey === cacheKey && m.pdf?.sha256 === pdfSha) {
243
+ result.pdf = pdfPath;
244
+ result.sha256 = pdfSha;
245
+ result.cached = true;
246
+ return result;
247
+ }
248
+ }
249
+ catch {
250
+ // an unreadable manifest just means a rebuild
251
+ }
252
+ }
253
+ let rendered;
254
+ try {
255
+ rendered = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, outDir) });
256
+ }
257
+ catch (e) {
258
+ if (e instanceof render_1.RenderError) {
259
+ throw new BuildError(`${job.name}: ${e.message}`, [
260
+ ...diagnostics,
261
+ ...e.diagnostics.map((d) => (0, template_1.diag)(d.severity, d.message, d.file ? { file: project.rel((0, path_1.join)(outDir, (0, path_1.basename)(d.file))), line: d.line ?? 0, column: 0 } : undefined)),
262
+ ]);
263
+ }
264
+ throw e;
265
+ }
266
+ result.pdf = rendered.pdf;
267
+ result.sha256 = rendered.sha256;
268
+ if (options.verify) {
269
+ // same output path: some tools (Ghostscript) hash the path into the PDF ID
270
+ const again = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, outDir) });
271
+ result.verified = again.sha256 === rendered.sha256;
272
+ }
273
+ // 4. keep the ID: only after a successful final build
274
+ if (minted && job.mintInto) {
275
+ (0, schema_1.writeDocId)(job.mintInto, docId);
276
+ result.minted = true;
277
+ }
278
+ // 5. manifest: what went in, what came out
279
+ const inputFiles = [...new Set([...files, ...extra])].filter(fs_1.existsSync).sort();
280
+ (0, fs_1.writeFileSync)(manifestPath, JSON.stringify({
281
+ document: job.name,
282
+ template: template.name,
283
+ variant,
284
+ docId: docId ?? null,
285
+ locale: job.locale,
286
+ engine,
287
+ engineReason,
288
+ image: rendered.image,
289
+ cacheKey,
290
+ sourceDateEpoch: finalEpoch.epoch,
291
+ inputs: inputFiles.map((f) => ({ file: (0, path_1.relative)(project.root, f), sha256: sha256((0, fs_1.readFileSync)(f)) })),
292
+ tex: { file: (0, path_1.relative)(project.root, texPath), sha256: sha256(tex) },
293
+ pdf: { file: (0, path_1.relative)(project.root, rendered.pdf), sha256: rendered.sha256 },
294
+ clauses: evaluated.clauses.map((c) => ({ id: c.id, version: c.version ?? null, file: (0, path_1.relative)(project.root, (0, path_1.resolve)(c.file)) })),
295
+ components: evaluated.components,
296
+ fields: evaluated.fields.map((f) => ({ path: f.path, missing: f.missing })),
297
+ // which signers had an image; never the images or where they live
298
+ signatureImages: staged.map((f) => (0, path_1.basename)(f)),
299
+ }, null, 2) + '\n');
300
+ return result;
153
301
  }
154
- // 5. manifest: what went in, what came out
155
- const inputFiles = [...new Set([...files, ...extra])].filter(fs_1.existsSync).sort();
156
- (0, fs_1.writeFileSync)((0, path_1.join)(outDir, `${job_}.manifest.json`), JSON.stringify({
157
- document: job.name,
158
- template: template.name,
159
- variant,
160
- docId: docId ?? null,
161
- locale: job.locale,
162
- engine,
163
- image: rendered.image,
164
- sourceDateEpoch: finalEpoch.epoch,
165
- inputs: inputFiles.map((f) => ({ file: (0, path_1.relative)(project.root, f), sha256: sha256((0, fs_1.readFileSync)(f)) })),
166
- tex: { file: (0, path_1.relative)(project.root, texPath), sha256: sha256(tex) },
167
- pdf: { file: (0, path_1.relative)(project.root, rendered.pdf), sha256: rendered.sha256 },
168
- clauses: evaluated.clauses.map((c) => ({ id: c.id, version: c.version ?? null, file: (0, path_1.relative)(project.root, (0, path_1.resolve)(c.file)) })),
169
- fields: evaluated.fields.map((f) => ({ path: f.path, missing: f.missing })),
170
- }, null, 2) + '\n');
171
- return result;
172
302
  }
173
303
  /** Build one document record. */
174
304
  async function buildDocument(project, file, options = {}) {
@@ -195,14 +325,18 @@ async function buildDocument(project, file, options = {}) {
195
325
  diagnostics.push((0, template_1.diag)('error', `a ${variant} build needs a document ID, and latex-kit does not edit code. Add: docId: '${suggestion}'`, at));
196
326
  throw new BuildError(`${doc.record.template}: no document ID`, diagnostics);
197
327
  }
328
+ const natural = doc.record.locale ?? template.meta.locale ?? project.config.locale;
329
+ const name = project.documentName(file);
198
330
  return run({
199
331
  project,
200
332
  template,
201
- name: project.documentName(file),
333
+ // another language is another PDF, next to the usual one
334
+ name: options.locale && options.locale !== natural ? `${name}-${options.locale}` : name,
202
335
  variant,
203
336
  data,
204
- locale: doc.record.locale ?? template.meta.locale ?? project.config.locale,
337
+ locale: options.locale ?? natural,
205
338
  docId: doc.record.docId ?? options.docIdFallback,
339
+ signed: doc.record.signed,
206
340
  inputs: [file, ...doc.refFiles],
207
341
  diagnostics,
208
342
  options,
@@ -212,13 +346,14 @@ async function buildDocument(project, file, options = {}) {
212
346
  /** Build a template as a blank form, without a record. */
213
347
  async function buildBlank(project, templateName, options = {}) {
214
348
  const template = await project.template(templateName);
349
+ const natural = template.meta.locale ?? project.config.locale;
215
350
  return run({
216
351
  project,
217
352
  template,
218
- name: `${templateName}`,
353
+ name: options.locale && options.locale !== natural ? `${templateName}-${options.locale}` : templateName,
219
354
  variant: 'blank',
220
355
  data: {},
221
- locale: template.meta.locale ?? project.config.locale,
356
+ locale: options.locale ?? natural,
222
357
  inputs: [],
223
358
  diagnostics: [],
224
359
  options: { ...options, variant: 'blank' },
package/check.js CHANGED
@@ -9,15 +9,16 @@ const template_1 = require("@latex-kit/template");
9
9
  * against each schema, every document's data, references, and duplicate IDs.
10
10
  */
11
11
  async function checkProject(project) {
12
- const diagnostics = [];
12
+ const diagnostics = [...project.codeDiagnostics];
13
13
  const templates = project.templateNames();
14
+ const components = project.componentNames();
14
15
  for (const name of templates) {
15
16
  try {
16
17
  const t = await project.template(name);
17
18
  if (!t.jsonSchema) {
18
19
  diagnostics.push((0, template_1.diag)('warning', `template ${name} has no schema.ts, so field names are not checked`, { file: t.compiled.file, line: 1, column: 1 }));
19
20
  }
20
- diagnostics.push(...(0, template_1.analyzeTemplate)(t.compiled, { schema: t.jsonSchema ?? undefined, loadSnippet: project.loadSnippet, loadClause: project.loadClause }).diagnostics);
21
+ diagnostics.push(...(0, template_1.analyzeTemplate)(t.compiled, { schema: t.jsonSchema ?? undefined, loadSnippet: project.loadSnippet, loadClause: project.loadClause, components }).diagnostics);
21
22
  }
22
23
  catch (e) {
23
24
  diagnostics.push((0, template_1.diag)('error', e.message, { file: project.rel(project.path(project.config.templates, name)), line: 1, column: 1 }));
@@ -53,6 +54,6 @@ async function checkProject(project) {
53
54
  /** Every field a template reads, including through snippets. */
54
55
  async function templateFields(project, name) {
55
56
  const t = await project.template(name);
56
- const r = (0, template_1.analyzeTemplate)(t.compiled, { schema: t.jsonSchema ?? undefined, loadSnippet: project.loadSnippet, loadClause: project.loadClause });
57
+ const r = (0, template_1.analyzeTemplate)(t.compiled, { schema: t.jsonSchema ?? undefined, loadSnippet: project.loadSnippet, loadClause: project.loadClause, components: project.componentNames() });
57
58
  return { fields: r.fields, diagnostics: r.diagnostics };
58
59
  }
package/cli.js CHANGED
@@ -20,8 +20,8 @@ const app = new inquirerer_1.CLI(commands_1.commands, {
20
20
  version: (0, commands_1.version)(),
21
21
  minimistOpts: {
22
22
  alias: { h: 'help', v: 'version', o: 'out', e: 'engine' },
23
- boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper'],
24
- string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against'],
23
+ boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper', 'check'],
24
+ string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against', 'only', 'locale', 'signatures', 'preset'],
25
25
  default: { strict: undefined, schema: true },
26
26
  },
27
27
  });
package/commands.js CHANGED
@@ -36,6 +36,7 @@ const COMMANDS = {
36
36
  import: project_commands_1.importCommand,
37
37
  diff: project_commands_1.diffCommand,
38
38
  sty: project_commands_1.styCommand,
39
+ lock: project_commands_1.lockCommand,
39
40
  render: render_1.renderCommand,
40
41
  doctor: doctor_1.doctorCommand,
41
42
  };
package/config.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import type { Backend, Engine } from '@latex-kit/render';
1
+ import type { Backend, EngineChoice } from '@latex-kit/render';
2
2
  /** latex-kit.config.ts (or .js, .mjs, .cjs, .json) at the project root. */
3
3
  export interface LatexKitConfig {
4
4
  /** One folder per template: `<templates>/<name>/template.tex` and optional `schema.ts`. Default `templates`. */
5
5
  templates?: string;
6
6
  /** Shared pieces for \snippet{name}. Default `snippets`. */
7
7
  snippets?: string;
8
- /** The clause library for \\clause{id}: `<clauses>/<id>.tex`. Default `clauses`. */
8
+ /** The clause library for \\clause{id}: `<clauses>/<id>.tex` or `.ts`. Default `clauses`. */
9
9
  clauses?: string;
10
+ /** TypeScript components for \\component{name}{path}: `<components>/<name>.ts`. Default `components`. */
11
+ components?: string;
10
12
  /** Shared records that references point at: `<data>/<collection>/<id>.json`. Default `data`. */
11
13
  data?: string;
12
14
  /** Document records: `<documents>/<name>.json|yaml|ts`. Default `documents`. */
@@ -15,12 +17,19 @@ export interface LatexKitConfig {
15
17
  out?: string;
16
18
  /** Default locale for dates, numbers and money. Default `en-US`. */
17
19
  locale?: string;
18
- engine?: Engine;
20
+ /** Default `auto`: chosen from the packages each document loads. */
21
+ engine?: EngineChoice;
22
+ /**
23
+ * Folder with signature images for signed builds (`<name>.png|pdf|jpg`).
24
+ * Keep it outside the repository; `--signatures` and LATEX_KIT_SIGNATURES
25
+ * override it. A leading ~ is the home folder.
26
+ */
27
+ signatures?: string;
19
28
  backend?: Backend;
20
29
  image?: string;
21
30
  platform?: string | null;
22
31
  }
23
- export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform'> & {
32
+ export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'components' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform' | 'signatures'> & {
24
33
  file: string | null;
25
34
  };
26
35
  export declare function defineConfig(config: LatexKitConfig): LatexKitConfig;
package/config.js CHANGED
@@ -10,7 +10,7 @@ function defineConfig(config) {
10
10
  return config;
11
11
  }
12
12
  exports.CONFIG_FILES = ['latex-kit.config.ts', 'latex-kit.config.mts', 'latex-kit.config.js', 'latex-kit.config.mjs', 'latex-kit.config.cjs', 'latex-kit.config.json'];
13
- const DEFAULTS = { templates: 'templates', snippets: 'snippets', clauses: 'clauses', data: 'data', documents: 'documents', out: 'out', locale: 'en-US' };
13
+ const DEFAULTS = { templates: 'templates', snippets: 'snippets', clauses: 'clauses', components: 'components', data: 'data', documents: 'documents', out: 'out', locale: 'en-US' };
14
14
  async function loadConfig(root) {
15
15
  for (const name of exports.CONFIG_FILES) {
16
16
  const file = (0, path_1.join)((0, path_1.resolve)(root), name);
package/diff.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Engine } from '@latex-kit/render';
1
+ import { EngineChoice } from '@latex-kit/render';
2
2
  import { Variant } from '@latex-kit/template';
3
3
  import { Project } from './project';
4
4
  export interface DiffOptions {
5
5
  variant?: Variant;
6
- engine?: Engine;
6
+ engine?: EngineChoice;
7
7
  backend?: 'docker' | 'local';
8
8
  image?: string;
9
9
  platform?: string | null;
package/diff.js CHANGED
@@ -19,14 +19,14 @@ async function redline(project, oldTex, newTex, dir, name, texInputs, options) {
19
19
  (0, fs_1.writeFileSync)((0, path_1.join)(dir, 'latex-kit.sty'), template_1.LATEX_KIT_STY);
20
20
  const tex = (0, path_1.join)(dir, `${name}.tex`);
21
21
  const rel = (p) => (0, path_1.relative)(project.root, p);
22
- await (0, render_1.runLatexdiff)({ root: project.root, old: rel(oldTex), new: rel(newTex), output: rel(tex), backend: options.backend, image: options.image, platform: options.platform });
22
+ await (0, render_1.runLatexdiff)({ root: project.root, old: rel(oldTex), new: rel(newTex), output: rel(tex), backend: options.backend, image: project.image(options.image), platform: options.platform });
23
23
  const r = await (0, render_1.render)({
24
24
  file: tex,
25
25
  root: project.root,
26
26
  outDir: rel(dir),
27
- engine: options.engine ?? project.config.engine ?? 'lualatex',
27
+ engine: options.engine ?? project.config.engine ?? 'auto',
28
28
  backend: options.backend ?? project.config.backend,
29
- image: options.image ?? project.config.image,
29
+ image: project.image(options.image),
30
30
  platform: options.platform !== undefined ? options.platform : project.config.platform,
31
31
  texInputs: [rel(dir), ...texInputs.map(rel)],
32
32
  });
package/esm/args.js CHANGED
@@ -4,9 +4,9 @@ export class UsageError extends Error {
4
4
  }
5
5
  /** Turn `latex-kit render` flags into render options. Pure, for testing. */
6
6
  export function renderOptionsFromArgv(argv) {
7
- const engine = (argv.engine ?? 'lualatex');
8
- if (!ENGINES.includes(engine)) {
9
- throw new UsageError(`--engine must be one of ${ENGINES.join(', ')}`);
7
+ const engine = (argv.engine ?? 'auto');
8
+ if (engine !== 'auto' && !ENGINES.includes(engine)) {
9
+ throw new UsageError(`--engine must be auto or one of ${ENGINES.join(', ')}`);
10
10
  }
11
11
  let sourceDateEpoch;
12
12
  if (argv['source-date-epoch'] !== undefined) {
@@ -3,6 +3,19 @@
3
3
  * and amount is a placeholder.
4
4
  */
5
5
  export type FileMap = Record<string, string>;
6
+ /** Paper presets for `latex-kit init --paper --preset <name>`. */
7
+ export declare const PAPER_PRESETS: readonly ["whitepaper", "plain"];
8
+ export type PaperPreset = (typeof PAPER_PRESETS)[number];
6
9
  export declare function projectFiles(version: string): FileMap;
7
- export declare function paperFiles(): FileMap;
10
+ /** A minimal LuaLaTeX paper: fontspec, natbib. */
11
+ export declare function plainPaperFiles(): FileMap;
8
12
  export declare function templateFiles(name: string): FileMap;
13
+ /**
14
+ * The Constructive whitepaper style (rls-whitepaper, hyperweb-whitepaper):
15
+ * article class, the code colour palette and TypeScript listings style,
16
+ * TikZ and PSTricks, IEEE references. PSTricks means latex → dvips → ps2pdf,
17
+ * which `engine: auto` picks.
18
+ */
19
+ export declare function whitepaperFiles(): FileMap;
20
+ /** Files for `latex-kit init --paper`. */
21
+ export declare function paperFiles(preset?: PaperPreset): FileMap;