latex-kit 0.2.0 → 0.4.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.
- package/README.md +3 -3
- package/boilerplates.d.ts +8 -0
- package/boilerplates.js +225 -0
- package/build.d.ts +45 -0
- package/build.js +226 -0
- package/check.d.ts +17 -0
- package/check.js +58 -0
- package/cli.d.ts +2 -0
- package/cli.js +31 -0
- package/commands.d.ts +1 -0
- package/commands.js +51 -15
- package/config.d.ts +28 -0
- package/config.js +30 -0
- package/diff.d.ts +25 -0
- package/diff.js +112 -0
- package/esm/boilerplates.d.ts +8 -0
- package/esm/boilerplates.js +220 -0
- package/esm/build.d.ts +45 -0
- package/esm/build.js +220 -0
- package/esm/check.d.ts +17 -0
- package/esm/check.js +54 -0
- package/esm/cli.d.ts +2 -0
- package/esm/cli.js +29 -0
- package/esm/commands.d.ts +1 -0
- package/esm/commands.js +49 -16
- package/esm/config.d.ts +28 -0
- package/esm/config.js +25 -0
- package/esm/diff.d.ts +25 -0
- package/esm/diff.js +108 -0
- package/esm/import.d.ts +24 -0
- package/esm/import.js +113 -0
- package/esm/index.d.ts +15 -2
- package/esm/index.js +15 -15
- package/esm/project-commands.d.ts +16 -0
- package/esm/project-commands.js +324 -0
- package/esm/project.d.ts +46 -0
- package/esm/project.js +139 -0
- package/esm/render.js +3 -5
- package/esm/scaffold.d.ts +27 -0
- package/esm/scaffold.js +108 -0
- package/esm/usage.js +53 -6
- package/import.d.ts +24 -0
- package/import.js +118 -0
- package/index.d.ts +15 -2
- package/index.js +29 -15
- package/package.json +8 -6
- package/project-commands.d.ts +16 -0
- package/project-commands.js +340 -0
- package/project.d.ts +46 -0
- package/project.js +143 -0
- package/render.js +2 -4
- package/scaffold.d.ts +27 -0
- package/scaffold.js +115 -0
- package/usage.js +53 -6
package/commands.js
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.commands = void 0;
|
|
4
7
|
exports.version = version;
|
|
5
8
|
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
11
|
+
const args_1 = require("./args");
|
|
6
12
|
const doctor_1 = require("./doctor");
|
|
13
|
+
const project_commands_1 = require("./project-commands");
|
|
7
14
|
const render_1 = require("./render");
|
|
8
15
|
const usage_1 = require("./usage");
|
|
16
|
+
/** The package version, from package.json next to the built files. */
|
|
9
17
|
function version() {
|
|
10
|
-
|
|
18
|
+
for (const p of [(0, path_1.join)(__dirname, 'package.json'), (0, path_1.join)(__dirname, '..', 'package.json')]) {
|
|
19
|
+
if ((0, fs_1.existsSync)(p)) {
|
|
20
|
+
const pkg = JSON.parse((0, fs_1.readFileSync)(p, 'utf8'));
|
|
21
|
+
if (pkg.name === 'latex-kit')
|
|
22
|
+
return pkg.version;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return 'unknown';
|
|
11
26
|
}
|
|
27
|
+
const COMMANDS = {
|
|
28
|
+
init: project_commands_1.initCommand,
|
|
29
|
+
new: project_commands_1.newCommand,
|
|
30
|
+
build: project_commands_1.buildCommand,
|
|
31
|
+
watch: project_commands_1.watchCommand,
|
|
32
|
+
clean: project_commands_1.cleanCommand,
|
|
33
|
+
check: project_commands_1.checkCommand,
|
|
34
|
+
fields: project_commands_1.fieldsCommand,
|
|
35
|
+
typegen: project_commands_1.typegenCommand,
|
|
36
|
+
import: project_commands_1.importCommand,
|
|
37
|
+
diff: project_commands_1.diffCommand,
|
|
38
|
+
sty: project_commands_1.styCommand,
|
|
39
|
+
render: render_1.renderCommand,
|
|
40
|
+
doctor: doctor_1.doctorCommand,
|
|
41
|
+
};
|
|
12
42
|
const commands = async (argv, prompter, _options) => {
|
|
13
43
|
const [command, ...rest] = (argv._ ?? []).map(String);
|
|
14
44
|
if (argv.version) {
|
|
@@ -19,21 +49,27 @@ const commands = async (argv, prompter, _options) => {
|
|
|
19
49
|
(0, usage_1.help)(command === 'help' ? rest[0] : argv.help ? command : undefined);
|
|
20
50
|
return argv;
|
|
21
51
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
const run = COMMANDS[command];
|
|
53
|
+
if (!run) {
|
|
54
|
+
console.error(`unknown command: ${command}\n`);
|
|
55
|
+
(0, usage_1.help)();
|
|
56
|
+
process.exitCode = 2;
|
|
57
|
+
return argv;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const code = await run({ ...argv, _: rest }, prompter);
|
|
61
|
+
if (code !== 0)
|
|
62
|
+
process.exitCode = code;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (e instanceof args_1.UsageError) {
|
|
66
|
+
console.error(yanse_1.default.red(e.message));
|
|
67
|
+
process.exitCode = 2;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
34
72
|
}
|
|
35
|
-
if (code !== 0)
|
|
36
|
-
process.exitCode = code;
|
|
37
73
|
return argv;
|
|
38
74
|
};
|
|
39
75
|
exports.commands = commands;
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Backend, Engine } from '@latex-kit/render';
|
|
2
|
+
/** latex-kit.config.ts (or .js, .mjs, .cjs, .json) at the project root. */
|
|
3
|
+
export interface LatexKitConfig {
|
|
4
|
+
/** One folder per template: `<templates>/<name>/template.tex` and optional `schema.ts`. Default `templates`. */
|
|
5
|
+
templates?: string;
|
|
6
|
+
/** Shared pieces for \snippet{name}. Default `snippets`. */
|
|
7
|
+
snippets?: string;
|
|
8
|
+
/** The clause library for \\clause{id}: `<clauses>/<id>.tex`. Default `clauses`. */
|
|
9
|
+
clauses?: string;
|
|
10
|
+
/** Shared records that references point at: `<data>/<collection>/<id>.json`. Default `data`. */
|
|
11
|
+
data?: string;
|
|
12
|
+
/** Document records: `<documents>/<name>.json|yaml|ts`. Default `documents`. */
|
|
13
|
+
documents?: string;
|
|
14
|
+
/** Generated .tex and PDFs. Default `out`. */
|
|
15
|
+
out?: string;
|
|
16
|
+
/** Default locale for dates, numbers and money. Default `en-US`. */
|
|
17
|
+
locale?: string;
|
|
18
|
+
engine?: Engine;
|
|
19
|
+
backend?: Backend;
|
|
20
|
+
image?: string;
|
|
21
|
+
platform?: string | null;
|
|
22
|
+
}
|
|
23
|
+
export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform'> & {
|
|
24
|
+
file: string | null;
|
|
25
|
+
};
|
|
26
|
+
export declare function defineConfig(config: LatexKitConfig): LatexKitConfig;
|
|
27
|
+
export declare const CONFIG_FILES: string[];
|
|
28
|
+
export declare function loadConfig(root: string): Promise<ResolvedConfig>;
|
package/config.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONFIG_FILES = void 0;
|
|
4
|
+
exports.defineConfig = defineConfig;
|
|
5
|
+
exports.loadConfig = loadConfig;
|
|
6
|
+
const schema_1 = require("@latex-kit/schema");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
function defineConfig(config) {
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
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' };
|
|
14
|
+
async function loadConfig(root) {
|
|
15
|
+
for (const name of exports.CONFIG_FILES) {
|
|
16
|
+
const file = (0, path_1.join)((0, path_1.resolve)(root), name);
|
|
17
|
+
if (!(0, fs_1.existsSync)(file))
|
|
18
|
+
continue;
|
|
19
|
+
let config;
|
|
20
|
+
if (name.endsWith('.json')) {
|
|
21
|
+
config = JSON.parse((0, fs_1.readFileSync)(file, 'utf8'));
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const mod = await (0, schema_1.loadModule)(file);
|
|
25
|
+
config = (mod.default ?? mod);
|
|
26
|
+
}
|
|
27
|
+
return { ...DEFAULTS, ...config, file };
|
|
28
|
+
}
|
|
29
|
+
return { ...DEFAULTS, file: null };
|
|
30
|
+
}
|
package/diff.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Engine } from '@latex-kit/render';
|
|
2
|
+
import { Variant } from '@latex-kit/template';
|
|
3
|
+
import { Project } from './project';
|
|
4
|
+
export interface DiffOptions {
|
|
5
|
+
variant?: Variant;
|
|
6
|
+
engine?: Engine;
|
|
7
|
+
backend?: 'docker' | 'local';
|
|
8
|
+
image?: string;
|
|
9
|
+
platform?: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface DiffResult {
|
|
12
|
+
/** The redline PDF. */
|
|
13
|
+
pdf: string;
|
|
14
|
+
/** latexdiff's marked-up .tex. */
|
|
15
|
+
tex: string;
|
|
16
|
+
old: string;
|
|
17
|
+
new: string;
|
|
18
|
+
}
|
|
19
|
+
/** Redline two .tex files inside the project. */
|
|
20
|
+
export declare function diffFiles(project: Project, oldFile: string, newFile: string, options?: DiffOptions): Promise<DiffResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Redline a document against an earlier commit: build it as it was at `ref`
|
|
23
|
+
* (in a temporary git worktree) and as it is now, then latexdiff the two.
|
|
24
|
+
*/
|
|
25
|
+
export declare function diffDocument(project: Project, file: string, ref: string, options?: DiffOptions): Promise<DiffResult>;
|
package/diff.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.diffFiles = diffFiles;
|
|
4
|
+
exports.diffDocument = diffDocument;
|
|
5
|
+
const render_1 = require("@latex-kit/render");
|
|
6
|
+
const template_1 = require("@latex-kit/template");
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const os_1 = require("os");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const build_1 = require("./build");
|
|
12
|
+
const project_1 = require("./project");
|
|
13
|
+
function git(cwd, args) {
|
|
14
|
+
return (0, child_process_1.execFileSync)('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
15
|
+
}
|
|
16
|
+
/** latexdiff old → new in `dir`, then render the redline. */
|
|
17
|
+
async function redline(project, oldTex, newTex, dir, name, texInputs, options) {
|
|
18
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
19
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(dir, 'latex-kit.sty'), template_1.LATEX_KIT_STY);
|
|
20
|
+
const tex = (0, path_1.join)(dir, `${name}.tex`);
|
|
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 });
|
|
23
|
+
const r = await (0, render_1.render)({
|
|
24
|
+
file: tex,
|
|
25
|
+
root: project.root,
|
|
26
|
+
outDir: rel(dir),
|
|
27
|
+
engine: options.engine ?? project.config.engine ?? 'lualatex',
|
|
28
|
+
backend: options.backend ?? project.config.backend,
|
|
29
|
+
image: options.image ?? project.config.image,
|
|
30
|
+
platform: options.platform !== undefined ? options.platform : project.config.platform,
|
|
31
|
+
texInputs: [rel(dir), ...texInputs.map(rel)],
|
|
32
|
+
});
|
|
33
|
+
return { pdf: r.pdf, tex, old: oldTex, new: newTex };
|
|
34
|
+
}
|
|
35
|
+
/** Redline two .tex files inside the project. */
|
|
36
|
+
async function diffFiles(project, oldFile, newFile, options = {}) {
|
|
37
|
+
for (const f of [oldFile, newFile])
|
|
38
|
+
if (!(0, fs_1.existsSync)(f))
|
|
39
|
+
throw new Error(`no such file: ${project.rel(f)}`);
|
|
40
|
+
const name = `${(0, path_1.basename)(newFile, '.tex')}-vs-${(0, path_1.basename)(oldFile, '.tex')}`;
|
|
41
|
+
const dir = (0, path_1.join)(project.outDir, 'diff', name);
|
|
42
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
43
|
+
// copies inside out/, so the files are always visible to Docker
|
|
44
|
+
const oldCopy = (0, path_1.join)(dir, 'old.tex');
|
|
45
|
+
const newCopy = (0, path_1.join)(dir, 'new.tex');
|
|
46
|
+
(0, fs_1.copyFileSync)(oldFile, oldCopy);
|
|
47
|
+
(0, fs_1.copyFileSync)(newFile, newCopy);
|
|
48
|
+
return redline(project, oldCopy, newCopy, dir, name, [(0, path_1.dirname)(newFile)], options);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Redline a document against an earlier commit: build it as it was at `ref`
|
|
52
|
+
* (in a temporary git worktree) and as it is now, then latexdiff the two.
|
|
53
|
+
*/
|
|
54
|
+
async function diffDocument(project, file, ref, options = {}) {
|
|
55
|
+
const variant = options.variant ?? 'final';
|
|
56
|
+
let top;
|
|
57
|
+
try {
|
|
58
|
+
top = git(project.root, ['rev-parse', '--show-toplevel']);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new Error('diff --against needs the project to be in a git repository');
|
|
62
|
+
}
|
|
63
|
+
const relDoc = (0, path_1.relative)(top, file);
|
|
64
|
+
const relProject = (0, path_1.relative)(top, project.root);
|
|
65
|
+
let sha;
|
|
66
|
+
try {
|
|
67
|
+
sha = git(top, ['rev-parse', '--short', `${ref}^{commit}`]);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new Error(`unknown git ref: ${ref}`);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
git(top, ['cat-file', '-e', `${sha}:${relDoc}`]);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw new Error(`${relDoc} does not exist at ${ref}`);
|
|
77
|
+
}
|
|
78
|
+
const name = project.documentName(file);
|
|
79
|
+
const dir = (0, path_1.join)(project.outDir, name, 'diff');
|
|
80
|
+
const common = { variant, texOnly: true, strict: false, docIdFallback: 'UNASSIGNED' };
|
|
81
|
+
const current = await (0, build_1.buildDocument)(project, file, { ...common, outDir: (0, path_1.join)(dir, 'new') }).catch((e) => {
|
|
82
|
+
if (e instanceof build_1.BuildError)
|
|
83
|
+
throw new build_1.BuildError(`the current ${name} does not build: ${e.message}`, e.diagnostics);
|
|
84
|
+
throw e;
|
|
85
|
+
});
|
|
86
|
+
const tree = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'latex-kit-diff-'));
|
|
87
|
+
try {
|
|
88
|
+
git(top, ['worktree', 'add', '--detach', '--quiet', tree, sha]);
|
|
89
|
+
const oldProject = await project_1.Project.open((0, path_1.join)(tree, relProject));
|
|
90
|
+
const old = await (0, build_1.buildDocument)(oldProject, (0, path_1.join)(tree, relDoc), { ...common, outDir: (0, path_1.join)(dir, 'old') }).catch((e) => {
|
|
91
|
+
if (e instanceof build_1.BuildError)
|
|
92
|
+
throw new build_1.BuildError(`${name} at ${ref} (${sha}) does not build: ${e.message}`, e.diagnostics);
|
|
93
|
+
throw e;
|
|
94
|
+
});
|
|
95
|
+
const template = await project.template(current.template);
|
|
96
|
+
return await redline(project, old.tex, current.tex, dir, `${name}-vs-${sha}`, [template.dir], options);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
try {
|
|
100
|
+
git(top, ['worktree', 'remove', '--force', tree]);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
(0, fs_1.rmSync)(tree, { recursive: true, force: true });
|
|
104
|
+
try {
|
|
105
|
+
git(top, ['worktree', 'prune']);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// nothing left to clean
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -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
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Engine } from '@latex-kit/render';
|
|
2
|
+
import { Diagnostic, Variant } from '@latex-kit/template';
|
|
3
|
+
import { Project } from './project';
|
|
4
|
+
export interface BuildOptions {
|
|
5
|
+
variant?: Variant;
|
|
6
|
+
/** Fail on missing values even in drafts. Default: on when CI=true. */
|
|
7
|
+
strict?: boolean;
|
|
8
|
+
engine?: Engine;
|
|
9
|
+
backend?: 'docker' | 'local';
|
|
10
|
+
image?: string;
|
|
11
|
+
platform?: string | null;
|
|
12
|
+
/** Build twice and fail unless the PDFs are byte-identical. */
|
|
13
|
+
verify?: boolean;
|
|
14
|
+
/** Stop after writing the .tex (no TeX run). */
|
|
15
|
+
texOnly?: boolean;
|
|
16
|
+
/** Use this ID when the record has none, instead of minting one (for redlines). */
|
|
17
|
+
docIdFallback?: string;
|
|
18
|
+
/** Write output here instead of out/<document>/. */
|
|
19
|
+
outDir?: string;
|
|
20
|
+
onOutput?: (chunk: string) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface BuildResult {
|
|
23
|
+
name: string;
|
|
24
|
+
/** The template the document uses. */
|
|
25
|
+
template: string;
|
|
26
|
+
variant: Variant;
|
|
27
|
+
tex: string;
|
|
28
|
+
pdf: string | null;
|
|
29
|
+
sha256: string | null;
|
|
30
|
+
docId: string | null;
|
|
31
|
+
/** The ID was minted by this build and written to the record. */
|
|
32
|
+
minted: boolean;
|
|
33
|
+
sourceDateEpoch: number;
|
|
34
|
+
reproducible: boolean;
|
|
35
|
+
verified?: boolean;
|
|
36
|
+
diagnostics: Diagnostic[];
|
|
37
|
+
}
|
|
38
|
+
export declare class BuildError extends Error {
|
|
39
|
+
readonly diagnostics: Diagnostic[];
|
|
40
|
+
constructor(message: string, diagnostics: Diagnostic[]);
|
|
41
|
+
}
|
|
42
|
+
/** Build one document record. */
|
|
43
|
+
export declare function buildDocument(project: Project, file: string, options?: BuildOptions): Promise<BuildResult>;
|
|
44
|
+
/** Build a template as a blank form, without a record. */
|
|
45
|
+
export declare function buildBlank(project: Project, templateName: string, options?: BuildOptions): Promise<BuildResult>;
|