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/README.md CHANGED
@@ -29,6 +29,25 @@ npm install -g latex-kit
29
29
 
30
30
  ## Usage
31
31
 
32
+ A project (templates, data, records) is described in the
33
+ [repository README](https://github.com/constructive-io/latex-kit#a-project):
34
+
35
+ ```bash
36
+ latex-kit init my-documents && cd my-documents
37
+ latex-kit check # no TeX needed
38
+ latex-kit build # drafts
39
+ latex-kit build --final --only 'nda-*' # final PDFs for some documents
40
+ latex-kit build --variant signed --signatures ~/signatures
41
+ latex-kit build --locale ja-JP # another language, next to the usual PDFs
42
+ latex-kit lock # pin the images in latex-kit.lock
43
+ ```
44
+
45
+ `latex-kit help build` lists every flag. Project files import helpers from
46
+ this package: `defineConfig`, `defineDocument`, `defineComponent`,
47
+ `defineClause`, `table`, `tex`, `ref`, `z` and the shared types.
48
+
49
+ Plain `.tex` files:
50
+
32
51
  ```bash
33
52
  latex-kit doctor # is Docker ready?
34
53
  latex-kit render examples/letter/letter.tex # → out/letter.pdf
@@ -42,9 +61,9 @@ latex-kit render letter.tex --json # machine-readable summary
42
61
  | Flag | Default | |
43
62
  |---|---|---|
44
63
  | `-o, --out <dir>` | `out` | Output directory, relative to `--root` |
45
- | `-e, --engine <name>` | `lualatex` | `lualatex`, `xelatex`, `pdflatex`, `pdfps` (PSTricks) |
64
+ | `-e, --engine <name>` | `auto` | `auto` (from the packages the file loads), `lualatex`, `xelatex`, `pdflatex`, `pdfps` (PSTricks) |
46
65
  | `--root <dir>` | current directory | Directory TeX can see |
47
- | `--image <ref>` | pinned `ghcr.io/constructive-io/latex-kit` (TeX Live 2026) | Docker image |
66
+ | `--image <ref>` | pinned `constructiveio/latex-kit` on Docker Hub (TeX Live 2026) | Docker image |
48
67
  | `--platform <os/arch>` | native | Docker `--platform` |
49
68
  | `--local` | | Use `latexmk` on `PATH` instead of Docker (not pinned) |
50
69
  | `--source-date-epoch <s>` | `SOURCE_DATE_EPOCH`, else the last git commit | Build timestamp |
package/args.js CHANGED
@@ -9,9 +9,9 @@ class UsageError extends Error {
9
9
  exports.UsageError = UsageError;
10
10
  /** Turn `latex-kit render` flags into render options. Pure, for testing. */
11
11
  function renderOptionsFromArgv(argv) {
12
- const engine = (argv.engine ?? 'lualatex');
13
- if (!render_1.ENGINES.includes(engine)) {
14
- throw new UsageError(`--engine must be one of ${render_1.ENGINES.join(', ')}`);
12
+ const engine = (argv.engine ?? 'auto');
13
+ if (engine !== 'auto' && !render_1.ENGINES.includes(engine)) {
14
+ throw new UsageError(`--engine must be auto or one of ${render_1.ENGINES.join(', ')}`);
15
15
  }
16
16
  let sourceDateEpoch;
17
17
  if (argv['source-date-epoch'] !== undefined) {
package/boilerplates.d.ts CHANGED
@@ -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;
package/boilerplates.js CHANGED
@@ -4,9 +4,15 @@
4
4
  * and amount is a placeholder.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PAPER_PRESETS = void 0;
7
8
  exports.projectFiles = projectFiles;
8
- exports.paperFiles = paperFiles;
9
+ exports.plainPaperFiles = plainPaperFiles;
9
10
  exports.templateFiles = templateFiles;
11
+ exports.whitepaperFiles = whitepaperFiles;
12
+ exports.paperFiles = paperFiles;
13
+ const paper_style_1 = require("./paper-style");
14
+ /** Paper presets for `latex-kit init --paper --preset <name>`. */
15
+ exports.PAPER_PRESETS = ['whitepaper', 'plain'];
10
16
  function projectFiles(version) {
11
17
  return {
12
18
  'package.json': `${JSON.stringify({
@@ -129,7 +135,8 @@ data:
129
135
  `,
130
136
  };
131
137
  }
132
- function paperFiles() {
138
+ /** A minimal LuaLaTeX paper: fontspec, natbib. */
139
+ function plainPaperFiles() {
133
140
  return {
134
141
  '.gitignore': 'out/\n',
135
142
  'paper/main.tex': `\\documentclass[11pt]{article}
@@ -223,3 +230,194 @@ export default z.object({
223
230
  `,
224
231
  };
225
232
  }
233
+ const PAPER_WORKFLOW = (file, name) => `name: Paper
234
+
235
+ on:
236
+ push:
237
+ branches: [main]
238
+ tags: ['v*']
239
+ pull_request:
240
+
241
+ jobs:
242
+ pdf:
243
+ runs-on: ubuntu-latest
244
+ permissions:
245
+ contents: read
246
+ steps:
247
+ - uses: actions/checkout@v4
248
+ with:
249
+ fetch-depth: 0 # the build date comes from the last commit
250
+ - uses: constructive-io/latex-kit/action@v1
251
+ with:
252
+ file: ${file}
253
+ engine: auto
254
+ verify: 'true'
255
+ artifact-name: ${name}.pdf
256
+
257
+ # pushing a tag like v1.0.0 attaches the PDF to a GitHub release
258
+ release:
259
+ needs: pdf
260
+ if: startsWith(github.ref, 'refs/tags/v')
261
+ runs-on: ubuntu-latest
262
+ permissions:
263
+ contents: write
264
+ steps:
265
+ - uses: actions/download-artifact@v4
266
+ with:
267
+ name: ${name}.pdf
268
+ path: pdf
269
+ - env:
270
+ GH_TOKEN: \${{ github.token }}
271
+ run: |
272
+ pdf=$(find pdf -name '*.pdf' | head -n 1)
273
+ cp "$pdf" "${name}-$GITHUB_REF_NAME.pdf"
274
+ gh release create "$GITHUB_REF_NAME" "${name}-$GITHUB_REF_NAME.pdf" -R "$GITHUB_REPOSITORY" --title "$GITHUB_REF_NAME" --generate-notes
275
+ `;
276
+ /**
277
+ * The Constructive whitepaper style (rls-whitepaper, hyperweb-whitepaper):
278
+ * article class, the code colour palette and TypeScript listings style,
279
+ * TikZ and PSTricks, IEEE references. PSTricks means latex → dvips → ps2pdf,
280
+ * which `engine: auto` picks.
281
+ */
282
+ function whitepaperFiles() {
283
+ return {
284
+ '.gitignore': 'out/\n',
285
+ 'paper/main.tex': `% A paper in the Constructive whitepaper style (as rls-whitepaper and
286
+ % hyperweb-whitepaper). It loads PSTricks, so latex-kit builds it with
287
+ % latex -> bibtex -> dvips -> ps2pdf; \`latex-kit render paper/main.tex\` picks that.
288
+ \\documentclass{article}
289
+ \\usepackage{amsmath}
290
+ \\usepackage{graphicx}
291
+ \\usepackage{xcolor}
292
+ \\usepackage{listings}
293
+ \\usepackage{geometry}
294
+ \\usepackage{enumitem}
295
+ \\usepackage{amsfonts}
296
+ \\usepackage{amssymb}
297
+ \\usepackage[hidelinks]{hyperref}
298
+ \\usepackage{cleveref}
299
+
300
+ \\usepackage{pstricks}
301
+ \\usepackage{tikz}
302
+ \\usetikzlibrary{arrows.meta, positioning, shapes, calc}
303
+
304
+ \\input{headers/colors.tex}
305
+ \\input{headers/typescript.tex}
306
+
307
+ \\title{Paper Title: What the Paper Shows}
308
+ \\author{Your Name, A. Co-Author
309
+ \\\\ \\\\
310
+ \\texttt{info@example.com}}
311
+ \\date{v0.0.1 --- \\today}
312
+
313
+ \\begin{document}
314
+
315
+ \\maketitle
316
+
317
+ \\begin{abstract}
318
+ One paragraph: the problem, why existing approaches fall short, what this
319
+ paper presents, and what it achieves.
320
+ \\end{abstract}
321
+
322
+ \\tableofcontents
323
+
324
+ \\input{sections/introduction.tex}
325
+ \\input{sections/design.tex}
326
+ \\input{sections/conclusion.tex}
327
+
328
+ \\newpage
329
+
330
+ \\section{Bibliography}
331
+ \\bibliographystyle{IEEEtran}
332
+ \\bibliography{references}
333
+
334
+ \\end{document}
335
+ `,
336
+ 'paper/headers/colors.tex': paper_style_1.WHITEPAPER_COLORS_TEX,
337
+ 'paper/headers/typescript.tex': paper_style_1.WHITEPAPER_TYPESCRIPT_TEX,
338
+ 'paper/sections/introduction.tex': `\\section{Introduction}
339
+
340
+ State the problem and why it matters. Cite prior work like this~\\cite{stonebraker1986}.
341
+ \\Cref{fig:flow} is drawn with PSTricks.
342
+
343
+ \\begin{figure}[ht]
344
+ \\centering
345
+ \\begin{pspicture}(0,0)(9,3)
346
+ \\psframe[fillstyle=solid,fillcolor=lightpurple,framearc=0.2](0,0.75)(3,2.25)
347
+ \\rput(1.5,1.5){Client}
348
+ \\psline[linewidth=1pt]{->}(3,1.5)(6,1.5)
349
+ \\rput(4.5,1.85){\\small request}
350
+ \\pscircle[fillstyle=solid,fillcolor=codelightgreen](7.5,1.5){1.2}
351
+ \\rput(7.5,1.5){Server}
352
+ \\end{pspicture}
353
+ \\caption{A request flow, drawn with PSTricks.}
354
+ \\label{fig:flow}
355
+ \\end{figure}
356
+ `,
357
+ 'paper/sections/design.tex': `\\section{Design}
358
+
359
+ \\Cref{fig:layers} is drawn with TikZ, and \\cref{lst:counter} uses the
360
+ TypeScript listing style.
361
+
362
+ \\begin{figure}[ht]
363
+ \\centering
364
+ \\begin{tikzpicture}[
365
+ node distance=1.2cm,
366
+ box/.style={rectangle, draw, rounded corners, fill=blue!10, text width=2.8cm, text centered, minimum height=0.9cm},
367
+ store/.style={rectangle, draw, rounded corners, fill=orange!10, text width=2.8cm, text centered, minimum height=0.9cm},
368
+ arrow/.style={-{Stealth}, thick}
369
+ ]
370
+ \\node[box] (api) {API};
371
+ \\node[box, below=of api] (policy) {Policy check};
372
+ \\node[store, right=1.6cm of policy] (data) {Data};
373
+ \\draw[arrow] (api) -- (policy);
374
+ \\draw[arrow] (policy) -- node[above] {\\small allowed} (data);
375
+ \\end{tikzpicture}
376
+ \\caption{Layers, drawn with TikZ.}
377
+ \\label{fig:layers}
378
+ \\end{figure}
379
+
380
+ \\begin{lstlisting}[language=typescript, caption=A small contract, label=lst:counter, style=typescript]
381
+ export default class Counter {
382
+ state = { count: 0 };
383
+
384
+ increment(by: number) {
385
+ this.state.count += by;
386
+ return this.state.count;
387
+ }
388
+ }
389
+ \\end{lstlisting}
390
+ `,
391
+ 'paper/sections/conclusion.tex': `\\section{Conclusion}
392
+
393
+ Summarize what the paper showed and what comes next.
394
+ `,
395
+ 'paper/references.bib': `@techreport{stonebraker1986,
396
+ author = {Michael Stonebraker and Lawrence A. Rowe},
397
+ title = {The Design of {POSTGRES}},
398
+ institution = {University of California, Berkeley},
399
+ number = {UCB/ERL M85/95},
400
+ year = {1986}
401
+ }
402
+ `,
403
+ '.github/workflows/paper.yml': PAPER_WORKFLOW('paper/main.tex', 'paper'),
404
+ 'README.md': `# Paper
405
+
406
+ \`\`\`bash
407
+ npx latex-kit render paper/main.tex --verify # → out/main.pdf, byte-identical on every build
408
+ \`\`\`
409
+
410
+ The Constructive whitepaper style: \`paper/headers/colors.tex\` (code colours)
411
+ and \`paper/headers/typescript.tex\` (\`style=typescript\` listings), TikZ and
412
+ PSTricks figures, IEEE references. PSTricks builds through latex → dvips →
413
+ ps2pdf, which latex-kit picks by itself.
414
+
415
+ CI builds the PDF on every push and attaches it to the run. Pushing a tag
416
+ like \`v1.0.0\` publishes it as a GitHub release.
417
+ `,
418
+ };
419
+ }
420
+ /** Files for `latex-kit init --paper`. */
421
+ function paperFiles(preset = 'whitepaper') {
422
+ return preset === 'plain' ? plainPaperFiles() : whitepaperFiles();
423
+ }
package/build.d.ts CHANGED
@@ -1,11 +1,21 @@
1
- import { Engine } from '@latex-kit/render';
1
+ import { Engine, EngineChoice } from '@latex-kit/render';
2
2
  import { Diagnostic, Variant } from '@latex-kit/template';
3
3
  import { Project } from './project';
4
4
  export interface BuildOptions {
5
5
  variant?: Variant;
6
6
  /** Fail on missing values even in drafts. Default: on when CI=true. */
7
7
  strict?: boolean;
8
- engine?: Engine;
8
+ /** Default: the template's, the config's, else `auto`. */
9
+ engine?: EngineChoice;
10
+ /** Build in this locale instead of the record's; the output name gets `-<locale>`. */
11
+ locale?: string;
12
+ /** Rebuild even when the cached PDF matches every input. */
13
+ force?: boolean;
14
+ /**
15
+ * Folder of signature images for signed builds. Default: the
16
+ * LATEX_KIT_SIGNATURES environment variable, then the config.
17
+ */
18
+ signatures?: string | null;
9
19
  backend?: 'docker' | 'local';
10
20
  image?: string;
11
21
  platform?: string | null;
@@ -33,12 +43,22 @@ export interface BuildResult {
33
43
  sourceDateEpoch: number;
34
44
  reproducible: boolean;
35
45
  verified?: boolean;
46
+ /** The engine TeX ran with (null for --tex-only). */
47
+ engine: Engine | null;
48
+ /** "chosen", or why `auto` picked it. */
49
+ engineReason: string | null;
50
+ /** The PDF was already up to date: same inputs, same image, same date. */
51
+ cached: boolean;
36
52
  diagnostics: Diagnostic[];
37
53
  }
38
54
  export declare class BuildError extends Error {
39
55
  readonly diagnostics: Diagnostic[];
40
56
  constructor(message: string, diagnostics: Diagnostic[]);
41
57
  }
58
+ /** A folder name for a signer: "Avery Example" → "avery-example". */
59
+ export declare function signerSlug(name: string): string;
60
+ /** The signatures folder: option, LATEX_KIT_SIGNATURES, then config. `~` is home. */
61
+ export declare function signaturesDir(project: Project, option?: string | null): string | null;
42
62
  /** Build one document record. */
43
63
  export declare function buildDocument(project: Project, file: string, options?: BuildOptions): Promise<BuildResult>;
44
64
  /** Build a template as a blank form, without a record. */