latex-kit 0.3.0 → 0.5.0

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 (54) hide show
  1. package/README.md +22 -3
  2. package/args.js +3 -3
  3. package/boilerplates.d.ts +8 -0
  4. package/boilerplates.js +225 -0
  5. package/build.d.ts +28 -2
  6. package/build.js +233 -94
  7. package/check.js +4 -3
  8. package/cli.js +14 -3
  9. package/commands.js +7 -0
  10. package/config.d.ts +14 -3
  11. package/config.js +1 -1
  12. package/diff.d.ts +25 -0
  13. package/diff.js +112 -0
  14. package/esm/args.js +3 -3
  15. package/esm/boilerplates.d.ts +8 -0
  16. package/esm/boilerplates.js +220 -0
  17. package/esm/build.d.ts +28 -2
  18. package/esm/build.js +234 -97
  19. package/esm/check.js +4 -3
  20. package/esm/cli.js +14 -3
  21. package/esm/commands.js +8 -1
  22. package/esm/config.d.ts +14 -3
  23. package/esm/config.js +1 -1
  24. package/esm/diff.d.ts +25 -0
  25. package/esm/diff.js +108 -0
  26. package/esm/import.d.ts +24 -0
  27. package/esm/import.js +113 -0
  28. package/esm/index.d.ts +9 -2
  29. package/esm/index.js +8 -2
  30. package/esm/lock.d.ts +24 -0
  31. package/esm/lock.js +50 -0
  32. package/esm/project-commands.d.ts +14 -0
  33. package/esm/project-commands.js +232 -7
  34. package/esm/project.d.ts +20 -1
  35. package/esm/project.js +105 -4
  36. package/esm/render.js +6 -6
  37. package/esm/scaffold.d.ts +27 -0
  38. package/esm/scaffold.js +108 -0
  39. package/esm/usage.js +40 -7
  40. package/import.d.ts +24 -0
  41. package/import.js +118 -0
  42. package/index.d.ts +9 -2
  43. package/index.js +27 -2
  44. package/lock.d.ts +24 -0
  45. package/lock.js +57 -0
  46. package/package.json +6 -5
  47. package/project-commands.d.ts +14 -0
  48. package/project-commands.js +238 -5
  49. package/project.d.ts +20 -1
  50. package/project.js +103 -2
  51. package/render.js +5 -5
  52. package/scaffold.d.ts +27 -0
  53. package/scaffold.js +115 -0
  54. package/usage.js +40 -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,10 +61,10 @@ 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` |
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 `pyramation/latex` | Docker image |
48
- | `--platform <os/arch>` | `linux/amd64` for the default image | Docker `--platform` |
66
+ | `--image <ref>` | pinned `ghcr.io/constructive-io/latex-kit` (TeX Live 2026) | Docker image |
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 |
51
70
  | `--verify` | | Build twice; exit 1 if the PDFs differ |
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) {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Files written by `latex-kit init` and `latex-kit new`. Every name, address
3
+ * and amount is a placeholder.
4
+ */
5
+ export type FileMap = Record<string, string>;
6
+ export declare function projectFiles(version: string): FileMap;
7
+ export declare function paperFiles(): FileMap;
8
+ export declare function templateFiles(name: string): FileMap;
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ /**
3
+ * Files written by `latex-kit init` and `latex-kit new`. Every name, address
4
+ * and amount is a placeholder.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.projectFiles = projectFiles;
8
+ exports.paperFiles = paperFiles;
9
+ exports.templateFiles = templateFiles;
10
+ function projectFiles(version) {
11
+ return {
12
+ 'package.json': `${JSON.stringify({
13
+ name: 'documents',
14
+ private: true,
15
+ scripts: {
16
+ check: 'latex-kit check',
17
+ draft: 'latex-kit build',
18
+ final: 'latex-kit build --final',
19
+ blank: 'latex-kit build --variant blank',
20
+ typegen: 'latex-kit typegen',
21
+ },
22
+ devDependencies: { 'latex-kit': `^${version}` },
23
+ }, null, 2)}\n`,
24
+ '.gitignore': 'node_modules/\nout/\n',
25
+ 'latex-kit.config.ts': `import { defineConfig } from 'latex-kit';
26
+
27
+ export default defineConfig({
28
+ locale: 'en-US',
29
+ });
30
+ `,
31
+ 'README.md': `# Documents
32
+
33
+ Built with [latex-kit](https://github.com/constructive-io/latex-kit).
34
+
35
+ | Folder | |
36
+ |---|---|
37
+ | \`templates/<name>/template.tex\` | A real \`.tex\` file with \`\\field{…}\`, \`\\when\`, \`\\each\` |
38
+ | \`templates/<name>/schema.ts\` | The data the template needs (zod) |
39
+ | \`snippets/\` | Shared pieces: \`\\snippet{letterhead}\` |
40
+ | \`clauses/\` | Versioned clauses: \`\\clause{id}\`, \`\\clauseref{id}\` |
41
+ | \`data/\` | Shared records, used with \`{ "$ref": "orgs/my-company" }\` |
42
+ | \`documents/\` | One record per document |
43
+ | \`out/\` | Generated .tex, PDFs and manifests (not committed) |
44
+
45
+ \`\`\`bash
46
+ npx latex-kit check # no TeX needed
47
+ npx latex-kit build # drafts
48
+ npx latex-kit build --final # final PDFs; mints document IDs once
49
+ npx latex-kit new document thank-you --template letter
50
+ \`\`\`
51
+ `,
52
+ 'templates/letter/template.tex': `\\documentclass[11pt]{article}
53
+ \\usepackage{fontspec}
54
+ \\usepackage[margin=25mm]{geometry}
55
+ \\usepackage{latex-kit}
56
+ \\pagestyle{empty}
57
+ \\setlength{\\parindent}{0pt}
58
+
59
+ \\begin{document}
60
+ \\snippet{letterhead}
61
+
62
+ \\vspace{2em}
63
+ \\field{date|date:long}
64
+
65
+ \\vspace{1em}
66
+ \\field{to.name}\\\\
67
+ \\when{to.address}{\\field{to.address.line1}\\\\
68
+ \\field{to.address.city}}
69
+
70
+ \\vspace{1em}
71
+ Dear \\field{to.name},
72
+
73
+ \\field{body|paragraphs}
74
+
75
+ \\vspace{2em}
76
+ Sincerely,\\\\[3em]
77
+ \\field{from.signer.name}\\\\
78
+ \\field{from.signer.title|default:""}
79
+
80
+ \\vfill
81
+ {\\small \\docid}
82
+ \\end{document}
83
+ `,
84
+ 'templates/letter/schema.ts': `import { ISODate, Organization, Party, z } from 'latex-kit';
85
+
86
+ export const meta = { docIdPrefix: 'LTR' };
87
+
88
+ export default z.object({
89
+ date: ISODate,
90
+ from: Organization,
91
+ to: Party,
92
+ body: z.string(),
93
+ });
94
+ `,
95
+ 'snippets/letterhead.tex': `% Shared letterhead: reads \`from\` from the document's data.
96
+ \\begin{flushright}
97
+ {\\large\\bfseries \\field{from.name}}\\\\
98
+ \\field{from.address.line1}\\\\
99
+ \\field{from.address.city}
100
+ \\end{flushright}
101
+ `,
102
+ 'clauses/.gitkeep': '',
103
+ 'data/orgs/my-company.yaml': `# Your organization. Documents refer to it as { $ref: orgs/my-company }.
104
+ name: My Company, Inc.
105
+ address:
106
+ line1: 1 Example Street
107
+ city: Springfield
108
+ signer:
109
+ $ref: people/me
110
+ `,
111
+ 'data/people/me.yaml': `name: Your Name
112
+ title: Founder
113
+ `,
114
+ 'documents/welcome-letter.yaml': `template: letter
115
+ data:
116
+ date: "2026-01-15"
117
+ from:
118
+ $ref: orgs/my-company
119
+ to:
120
+ name: Jordan Example
121
+ address:
122
+ line1: 2 Sample Road
123
+ city: Anytown
124
+ body: |
125
+ Welcome aboard! This letter was built by latex-kit from
126
+ documents/welcome-letter.yaml and templates/letter/template.tex.
127
+
128
+ Run latex-kit build --final to mint its document ID.
129
+ `,
130
+ };
131
+ }
132
+ function paperFiles() {
133
+ return {
134
+ '.gitignore': 'out/\n',
135
+ 'paper/main.tex': `\\documentclass[11pt]{article}
136
+ \\usepackage{fontspec}
137
+ \\usepackage[margin=25mm]{geometry}
138
+ \\usepackage{amsmath,natbib,hyperref}
139
+
140
+ \\title{Paper Title}
141
+ \\author{Your Name}
142
+ \\date{\\today}
143
+
144
+ \\begin{document}
145
+ \\maketitle
146
+
147
+ \\begin{abstract}
148
+ One paragraph that says what the paper shows.
149
+ \\end{abstract}
150
+
151
+ \\section{Introduction}
152
+ Cite related work like this~\\citep{knuth1984}.
153
+
154
+ \\section{Results}
155
+ \\begin{equation}
156
+ e^{i\\pi} + 1 = 0
157
+ \\end{equation}
158
+
159
+ \\bibliographystyle{plainnat}
160
+ \\bibliography{refs}
161
+ \\end{document}
162
+ `,
163
+ 'paper/refs.bib': `@book{knuth1984,
164
+ author = {Donald E. Knuth},
165
+ title = {The {\\TeX}book},
166
+ publisher = {Addison-Wesley},
167
+ year = {1984}
168
+ }
169
+ `,
170
+ '.github/workflows/paper.yml': `name: Paper
171
+
172
+ on:
173
+ push:
174
+ branches: [main]
175
+ pull_request:
176
+
177
+ jobs:
178
+ pdf:
179
+ runs-on: ubuntu-latest
180
+ steps:
181
+ - uses: actions/checkout@v4
182
+ with:
183
+ fetch-depth: 0 # the build date comes from the last commit
184
+ - uses: constructive-io/latex-kit/action@v1
185
+ with:
186
+ file: paper/main.tex
187
+ verify: 'true'
188
+ `,
189
+ 'README.md': `# Paper
190
+
191
+ \`\`\`bash
192
+ npx latex-kit render paper/main.tex --verify # → out/main.pdf, byte-identical on every build
193
+ \`\`\`
194
+
195
+ CI builds the PDF on every push and attaches it to the run.
196
+ `,
197
+ };
198
+ }
199
+ function templateFiles(name) {
200
+ return {
201
+ [`templates/${name}/template.tex`]: `\\documentclass[11pt]{article}
202
+ \\usepackage{fontspec}
203
+ \\usepackage[margin=25mm]{geometry}
204
+ \\usepackage{latex-kit}
205
+
206
+ \\begin{document}
207
+ \\section*{\\field{title}}
208
+
209
+ Prepared for \\field{recipient.name} on \\field{date|date:long}.
210
+
211
+ \\docid
212
+ \\end{document}
213
+ `,
214
+ [`templates/${name}/schema.ts`]: `import { ISODate, Party, z } from 'latex-kit';
215
+
216
+ export const meta = { docIdPrefix: '${name.toUpperCase().replace(/[^A-Z0-9]+/g, '-').slice(0, 12)}' };
217
+
218
+ export default z.object({
219
+ title: z.string(),
220
+ date: ISODate,
221
+ recipient: Party,
222
+ });
223
+ `,
224
+ };
225
+ }
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;
@@ -13,10 +23,16 @@ export interface BuildOptions {
13
23
  verify?: boolean;
14
24
  /** Stop after writing the .tex (no TeX run). */
15
25
  texOnly?: boolean;
26
+ /** Use this ID when the record has none, instead of minting one (for redlines). */
27
+ docIdFallback?: string;
28
+ /** Write output here instead of out/<document>/. */
29
+ outDir?: string;
16
30
  onOutput?: (chunk: string) => void;
17
31
  }
18
32
  export interface BuildResult {
19
33
  name: string;
34
+ /** The template the document uses. */
35
+ template: string;
20
36
  variant: Variant;
21
37
  tex: string;
22
38
  pdf: string | null;
@@ -27,12 +43,22 @@ export interface BuildResult {
27
43
  sourceDateEpoch: number;
28
44
  reproducible: boolean;
29
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;
30
52
  diagnostics: Diagnostic[];
31
53
  }
32
54
  export declare class BuildError extends Error {
33
55
  readonly diagnostics: Diagnostic[];
34
56
  constructor(message: string, diagnostics: Diagnostic[]);
35
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;
36
62
  /** Build one document record. */
37
63
  export declare function buildDocument(project: Project, file: string, options?: BuildOptions): Promise<BuildResult>;
38
64
  /** Build a template as a blank form, without a record. */