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