latex-kit 0.0.0-stage → 0.2.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.
- package/LICENSE +23 -0
- package/README.md +67 -2
- package/args.d.ts +9 -0
- package/args.js +37 -0
- package/commands.d.ts +4 -0
- package/commands.js +39 -0
- package/doctor.d.ts +2 -0
- package/doctor.js +23 -0
- package/esm/args.d.ts +9 -0
- package/esm/args.js +32 -0
- package/esm/commands.d.ts +4 -0
- package/esm/commands.js +34 -0
- package/esm/doctor.d.ts +2 -0
- package/esm/doctor.js +17 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +15 -0
- package/esm/render.d.ts +3 -0
- package/esm/render.js +82 -0
- package/esm/usage.d.ts +1 -0
- package/esm/usage.js +41 -0
- package/index.d.ts +2 -0
- package/index.js +17 -0
- package/package.json +51 -4
- package/render.d.ts +3 -0
- package/render.js +88 -0
- package/usage.d.ts +1 -0
- package/usage.js +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2026 Constructive <developers@constructive.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# latex-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/constructive-io/latex-kit/actions/workflows/ci.yml">
|
|
9
|
+
<img height="20" src="https://github.com/constructive-io/latex-kit/actions/workflows/ci.yml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/constructive-io/latex-kit/blob/main/LICENSE">
|
|
12
|
+
<img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/latex-kit">
|
|
15
|
+
<img height="20" src="https://img.shields.io/npm/v/latex-kit.svg"/>
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">Build typed, reproducible LaTeX documents from the command line.</p>
|
|
20
|
+
|
|
21
|
+
The command-line front end for the `@latex-kit/*` packages. The binary is
|
|
22
|
+
`latex-kit`, not `latex`, so it never shadows TeX's own `latex`.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g latex-kit
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
latex-kit doctor # is Docker ready?
|
|
34
|
+
latex-kit render examples/letter/letter.tex # → out/letter.pdf
|
|
35
|
+
latex-kit render paper.tex --engine xelatex -o build
|
|
36
|
+
latex-kit render letter.tex --verify # build twice, fail if the bytes differ
|
|
37
|
+
latex-kit render letter.tex --json # machine-readable summary
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### `render <file.tex>`
|
|
41
|
+
|
|
42
|
+
| Flag | Default | |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `-o, --out <dir>` | `out` | Output directory, relative to `--root` |
|
|
45
|
+
| `-e, --engine <name>` | `lualatex` | `lualatex`, `xelatex`, `pdflatex` |
|
|
46
|
+
| `--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` |
|
|
49
|
+
| `--local` | | Use `latexmk` on `PATH` instead of Docker (not pinned) |
|
|
50
|
+
| `--source-date-epoch <s>` | `SOURCE_DATE_EPOCH`, else the last git commit | Build timestamp |
|
|
51
|
+
| `--verify` | | Build twice; exit 1 if the PDFs differ |
|
|
52
|
+
| `--json` | | Print a JSON summary |
|
|
53
|
+
|
|
54
|
+
### `doctor`
|
|
55
|
+
|
|
56
|
+
Checks Node, the Docker daemon, whether the image is pulled and runs
|
|
57
|
+
natively on this machine, and whether a local `latexmk` exists. Exits 1 if
|
|
58
|
+
rendering cannot work.
|
|
59
|
+
|
|
60
|
+
## Credits
|
|
61
|
+
|
|
62
|
+
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
63
|
+
|
|
64
|
+
## Disclaimer
|
|
65
|
+
|
|
66
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
67
|
+
|
|
68
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
package/args.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RenderOptions } from '@latex-kit/render';
|
|
2
|
+
import type { ParsedArgs } from 'minimist';
|
|
3
|
+
export declare class UsageError extends Error {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
/** Turn `latex-kit render` flags into render options. Pure, for testing. */
|
|
7
|
+
export declare function renderOptionsFromArgv(argv: Partial<ParsedArgs>): Omit<RenderOptions, 'file'> & {
|
|
8
|
+
file?: string;
|
|
9
|
+
};
|
package/args.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsageError = void 0;
|
|
4
|
+
exports.renderOptionsFromArgv = renderOptionsFromArgv;
|
|
5
|
+
const render_1 = require("@latex-kit/render");
|
|
6
|
+
class UsageError extends Error {
|
|
7
|
+
name = 'UsageError';
|
|
8
|
+
}
|
|
9
|
+
exports.UsageError = UsageError;
|
|
10
|
+
/** Turn `latex-kit render` flags into render options. Pure, for testing. */
|
|
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(', ')}`);
|
|
15
|
+
}
|
|
16
|
+
let sourceDateEpoch;
|
|
17
|
+
if (argv['source-date-epoch'] !== undefined) {
|
|
18
|
+
const raw = String(argv['source-date-epoch']);
|
|
19
|
+
if (!/^\d+$/.test(raw))
|
|
20
|
+
throw new UsageError('--source-date-epoch must be a whole number of seconds');
|
|
21
|
+
sourceDateEpoch = Number(raw);
|
|
22
|
+
}
|
|
23
|
+
const backend = argv.local ? 'local' : 'docker';
|
|
24
|
+
if (backend === 'local' && (argv.image || argv.platform)) {
|
|
25
|
+
throw new UsageError('--image and --platform only apply to the docker backend');
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
file: argv._?.[0] !== undefined ? String(argv._[0]) : argv.file,
|
|
29
|
+
root: argv.root,
|
|
30
|
+
outDir: argv.out ?? 'out',
|
|
31
|
+
engine,
|
|
32
|
+
backend,
|
|
33
|
+
image: argv.image,
|
|
34
|
+
platform: argv.platform,
|
|
35
|
+
sourceDateEpoch,
|
|
36
|
+
};
|
|
37
|
+
}
|
package/commands.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CLIOptions, Inquirerer } from 'inquirerer';
|
|
2
|
+
import type { ParsedArgs } from 'minimist';
|
|
3
|
+
export declare function version(): string;
|
|
4
|
+
export declare const commands: (argv: Partial<ParsedArgs>, prompter: Inquirerer, _options: CLIOptions) => Promise<Partial<ParsedArgs>>;
|
package/commands.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commands = void 0;
|
|
4
|
+
exports.version = version;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const doctor_1 = require("./doctor");
|
|
7
|
+
const render_1 = require("./render");
|
|
8
|
+
const usage_1 = require("./usage");
|
|
9
|
+
function version() {
|
|
10
|
+
return JSON.parse((0, fs_1.readFileSync)(require.resolve('../package.json'), 'utf8')).version;
|
|
11
|
+
}
|
|
12
|
+
const commands = async (argv, prompter, _options) => {
|
|
13
|
+
const [command, ...rest] = (argv._ ?? []).map(String);
|
|
14
|
+
if (argv.version) {
|
|
15
|
+
console.log(version());
|
|
16
|
+
return argv;
|
|
17
|
+
}
|
|
18
|
+
if (!command || argv.help || command === 'help') {
|
|
19
|
+
(0, usage_1.help)(command === 'help' ? rest[0] : argv.help ? command : undefined);
|
|
20
|
+
return argv;
|
|
21
|
+
}
|
|
22
|
+
let code;
|
|
23
|
+
switch (command) {
|
|
24
|
+
case 'render':
|
|
25
|
+
code = await (0, render_1.renderCommand)({ ...argv, _: rest }, prompter);
|
|
26
|
+
break;
|
|
27
|
+
case 'doctor':
|
|
28
|
+
code = await (0, doctor_1.doctorCommand)({ ...argv, _: rest });
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
console.error(`unknown command: ${command}\n`);
|
|
32
|
+
(0, usage_1.help)();
|
|
33
|
+
code = 2;
|
|
34
|
+
}
|
|
35
|
+
if (code !== 0)
|
|
36
|
+
process.exitCode = code;
|
|
37
|
+
return argv;
|
|
38
|
+
};
|
|
39
|
+
exports.commands = commands;
|
package/doctor.d.ts
ADDED
package/doctor.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.doctorCommand = doctorCommand;
|
|
7
|
+
const render_1 = require("@latex-kit/render");
|
|
8
|
+
const yanse_1 = __importDefault(require("yanse"));
|
|
9
|
+
const MARK = { ok: yanse_1.default.green('✓'), warn: yanse_1.default.yellow('!'), fail: yanse_1.default.red('✗'), info: yanse_1.default.dim('·') };
|
|
10
|
+
async function doctorCommand(argv) {
|
|
11
|
+
const checks = await (0, render_1.doctor)(argv.image);
|
|
12
|
+
if (argv.json) {
|
|
13
|
+
console.log(JSON.stringify(checks, null, 2));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
for (const c of checks) {
|
|
17
|
+
console.log(`${MARK[c.status]} ${c.name.padEnd(14)} ${c.detail}`);
|
|
18
|
+
if (c.hint)
|
|
19
|
+
console.log(` ${''.padEnd(14)} ${yanse_1.default.dim(c.hint)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return checks.some((c) => c.status === 'fail') ? 1 : 0;
|
|
23
|
+
}
|
package/esm/args.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RenderOptions } from '@latex-kit/render';
|
|
2
|
+
import type { ParsedArgs } from 'minimist';
|
|
3
|
+
export declare class UsageError extends Error {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
/** Turn `latex-kit render` flags into render options. Pure, for testing. */
|
|
7
|
+
export declare function renderOptionsFromArgv(argv: Partial<ParsedArgs>): Omit<RenderOptions, 'file'> & {
|
|
8
|
+
file?: string;
|
|
9
|
+
};
|
package/esm/args.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ENGINES } from '@latex-kit/render';
|
|
2
|
+
export class UsageError extends Error {
|
|
3
|
+
name = 'UsageError';
|
|
4
|
+
}
|
|
5
|
+
/** Turn `latex-kit render` flags into render options. Pure, for testing. */
|
|
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(', ')}`);
|
|
10
|
+
}
|
|
11
|
+
let sourceDateEpoch;
|
|
12
|
+
if (argv['source-date-epoch'] !== undefined) {
|
|
13
|
+
const raw = String(argv['source-date-epoch']);
|
|
14
|
+
if (!/^\d+$/.test(raw))
|
|
15
|
+
throw new UsageError('--source-date-epoch must be a whole number of seconds');
|
|
16
|
+
sourceDateEpoch = Number(raw);
|
|
17
|
+
}
|
|
18
|
+
const backend = argv.local ? 'local' : 'docker';
|
|
19
|
+
if (backend === 'local' && (argv.image || argv.platform)) {
|
|
20
|
+
throw new UsageError('--image and --platform only apply to the docker backend');
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
file: argv._?.[0] !== undefined ? String(argv._[0]) : argv.file,
|
|
24
|
+
root: argv.root,
|
|
25
|
+
outDir: argv.out ?? 'out',
|
|
26
|
+
engine,
|
|
27
|
+
backend,
|
|
28
|
+
image: argv.image,
|
|
29
|
+
platform: argv.platform,
|
|
30
|
+
sourceDateEpoch,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CLIOptions, Inquirerer } from 'inquirerer';
|
|
2
|
+
import type { ParsedArgs } from 'minimist';
|
|
3
|
+
export declare function version(): string;
|
|
4
|
+
export declare const commands: (argv: Partial<ParsedArgs>, prompter: Inquirerer, _options: CLIOptions) => Promise<Partial<ParsedArgs>>;
|
package/esm/commands.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { doctorCommand } from './doctor';
|
|
3
|
+
import { renderCommand } from './render';
|
|
4
|
+
import { help } from './usage';
|
|
5
|
+
export function version() {
|
|
6
|
+
return JSON.parse(readFileSync(require.resolve('../package.json'), 'utf8')).version;
|
|
7
|
+
}
|
|
8
|
+
export const commands = async (argv, prompter, _options) => {
|
|
9
|
+
const [command, ...rest] = (argv._ ?? []).map(String);
|
|
10
|
+
if (argv.version) {
|
|
11
|
+
console.log(version());
|
|
12
|
+
return argv;
|
|
13
|
+
}
|
|
14
|
+
if (!command || argv.help || command === 'help') {
|
|
15
|
+
help(command === 'help' ? rest[0] : argv.help ? command : undefined);
|
|
16
|
+
return argv;
|
|
17
|
+
}
|
|
18
|
+
let code;
|
|
19
|
+
switch (command) {
|
|
20
|
+
case 'render':
|
|
21
|
+
code = await renderCommand({ ...argv, _: rest }, prompter);
|
|
22
|
+
break;
|
|
23
|
+
case 'doctor':
|
|
24
|
+
code = await doctorCommand({ ...argv, _: rest });
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
console.error(`unknown command: ${command}\n`);
|
|
28
|
+
help();
|
|
29
|
+
code = 2;
|
|
30
|
+
}
|
|
31
|
+
if (code !== 0)
|
|
32
|
+
process.exitCode = code;
|
|
33
|
+
return argv;
|
|
34
|
+
};
|
package/esm/doctor.d.ts
ADDED
package/esm/doctor.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { doctor } from '@latex-kit/render';
|
|
2
|
+
import chalk from 'yanse';
|
|
3
|
+
const MARK = { ok: chalk.green('✓'), warn: chalk.yellow('!'), fail: chalk.red('✗'), info: chalk.dim('·') };
|
|
4
|
+
export async function doctorCommand(argv) {
|
|
5
|
+
const checks = await doctor(argv.image);
|
|
6
|
+
if (argv.json) {
|
|
7
|
+
console.log(JSON.stringify(checks, null, 2));
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
for (const c of checks) {
|
|
11
|
+
console.log(`${MARK[c.status]} ${c.name.padEnd(14)} ${c.detail}`);
|
|
12
|
+
if (c.hint)
|
|
13
|
+
console.log(` ${''.padEnd(14)} ${chalk.dim(c.hint)}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return checks.some((c) => c.status === 'fail') ? 1 : 0;
|
|
17
|
+
}
|
package/esm/index.d.ts
ADDED
package/esm/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CLI } from 'inquirerer';
|
|
3
|
+
import { commands } from './commands';
|
|
4
|
+
const app = new CLI(commands, {
|
|
5
|
+
noTty: !process.stdin.isTTY,
|
|
6
|
+
minimistOpts: {
|
|
7
|
+
alias: { h: 'help', v: 'version', o: 'out', e: 'engine' },
|
|
8
|
+
boolean: ['help', 'version', 'local', 'verify', 'json'],
|
|
9
|
+
string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch'],
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
app.run().catch((error) => {
|
|
13
|
+
console.error(error instanceof Error ? error.message : error);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
});
|
package/esm/render.d.ts
ADDED
package/esm/render.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { formatDiagnostic, render, RenderError } from '@latex-kit/render';
|
|
2
|
+
import { rmSync } from 'fs';
|
|
3
|
+
import { dirname, relative } from 'path';
|
|
4
|
+
import chalk from 'yanse';
|
|
5
|
+
import { renderOptionsFromArgv, UsageError } from './args';
|
|
6
|
+
function summary(r) {
|
|
7
|
+
return {
|
|
8
|
+
pdf: relative(process.cwd(), r.pdf),
|
|
9
|
+
sha256: r.sha256,
|
|
10
|
+
engine: r.engine,
|
|
11
|
+
backend: r.backend,
|
|
12
|
+
image: r.image,
|
|
13
|
+
sourceDateEpoch: r.sourceDateEpoch,
|
|
14
|
+
epochSource: r.epochSource,
|
|
15
|
+
reproducible: r.reproducible,
|
|
16
|
+
warnings: r.diagnostics.filter((d) => d.severity === 'warning').length,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export async function renderCommand(argv, prompter) {
|
|
20
|
+
let opts;
|
|
21
|
+
try {
|
|
22
|
+
opts = renderOptionsFromArgv(argv);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
if (e instanceof UsageError) {
|
|
26
|
+
console.error(chalk.red(e.message));
|
|
27
|
+
return 2;
|
|
28
|
+
}
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
if (!opts.file) {
|
|
32
|
+
const answers = await prompter.prompt({}, [
|
|
33
|
+
{ type: 'text', name: 'file', message: 'Which .tex file?', required: true },
|
|
34
|
+
]);
|
|
35
|
+
opts.file = answers.file;
|
|
36
|
+
}
|
|
37
|
+
const log = (s) => {
|
|
38
|
+
if (!argv.json)
|
|
39
|
+
console.error(s);
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
log(chalk.dim(`rendering ${opts.file} with ${opts.engine} (${opts.backend})…`));
|
|
43
|
+
const first = await render({ ...opts, file: opts.file });
|
|
44
|
+
for (const d of first.diagnostics)
|
|
45
|
+
log(chalk.yellow(formatDiagnostic(d)));
|
|
46
|
+
if (!first.reproducible) {
|
|
47
|
+
log(chalk.yellow('warning: no SOURCE_DATE_EPOCH and the file is not committed; the build date is "now", so builds will differ'));
|
|
48
|
+
}
|
|
49
|
+
let verified;
|
|
50
|
+
if (argv.verify) {
|
|
51
|
+
const verifyDir = `${opts.outDir}.verify`;
|
|
52
|
+
log(chalk.dim('rendering again to check the output is byte-identical…'));
|
|
53
|
+
const second = await render({ ...opts, file: opts.file, outDir: verifyDir, sourceDateEpoch: first.sourceDateEpoch });
|
|
54
|
+
verified = second.sha256 === first.sha256;
|
|
55
|
+
rmSync(dirname(second.pdf), { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
if (argv.json) {
|
|
58
|
+
console.log(JSON.stringify({ ...summary(first), verified }, null, 2));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.log(`${chalk.green('✓')} ${relative(process.cwd(), first.pdf)}`);
|
|
62
|
+
console.log(chalk.dim(` sha256 ${first.sha256}`));
|
|
63
|
+
console.log(chalk.dim(` date ${new Date(first.sourceDateEpoch * 1000).toISOString()} (from ${first.epochSource})`));
|
|
64
|
+
if (verified !== undefined) {
|
|
65
|
+
console.log(verified ? `${chalk.green('✓')} byte-identical on a second build` : chalk.red('✗ second build differs'));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return verified === false ? 1 : 0;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (e instanceof RenderError) {
|
|
72
|
+
console.error(chalk.red(e.message));
|
|
73
|
+
for (const d of e.diagnostics)
|
|
74
|
+
console.error(formatDiagnostic(d));
|
|
75
|
+
if (e.diagnostics.length === 0 && e.output) {
|
|
76
|
+
console.error(chalk.dim(e.output.split('\n').slice(-25).join('\n')));
|
|
77
|
+
}
|
|
78
|
+
return 1;
|
|
79
|
+
}
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
}
|
package/esm/usage.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function help(command?: string): void;
|
package/esm/usage.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const MAIN = `latex-kit — build typed, reproducible LaTeX documents
|
|
2
|
+
|
|
3
|
+
Usage
|
|
4
|
+
latex-kit <command> [options]
|
|
5
|
+
|
|
6
|
+
Commands
|
|
7
|
+
render <file.tex> Build a PDF with latexmk in a pinned Docker image
|
|
8
|
+
doctor Check Docker, the image and local TeX
|
|
9
|
+
|
|
10
|
+
Options
|
|
11
|
+
-h, --help Show help (latex-kit help <command> for details)
|
|
12
|
+
-v, --version Show the version
|
|
13
|
+
`;
|
|
14
|
+
const RENDER = `latex-kit render <file.tex> [options]
|
|
15
|
+
|
|
16
|
+
Builds <file.tex> with latexmk. The build date is taken from
|
|
17
|
+
SOURCE_DATE_EPOCH, else the file's last git commit, so the same commit
|
|
18
|
+
always produces the same PDF bytes.
|
|
19
|
+
|
|
20
|
+
Options
|
|
21
|
+
-o, --out <dir> Output directory, relative to --root (default: out)
|
|
22
|
+
-e, --engine <name> lualatex (default), xelatex or pdflatex
|
|
23
|
+
--root <dir> Directory TeX can see (default: current directory)
|
|
24
|
+
--image <ref> Docker image (default: pinned pyramation/latex digest)
|
|
25
|
+
--platform <os/arch> Docker --platform (default: linux/amd64 for the default image)
|
|
26
|
+
--local Use latexmk on PATH instead of Docker (not pinned)
|
|
27
|
+
--source-date-epoch <s> Build timestamp in seconds since 1970
|
|
28
|
+
--verify Build twice and fail if the PDFs differ
|
|
29
|
+
--json Print a JSON summary on stdout
|
|
30
|
+
|
|
31
|
+
Only lualatex is byte-reproducible in the default image.
|
|
32
|
+
`;
|
|
33
|
+
const DOCTOR = `latex-kit doctor [--image <ref>] [--json]
|
|
34
|
+
|
|
35
|
+
Reports the Node version, whether Docker is running, whether the image is
|
|
36
|
+
pulled and whether it runs natively on this machine, and whether latexmk
|
|
37
|
+
is available for --local builds. Exits 1 if rendering cannot work.
|
|
38
|
+
`;
|
|
39
|
+
export function help(command) {
|
|
40
|
+
console.log(command === 'render' ? RENDER : command === 'doctor' ? DOCTOR : MAIN);
|
|
41
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const inquirerer_1 = require("inquirerer");
|
|
5
|
+
const commands_1 = require("./commands");
|
|
6
|
+
const app = new inquirerer_1.CLI(commands_1.commands, {
|
|
7
|
+
noTty: !process.stdin.isTTY,
|
|
8
|
+
minimistOpts: {
|
|
9
|
+
alias: { h: 'help', v: 'version', o: 'out', e: 'engine' },
|
|
10
|
+
boolean: ['help', 'version', 'local', 'verify', 'json'],
|
|
11
|
+
string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch'],
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
app.run().catch((error) => {
|
|
15
|
+
console.error(error instanceof Error ? error.message : error);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "latex-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Build typed, reproducible LaTeX documents from the command line",
|
|
5
|
+
"author": "Constructive <developers@constructive.io>",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/constructive-io/latex-kit",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/constructive-io/latex-kit"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/constructive-io/latex-kit/issues"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"copy": "makage assets",
|
|
24
|
+
"clean": "makage clean",
|
|
25
|
+
"prepublishOnly": "npm run build",
|
|
26
|
+
"build": "makage build",
|
|
27
|
+
"build:dev": "makage build --dev",
|
|
28
|
+
"lint": "eslint . --fix",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/minimist": "^1.2.5",
|
|
34
|
+
"makage": "^0.8.0"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"latex",
|
|
38
|
+
"tex",
|
|
39
|
+
"pdf",
|
|
40
|
+
"cli",
|
|
41
|
+
"reproducible-builds"
|
|
42
|
+
],
|
|
43
|
+
"bin": {
|
|
44
|
+
"latex-kit": "index.js"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@latex-kit/render": "0.2.0",
|
|
48
|
+
"inquirerer": "^4.9.5",
|
|
49
|
+
"minimist": "^1.2.8",
|
|
50
|
+
"yanse": "^0.2.3"
|
|
51
|
+
},
|
|
52
|
+
"gitHead": "b88becdf229a9f5689fcc3b8ff087f718e04f216"
|
|
53
|
+
}
|
package/render.d.ts
ADDED
package/render.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.renderCommand = renderCommand;
|
|
7
|
+
const render_1 = require("@latex-kit/render");
|
|
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");
|
|
12
|
+
function summary(r) {
|
|
13
|
+
return {
|
|
14
|
+
pdf: (0, path_1.relative)(process.cwd(), r.pdf),
|
|
15
|
+
sha256: r.sha256,
|
|
16
|
+
engine: r.engine,
|
|
17
|
+
backend: r.backend,
|
|
18
|
+
image: r.image,
|
|
19
|
+
sourceDateEpoch: r.sourceDateEpoch,
|
|
20
|
+
epochSource: r.epochSource,
|
|
21
|
+
reproducible: r.reproducible,
|
|
22
|
+
warnings: r.diagnostics.filter((d) => d.severity === 'warning').length,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async function renderCommand(argv, prompter) {
|
|
26
|
+
let opts;
|
|
27
|
+
try {
|
|
28
|
+
opts = (0, args_1.renderOptionsFromArgv)(argv);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (e instanceof args_1.UsageError) {
|
|
32
|
+
console.error(yanse_1.default.red(e.message));
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
if (!opts.file) {
|
|
38
|
+
const answers = await prompter.prompt({}, [
|
|
39
|
+
{ type: 'text', name: 'file', message: 'Which .tex file?', required: true },
|
|
40
|
+
]);
|
|
41
|
+
opts.file = answers.file;
|
|
42
|
+
}
|
|
43
|
+
const log = (s) => {
|
|
44
|
+
if (!argv.json)
|
|
45
|
+
console.error(s);
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
log(yanse_1.default.dim(`rendering ${opts.file} with ${opts.engine} (${opts.backend})…`));
|
|
49
|
+
const first = await (0, render_1.render)({ ...opts, file: opts.file });
|
|
50
|
+
for (const d of first.diagnostics)
|
|
51
|
+
log(yanse_1.default.yellow((0, render_1.formatDiagnostic)(d)));
|
|
52
|
+
if (!first.reproducible) {
|
|
53
|
+
log(yanse_1.default.yellow('warning: no SOURCE_DATE_EPOCH and the file is not committed; the build date is "now", so builds will differ'));
|
|
54
|
+
}
|
|
55
|
+
let verified;
|
|
56
|
+
if (argv.verify) {
|
|
57
|
+
const verifyDir = `${opts.outDir}.verify`;
|
|
58
|
+
log(yanse_1.default.dim('rendering again to check the output is byte-identical…'));
|
|
59
|
+
const second = await (0, render_1.render)({ ...opts, file: opts.file, outDir: verifyDir, sourceDateEpoch: first.sourceDateEpoch });
|
|
60
|
+
verified = second.sha256 === first.sha256;
|
|
61
|
+
(0, fs_1.rmSync)((0, path_1.dirname)(second.pdf), { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
if (argv.json) {
|
|
64
|
+
console.log(JSON.stringify({ ...summary(first), verified }, null, 2));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.log(`${yanse_1.default.green('✓')} ${(0, path_1.relative)(process.cwd(), first.pdf)}`);
|
|
68
|
+
console.log(yanse_1.default.dim(` sha256 ${first.sha256}`));
|
|
69
|
+
console.log(yanse_1.default.dim(` date ${new Date(first.sourceDateEpoch * 1000).toISOString()} (from ${first.epochSource})`));
|
|
70
|
+
if (verified !== undefined) {
|
|
71
|
+
console.log(verified ? `${yanse_1.default.green('✓')} byte-identical on a second build` : yanse_1.default.red('✗ second build differs'));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return verified === false ? 1 : 0;
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
if (e instanceof render_1.RenderError) {
|
|
78
|
+
console.error(yanse_1.default.red(e.message));
|
|
79
|
+
for (const d of e.diagnostics)
|
|
80
|
+
console.error((0, render_1.formatDiagnostic)(d));
|
|
81
|
+
if (e.diagnostics.length === 0 && e.output) {
|
|
82
|
+
console.error(yanse_1.default.dim(e.output.split('\n').slice(-25).join('\n')));
|
|
83
|
+
}
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
}
|
package/usage.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function help(command?: string): void;
|
package/usage.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.help = help;
|
|
4
|
+
const MAIN = `latex-kit — build typed, reproducible LaTeX documents
|
|
5
|
+
|
|
6
|
+
Usage
|
|
7
|
+
latex-kit <command> [options]
|
|
8
|
+
|
|
9
|
+
Commands
|
|
10
|
+
render <file.tex> Build a PDF with latexmk in a pinned Docker image
|
|
11
|
+
doctor Check Docker, the image and local TeX
|
|
12
|
+
|
|
13
|
+
Options
|
|
14
|
+
-h, --help Show help (latex-kit help <command> for details)
|
|
15
|
+
-v, --version Show the version
|
|
16
|
+
`;
|
|
17
|
+
const RENDER = `latex-kit render <file.tex> [options]
|
|
18
|
+
|
|
19
|
+
Builds <file.tex> with latexmk. The build date is taken from
|
|
20
|
+
SOURCE_DATE_EPOCH, else the file's last git commit, so the same commit
|
|
21
|
+
always produces the same PDF bytes.
|
|
22
|
+
|
|
23
|
+
Options
|
|
24
|
+
-o, --out <dir> Output directory, relative to --root (default: out)
|
|
25
|
+
-e, --engine <name> lualatex (default), xelatex or pdflatex
|
|
26
|
+
--root <dir> Directory TeX can see (default: current directory)
|
|
27
|
+
--image <ref> Docker image (default: pinned pyramation/latex digest)
|
|
28
|
+
--platform <os/arch> Docker --platform (default: linux/amd64 for the default image)
|
|
29
|
+
--local Use latexmk on PATH instead of Docker (not pinned)
|
|
30
|
+
--source-date-epoch <s> Build timestamp in seconds since 1970
|
|
31
|
+
--verify Build twice and fail if the PDFs differ
|
|
32
|
+
--json Print a JSON summary on stdout
|
|
33
|
+
|
|
34
|
+
Only lualatex is byte-reproducible in the default image.
|
|
35
|
+
`;
|
|
36
|
+
const DOCTOR = `latex-kit doctor [--image <ref>] [--json]
|
|
37
|
+
|
|
38
|
+
Reports the Node version, whether Docker is running, whether the image is
|
|
39
|
+
pulled and whether it runs natively on this machine, and whether latexmk
|
|
40
|
+
is available for --local builds. Exits 1 if rendering cannot work.
|
|
41
|
+
`;
|
|
42
|
+
function help(command) {
|
|
43
|
+
console.log(command === 'render' ? RENDER : command === 'doctor' ? DOCTOR : MAIN);
|
|
44
|
+
}
|