paperlint 18.1.0 → 18.2.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 (100) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/latex/document-class.d.ts +28 -5
  3. package/dist/adapters/latex/document-class.d.ts.map +1 -1
  4. package/dist/adapters/latex/document-class.js +208 -21
  5. package/dist/adapters/latex/document-class.js.map +1 -1
  6. package/dist/adapters/latex/index.d.ts +4 -4
  7. package/dist/adapters/latex/index.d.ts.map +1 -1
  8. package/dist/adapters/latex/index.js +5 -2
  9. package/dist/adapters/latex/index.js.map +1 -1
  10. package/dist/adapters/latex/parse.d.ts.map +1 -1
  11. package/dist/adapters/latex/parse.js +5 -0
  12. package/dist/adapters/latex/parse.js.map +1 -1
  13. package/dist/adapters/latex/prose.d.ts.map +1 -1
  14. package/dist/adapters/latex/prose.js +20 -4
  15. package/dist/adapters/latex/prose.js.map +1 -1
  16. package/dist/domain/body-pages.d.ts.map +1 -1
  17. package/dist/domain/body-pages.js +4 -2
  18. package/dist/domain/body-pages.js.map +1 -1
  19. package/dist/domain/tex-document.d.ts +52 -4
  20. package/dist/domain/tex-document.d.ts.map +1 -1
  21. package/dist/domain/tex-document.js +9 -0
  22. package/dist/domain/tex-document.js.map +1 -1
  23. package/dist/eslint-rules/latex-language.d.ts +10 -0
  24. package/dist/eslint-rules/latex-language.d.ts.map +1 -1
  25. package/dist/eslint-rules/latex-language.js +41 -2
  26. package/dist/eslint-rules/latex-language.js.map +1 -1
  27. package/dist/ports/latex.d.ts +13 -1
  28. package/dist/ports/latex.d.ts.map +1 -1
  29. package/dist/presets.d.ts +15 -0
  30. package/dist/presets.d.ts.map +1 -1
  31. package/dist/presets.js +9 -0
  32. package/dist/presets.js.map +1 -1
  33. package/dist/tex-requirements.d.ts +2 -0
  34. package/dist/tex-requirements.d.ts.map +1 -1
  35. package/dist/tex-requirements.js +7 -2
  36. package/dist/tex-requirements.js.map +1 -1
  37. package/dist/tex-venue-rules.d.ts +36 -3
  38. package/dist/tex-venue-rules.d.ts.map +1 -1
  39. package/dist/tex-venue-rules.js +181 -33
  40. package/dist/tex-venue-rules.js.map +1 -1
  41. package/docs/rules/cycle/port-done.md +3 -0
  42. package/docs/rules/tex/negated-sentences.md +1 -1
  43. package/docs/rules/tex/template.md +96 -1
  44. package/docs/rules.md +19 -14
  45. package/docs/venues.md +51 -12
  46. package/eslint-rules/latex-language.test.mjs +64 -1
  47. package/eslint-rules/latex-language.ts +44 -2
  48. package/eslint.config.mjs +1 -0
  49. package/fixtures/build-e2e/neurips/PIPELINE-STATUS.md +3 -0
  50. package/fixtures/build-e2e/neurips/expect.json +20 -0
  51. package/fixtures/build-e2e/neurips/paper.tex +60 -0
  52. package/fixtures/build-e2e/neurips/paperlint.json +1 -0
  53. package/fixtures/build-e2e/neurips-nostyle/PIPELINE-STATUS.md +3 -0
  54. package/fixtures/build-e2e/neurips-nostyle/expect.json +26 -0
  55. package/fixtures/build-e2e/neurips-nostyle/paper.tex +56 -0
  56. package/fixtures/build-e2e/neurips-nostyle/paperlint.json +1 -0
  57. package/fixtures/build-e2e/neurips-over/PIPELINE-STATUS.md +3 -0
  58. package/fixtures/build-e2e/neurips-over/expect.json +24 -0
  59. package/fixtures/build-e2e/neurips-over/paper.tex +56 -0
  60. package/fixtures/build-e2e/neurips-over/paperlint.json +1 -0
  61. package/fixtures/real-papers.test.ts +17 -6
  62. package/package.json +3 -1
  63. package/presets/aaai-2027.jsonc +126 -0
  64. package/presets/aaai-2027.md +127 -0
  65. package/presets/aaai-press.jsonc +167 -0
  66. package/presets/aaai-press.md +126 -0
  67. package/presets/aidc-2026.jsonc +11 -11
  68. package/presets/icml-2027.jsonc +111 -0
  69. package/presets/icml-2027.md +130 -0
  70. package/presets/icml-style.jsonc +125 -0
  71. package/presets/icml-style.md +77 -0
  72. package/presets/neurips-2026.jsonc +123 -0
  73. package/presets/neurips-2026.md +137 -0
  74. package/presets/neurips-style.jsonc +113 -0
  75. package/presets/neurips-style.md +85 -0
  76. package/presets/venue-profile.schema.json +6 -0
  77. package/skills/build-label-page/scripts/label-page-browser.test.ts +275 -114
  78. package/src/adapters/latex/document-class.ts +292 -20
  79. package/src/adapters/latex/index.test.ts +310 -0
  80. package/src/adapters/latex/index.ts +12 -3
  81. package/src/adapters/latex/parse.ts +5 -0
  82. package/src/adapters/latex/prose.ts +27 -4
  83. package/src/cli.test.ts +6 -1
  84. package/src/domain/body-pages.test.ts +22 -6
  85. package/src/domain/body-pages.ts +4 -2
  86. package/src/domain/tex-document.ts +64 -5
  87. package/src/folder-venue-rule.test.ts +51 -0
  88. package/src/new-paper.test.ts +2 -2
  89. package/src/paper-settings-commands.test.ts +1 -1
  90. package/src/ports/latex.ts +14 -0
  91. package/src/preset-card-rule.test.ts +44 -27
  92. package/src/presets.test.ts +177 -1
  93. package/src/presets.ts +27 -0
  94. package/src/register-bands.test.ts +2 -2
  95. package/src/rule-cases.test.ts +52 -0
  96. package/src/tex-requirements.harness.ts +17 -3
  97. package/src/tex-requirements.ts +13 -2
  98. package/src/tex-venue-rules.test.ts +1020 -0
  99. package/src/tex-venue-rules.ts +248 -38
  100. package/src/venue-rules.test.ts +369 -2
@@ -25,7 +25,10 @@ import {
25
25
  optional,
26
26
  outlineOf,
27
27
  parseLatex,
28
+ packagesOf,
29
+ packagesUnseen,
28
30
  parseTemplate,
31
+ parseTemplateStyle,
29
32
  placeOf,
30
33
  renderedRuns,
31
34
  replaceDocumentClass,
@@ -41,6 +44,8 @@ describe("documentClassOf — the class line's three states", () => {
41
44
  kind: "class",
42
45
  cls: "IEEEtran",
43
46
  options: ["conference", "compsoc"],
47
+ unread: [],
48
+ passed: [],
44
49
  place: {
45
50
  kind: "at",
46
51
  span: { start: 4, end: src.indexOf("}") + 1 },
@@ -77,6 +82,81 @@ describe("documentClassOf — the class line's three states", () => {
77
82
  });
78
83
  });
79
84
 
85
+ describe("documentClassOf — options passed before the line, and what a macro builds", () => {
86
+ it("🔴 `\\PassOptionsToClass` before the line, for its class: each option as written, with its place", () => {
87
+ const src =
88
+ "\\PassOptionsToClass{compsoc}{IEEEtran}\n\\PassOptionsToClass{x}{article}\n\\documentclass[conference]{IEEEtran}\n\\PassOptionsToClass{late}{IEEEtran}";
89
+ expect(documentClassOf(parseLatex(src))).toEqual({
90
+ kind: "class",
91
+ cls: "IEEEtran",
92
+ options: ["conference"],
93
+ unread: [],
94
+ passed: [
95
+ {
96
+ options: ["compsoc"],
97
+ unread: [],
98
+ place: { kind: "at", span: { start: 0, end: 38 } },
99
+ },
100
+ ],
101
+ place: {
102
+ kind: "at",
103
+ span: {
104
+ start: src.indexOf("\\documentclass"),
105
+ end: src.indexOf("}\n\\PassOptionsToClass{late}") + 1,
106
+ },
107
+ },
108
+ });
109
+ });
110
+
111
+ it("an option built by a macro is unread, in the line and in a passed list; braces do not hide one", () => {
112
+ const src =
113
+ "\\PassOptionsToClass{\\more}{IEEEtran}\\documentclass[\\opts, a, b={\\c}]{IEEEtran}";
114
+ const line = documentClassOf(parseLatex(src));
115
+ expect(
116
+ line.kind === "class" && [
117
+ line.options,
118
+ line.unread,
119
+ line.passed.map((p) => p.unread),
120
+ ],
121
+ ).toEqual([
122
+ ["\\opts", "a", "b={\\c}"],
123
+ ["\\opts", "b={\\c}"],
124
+ [["\\more"]],
125
+ ]);
126
+ });
127
+ });
128
+
129
+ describe("documentClassOf — a line with a part missing, a class from a macro, a class out of reach", () => {
130
+ it("a \\PassOptionsToClass missing an argument passes nothing; a \\documentclass with no name is empty", () => {
131
+ const line = (src: string) => documentClassOf(parseLatex(src));
132
+ // At the end of the file: before a line, the parser would take the line as its argument.
133
+ for (const pass of ["\\PassOptionsToClass", "\\PassOptionsToClass{a}"]) {
134
+ const l = line(`\\documentclass{IEEEtran}\n${pass}`);
135
+ expect(l.kind === "class" && l.passed).toEqual([]);
136
+ }
137
+ expect(line("\\documentclass[a]").kind).toBe("empty");
138
+ });
139
+
140
+ it("🔴 a class name built by a macro is unread, not empty", () => {
141
+ expect(documentClassOf(parseLatex("\\documentclass[a]{\\cls}")).kind).toBe(
142
+ "unread",
143
+ );
144
+ });
145
+
146
+ it("🔴 unseen: no class line at the top, and one inside another macro, or an \\input in the preamble", () => {
147
+ const kind = (src: string) => documentClassOf(parseLatex(src)).kind;
148
+ expect(kind("{\\documentclass{article}}")).toBe("unseen");
149
+ expect(kind("\\input{preamble}\n\\begin{document}\\end{document}")).toBe(
150
+ "unseen",
151
+ );
152
+ expect(kind("\\input{preamble}")).toBe("unseen");
153
+ // The other half: an \input in the body does not stand where a class line goes.
154
+ expect(kind("\\begin{document}\\input{intro}\\end{document}")).toBe(
155
+ "missing",
156
+ );
157
+ });
158
+ });
159
+
80
160
  describe("placeOf / macroPlace — a node the parser gave no position is unplaced, never offset 0", () => {
81
161
  const at = (start: number, end: number) => ({
82
162
  start: { offset: start, line: 1, column: start + 1 },
@@ -152,6 +232,173 @@ describe("parseTemplate — a preset's template", () => {
152
232
  });
153
233
  });
154
234
 
235
+ describe("parseTemplateStyle — a preset's template_style", () => {
236
+ it.each<[string, { name: string; options: string[] } | null]>([
237
+ ["\\usepackage{neurips_2026}", { name: "neurips_2026", options: [] }],
238
+ [
239
+ "% c\n\\usepackage[ main , final ]{neurips_2026}\n",
240
+ { name: "neurips_2026", options: ["main", "final"] },
241
+ ],
242
+ ["\\RequirePackage{icml2027}", { name: "icml2027", options: [] }],
243
+ ["\\usepackage{a,b}", null],
244
+ ["\\usepackage{}", null],
245
+ ["\\usepackage{a} \\usepackage{b}", null],
246
+ ["\\documentclass{article}", null],
247
+ ["neurips_2026", null],
248
+ ["", null],
249
+ ])("%j → %j", (text, want) => {
250
+ expect(parseTemplateStyle(text)).toEqual(want);
251
+ });
252
+ });
253
+
254
+ describe("packagesOf — options passed to a package before it is loaded (`\\PassOptionsToPackage`)", () => {
255
+ const optionsOf = (src: string) =>
256
+ packagesOf(parseLatex(src)).map((p) => [p.name, p.options]);
257
+
258
+ it("🔴 options passed before the load are in effect, to each package of a comma list", () => {
259
+ expect(
260
+ optionsOf(
261
+ "\\documentclass{article}\n\\PassOptionsToPackage{submission, x}{other, aaai2027}\n\\usepackage[y]{aaai2027}\n\\usepackage{other}\n",
262
+ ),
263
+ ).toEqual([
264
+ ["aaai2027", ["submission", "x", "y"]],
265
+ ["other", ["submission", "x"]],
266
+ ]);
267
+ });
268
+
269
+ it("options passed after the load, or to another package, are not", () => {
270
+ expect(
271
+ optionsOf(
272
+ "\\documentclass{article}\n\\PassOptionsToPackage{a}{other}\n\\usepackage{aaai2027}\n\\PassOptionsToPackage{submission}{aaai2027}\n\\PassOptionsToPackage{b}\n",
273
+ ),
274
+ ).toEqual([["aaai2027", []]]);
275
+ });
276
+ });
277
+
278
+ describe("packagesOf — only what TeX reads: nothing after \\end{document}", () => {
279
+ const doc =
280
+ "\\documentclass{article}\n\\usepackage{a}\n\\begin{document}\nx\n\\end{document}\n";
281
+
282
+ it("🔴 a load and a \\PassOptionsToPackage parked after it are not read", () => {
283
+ const src = `${doc}\\PassOptionsToPackage{o}{a}\n\\usepackage[p]{b}\n`;
284
+ expect(packagesOf(parseLatex(src)).map((p) => [p.name, p.options])).toEqual(
285
+ [["a", []]],
286
+ );
287
+ });
288
+
289
+ it("🔴 a load inside a macro after it hides nothing; one in the preamble's macro still does", () => {
290
+ const after = "\\newcommand{\\x}{\\usepackage{c}}\n";
291
+ expect(packagesUnseen(parseLatex(`${doc}${after}`))).toBe(false);
292
+ expect(packagesUnseen(parseLatex(`${after}${doc}`))).toBe(true);
293
+ });
294
+ });
295
+
296
+ describe("packagesOf — the options LaTeX hands a package: global, passed, its own (latex.ltx)", () => {
297
+ const loads = (src: string) =>
298
+ packagesOf(parseLatex(src)).map((p) => [p.name, p.options, p.unread]);
299
+
300
+ it("🔴 the class line's options are global: every package after it gets them, before its own", () => {
301
+ expect(
302
+ loads(
303
+ "\\documentclass[letterpaper, submission]{article}\n\\PassOptionsToPackage{x}{aaai2027}\n\\usepackage[y]{aaai2027}\n",
304
+ ),
305
+ ).toEqual([["aaai2027", ["letterpaper", "submission", "x", "y"], []]]);
306
+ });
307
+
308
+ it("options passed to the class with \\PassOptionsToClass are the class's alone, not global", () => {
309
+ expect(
310
+ loads(
311
+ "\\PassOptionsToClass{submission}{article}\n\\documentclass[letterpaper]{article}\n\\usepackage{aaai2027}\n",
312
+ ),
313
+ ).toEqual([["aaai2027", ["letterpaper"], []]]);
314
+ });
315
+
316
+ it("🔴 \\RequirePackageWithOptions loads the package with the global options, and what was passed to it is replaced", () => {
317
+ expect(
318
+ loads(
319
+ "\\documentclass[submission]{article}\n\\PassOptionsToPackage{x}{aaai2027}\n\\RequirePackageWithOptions{aaai2027}\n",
320
+ ),
321
+ ).toEqual([["aaai2027", ["submission"], []]]);
322
+ });
323
+
324
+ it("🔴 an option built by a macro, on the class line, passed, or on the load, is unread", () => {
325
+ expect(
326
+ loads(
327
+ "\\documentclass[\\cls]{article}\n\\PassOptionsToPackage{\\pass}{aaai2027}\n\\usepackage[\\own, y]{aaai2027}\n",
328
+ ),
329
+ ).toEqual([
330
+ [
331
+ "aaai2027",
332
+ ["\\cls", "\\pass", "\\own", "y"],
333
+ ["\\cls", "\\pass", "\\own"],
334
+ ],
335
+ ]);
336
+ });
337
+ });
338
+
339
+ describe("packagesUnseen — a preamble that may load what the reader does not see", () => {
340
+ const unseen = (preamble: string, body = "Text.") =>
341
+ packagesUnseen(
342
+ parseLatex(
343
+ `\\documentclass{article}\n${preamble}\n\\begin{document}\n${body}\n\\end{document}\n`,
344
+ ),
345
+ );
346
+
347
+ it("🔴 an \\input in the preamble, a package line inside a macro, a name a macro builds", () => {
348
+ expect(unseen("\\input{preamble}")).toBe(true);
349
+ expect(unseen("\\newcommand{\\load}{\\usepackage{x}}\n\\load")).toBe(true);
350
+ expect(unseen("\\usepackage{\\style}")).toBe(true);
351
+ });
352
+
353
+ it("🔴 options passed where the reader does not see them: inside a macro, or to a package a macro names", () => {
354
+ expect(
355
+ unseen("\\newcommand{\\opts}{\\PassOptionsToPackage{final}{x}}\n\\opts"),
356
+ ).toBe(true);
357
+ expect(unseen("\\PassOptionsToPackage{final}{\\style}")).toBe(true);
358
+ });
359
+
360
+ it("🔴 a file read through a loader the include reader does not follow, or a line built by \\csname", () => {
361
+ expect(unseen("\\InputIfFileExists{setup.tex}{}{}")).toBe(true);
362
+ expect(unseen("\\import{sections/}{preamble}")).toBe(true);
363
+ expect(unseen("\\csname usepackage\\endcsname{x}")).toBe(true);
364
+ expect(unseen("\\usepackage{x}", "\\import{sections/}{intro}")).toBe(false);
365
+ });
366
+
367
+ it("the whole preamble in view: plain lines and an \\input in the body; a bare \\usepackage hides nothing", () => {
368
+ expect(unseen("\\usepackage[a]{x,y}", "\\input{intro}")).toBe(false);
369
+ expect(packagesUnseen(parseLatex("\\usepackage"))).toBe(false);
370
+ expect(unseen("\\PassOptionsToPackage{\\opt}{x}\n\\usepackage{x}")).toBe(
371
+ false,
372
+ );
373
+ });
374
+ });
375
+
376
+ describe("packagesOf — the packages the preamble loads", () => {
377
+ it("a \\usepackage with no argument loads nothing", () => {
378
+ expect(
379
+ packagesOf(parseLatex("\\documentclass{article}\n\\usepackage\n")),
380
+ ).toEqual([]);
381
+ });
382
+
383
+ it("each package of each line, with the line's options and place; a comment loads nothing", () => {
384
+ const src =
385
+ "\\documentclass{article}\n% \\usepackage{x}\n\\usepackage[a, b]{p,q}\n\\RequirePackage{r}\n";
386
+ expect(
387
+ packagesOf(parseLatex(src)).map((p) => [
388
+ p.name,
389
+ p.options,
390
+ p.place.kind === "at"
391
+ ? src.slice(p.place.span.start, p.place.span.end)
392
+ : "",
393
+ ]),
394
+ ).toEqual([
395
+ ["p", ["a", "b"], "\\usepackage[a, b]{p,q}"],
396
+ ["q", ["a", "b"], "\\usepackage[a, b]{p,q}"],
397
+ ["r", [], "\\RequirePackage{r}"],
398
+ ]);
399
+ });
400
+ });
401
+
155
402
  const replaced = (src: string) => replaceDocumentClass(parseLatex(src), IEEE);
156
403
 
157
404
  describe("replaceDocumentClass — the class `paperlint new` writes", () => {
@@ -189,6 +436,22 @@ describe("replaceDocumentClass — the class `paperlint new` writes", () => {
189
436
  expect(replaced("\\documentclass{}\nx")).toBe("\\documentclass{}\nx");
190
437
  });
191
438
 
439
+ it("🔴 an option passed with \\PassOptionsToClass is not added again; only the one still missing is", () => {
440
+ expect(
441
+ replaced(
442
+ "\\PassOptionsToClass{compsoc}{IEEEtran}\n\\documentclass{IEEEtran}",
443
+ ),
444
+ ).toBe(
445
+ "\\PassOptionsToClass{compsoc}{IEEEtran}\n\\documentclass[conference]{IEEEtran}",
446
+ );
447
+ });
448
+
449
+ it("🔴 a line built by a macro is returned as it is: what it lacks is not known", () => {
450
+ const opts = "\\documentclass[\\opts]{IEEEtran}";
451
+ expect(replaced(opts)).toBe(opts);
452
+ expect(replaced("\\documentclass{\\cls}")).toBe("\\documentclass{\\cls}");
453
+ });
454
+
192
455
  it("the port does the same over a source", () => {
193
456
  expect(
194
457
  latexReader.withDocumentClass("\\documentclass{article}", IEEE),
@@ -511,6 +774,53 @@ describe("bodyProse — passages a sentence cannot cross, with the marks that sa
511
774
  });
512
775
  });
513
776
 
777
+ describe("bodyProse — the space a % comment leaves, which TeX keeps", () => {
778
+ /** The text of the body's one passage, marks and math left out, spaces as TeX leaves them. */
779
+ const typeset = (src: string): string =>
780
+ bodyProse(parseLatex(src))
781
+ .flatMap((p) =>
782
+ p.pieces.map((x) => (x.kind === "text" ? x.segment.text : "")),
783
+ )
784
+ .join("");
785
+
786
+ it("🔴 an own-line comment between two sentences leaves the space the line break made", () => {
787
+ expect(typeset("First four.\n%\nSecond four.")).toBe(
788
+ "First four. Second four.",
789
+ );
790
+ expect(typeset("First four.\n% note\nSecond four.")).toBe(
791
+ "First four. Second four.",
792
+ );
793
+ });
794
+
795
+ it("🔴 a trailing comment leaves the space TeX keeps, with or without a space before the `%`", () => {
796
+ expect(typeset("First four. % note\nSecond four.")).toBe(
797
+ "First four. Second four.",
798
+ );
799
+ expect(typeset("First four.\n% note\nSecond four.")).toBe(
800
+ "First four. Second four.",
801
+ );
802
+ });
803
+
804
+ it("a comment glued to the word before it leaves no space: TeX sets `four.Second`", () => {
805
+ expect(typeset("First four.% note\nSecond four.")).toBe(
806
+ "First four.Second four.",
807
+ );
808
+ expect(typeset("a%\nb")).toBe("ab");
809
+ });
810
+
811
+ it("🔴 a run of comments leaves one space, and only when TeX kept one before the first of them", () => {
812
+ expect(typeset("some%\n% explanation\nthing")).toBe("something");
813
+ expect(typeset("some \n% one\n% two\nthing")).toBe("some thing");
814
+ expect(typeset("some % one\n% two\nthing")).toBe("some thing");
815
+ });
816
+
817
+ it("the text inside a comment is not prose, whichever way the comment stands", () => {
818
+ expect(typeset("A. % hidden words\nB.\n% more hidden\nC.")).toBe(
819
+ "A. B. C.",
820
+ );
821
+ });
822
+ });
823
+
514
824
  describe("bodyProse — run-in headings and list items", () => {
515
825
  /** The text of each passage of `src`'s body, marks and math left out. */
516
826
  const texts = (src: string): readonly string[] =>
@@ -15,16 +15,19 @@
15
15
  * the parser the language already uses.
16
16
  *
17
17
  * ── STATES, NOT NULL ─────────────────────────────────────────────────────────────
18
- * A class line is missing, empty or a class; a node the parser gave no position is `unplaced`, not
19
- * offset 0; a run of text is a non-empty list of contiguous segments, and a range outside it has
20
- * no span (`spanIn` in `src/domain/tex-document.ts`). A tree travels only with its own source
18
+ * A class line is missing, unseen, empty, unread or a class; a node the parser gave no position is
19
+ * `unplaced`, not offset 0; a run of text is a non-empty list of contiguous segments, and a range
20
+ * outside it has no span (`spanIn` in `src/domain/tex-document.ts`). A tree travels only with its own source
21
21
  * (`ParsedTex`, minted by `parseLatex` alone).
22
22
  */
23
23
  import type { LatexReader } from "../../ports/latex.ts";
24
24
  import { abstractSpan, abstractText } from "./abstract.ts";
25
25
  import {
26
26
  documentClassOf,
27
+ packagesOf,
28
+ packagesUnseen,
27
29
  parseTemplate,
30
+ parseTemplateStyle,
28
31
  replaceDocumentClass,
29
32
  } from "./document-class.ts";
30
33
  import { citeKeysOf, macroTextsOf, registeredNumbersOf } from "./facts.ts";
@@ -41,7 +44,10 @@ import { filecontentsOf } from "./filecontents.ts";
41
44
 
42
45
  export {
43
46
  documentClassOf,
47
+ packagesOf,
48
+ packagesUnseen,
44
49
  parseTemplate,
50
+ parseTemplateStyle,
45
51
  replaceDocumentClass,
46
52
  } from "./document-class.ts";
47
53
  export {
@@ -76,6 +82,9 @@ export const latexReader: LatexReader = {
76
82
  includes: (src) => includesOf(parseLatex(src)),
77
83
  documentBody: (src) => documentBodyOf(parseLatex(src)),
78
84
  template: parseTemplate,
85
+ packages: (src) => packagesOf(parseLatex(src)),
86
+ packagesUnseen: (src) => packagesUnseen(parseLatex(src)),
87
+ templateStyle: parseTemplateStyle,
79
88
  withDocumentClass: (src, want) => replaceDocumentClass(parseLatex(src), want),
80
89
  layoutOverrides: (src) => layoutOverridesOf(parseLatex(src)),
81
90
  filecontents: (src, jobname) => filecontentsOf(parseLatex(src), jobname),
@@ -107,6 +107,11 @@ export const KEY_SIGNATURES: Readonly<
107
107
  ...signed(["nobibliography"], "m"),
108
108
  ...signed(["includegraphics"], "s o o m"),
109
109
  ...signed(["usepackage", "RequirePackage", "documentclass"], "o m o"),
110
+ // Options for a class, given before its `\documentclass`: `tex/template` reads them as the line's.
111
+ // The same for a package, before its `\usepackage`.
112
+ ...signed(["PassOptionsToClass", "PassOptionsToPackage"], "m m"),
113
+ // A package given the options of the file that loads it: `\RequirePackageWithOptions{pkg}[date]`.
114
+ ...signed(["RequirePackageWithOptions"], "m o"),
110
115
  ]);
111
116
 
112
117
  /**
@@ -380,10 +380,32 @@ const isBreak = (n: Node): n is NodeOf<"parbreak" | "verbatim"> =>
380
380
  const isSilent = (n: Node): n is NodeOf<"comment" | "verb" | "root"> =>
381
381
  n.type === "comment" || n.type === "verb" || n.type === "root";
382
382
 
383
- function nodeEvents(t: ParsedTex, n: Node): readonly Event[] {
383
+ /** Whether a comment follows a space TeX keeps: written before a trailing `%`, or the line break before an own-line one. */
384
+ const followsSpace = (n: NodeOf<"comment">): boolean =>
385
+ n.leadingWhitespace === true || n.sameline === false;
386
+
387
+ /**
388
+ * What a node that holds no prose typesets: a verbatim span and the root nothing, a comment — which
389
+ * eats the rest of its line, never the space TeX keeps before it — that space. The parser folds the
390
+ * space written before a trailing `%` into the comment as `leadingWhitespace`, and drops the line
391
+ * break before an own-line comment (`sameline` is false). A comment glued to the word before it
392
+ * (`four.% note`) leaves none, and neither does one after another comment: the first ate the line
393
+ * break, so a run of comments leaves at most the one space before it (`some%`, then a line of
394
+ * comment, then `thing` sets `something`). The text inside a comment is never prose.
395
+ */
396
+ const silentEvents = (
397
+ n: NodeOf<"comment" | "verb" | "root">,
398
+ prev: Node | undefined,
399
+ ): readonly Event[] =>
400
+ n.type === "comment" && prev?.type !== "comment" && followsSpace(n)
401
+ ? textAt(n, " ")
402
+ : [];
403
+
404
+ /** A node's events; `prev` is the node before it in the same list, which decides a comment's space. */
405
+ function nodeEvents(t: ParsedTex, n: Node, prev?: Node): readonly Event[] {
384
406
  if (isMath(n)) return math(t, n);
385
407
  if (isBreak(n)) return [BREAK];
386
- if (isSilent(n)) return [];
408
+ if (isSilent(n)) return silentEvents(n, prev);
387
409
  switch (n.type) {
388
410
  case "string":
389
411
  return textAt(n, stringText(n.content));
@@ -549,8 +571,9 @@ function walkList(
549
571
  );
550
572
  return nodes.flatMap((n, i) => {
551
573
  const opening = i === 0 ? opens : after[i - 1] === true;
552
- if (!opening) return nodeEvents(t, n);
553
- return isRunInHeading(t, n) ? [BREAK] : asOpening(n, nodeEvents(t, n));
574
+ const events = nodeEvents(t, n, nodes[i - 1]);
575
+ if (!opening) return events;
576
+ return isRunInHeading(t, n) ? [BREAK] : asOpening(n, events);
554
577
  });
555
578
  }
556
579
 
package/src/cli.test.ts CHANGED
@@ -34,7 +34,11 @@ import { texInputsDir } from "./package-dirs.ts";
34
34
 
35
35
  const root = useTempDir("cli-test-");
36
36
 
37
- /** `run(argv)` from `cwd`, the output as one string per stream. */
37
+ /**
38
+ * `run(argv)` from `cwd`, the output as one string per stream. Its clock stands still, so `lint`'s
39
+ * «linted N file(s) in 0.0 s» is the same however long the run took: under a loaded
40
+ * `npm run test:changed` two lints of one tree printed 0.2 s and 0.0 s.
41
+ */
38
42
  async function cli(
39
43
  argv: string[],
40
44
  cwd: string,
@@ -46,6 +50,7 @@ async function cli(
46
50
  log: (...a: unknown[]) => out.push(a.join(" ")),
47
51
  err: (...a: unknown[]) => err.push(a.join(" ")),
48
52
  cwd,
53
+ now: () => 0,
49
54
  ...deps,
50
55
  });
51
56
  return { code, out: out.join("\n"), err: err.join("\n") };
@@ -16,19 +16,35 @@ describe("isReferencesHeading", () => {
16
16
  "7 References",
17
17
  "VII. REFERENCES",
18
18
  " References ",
19
+ // lineno's line number, which pdf.js reads glued to the end of the line (a NeurIPS submission,
20
+ // measured 2026-11-19 on fixtures/build-e2e/neurips: «References346»).
21
+ "References346",
22
+ "7 References 12",
19
23
  ])("%j is a heading", (line) => {
20
24
  expect(isReferencesHeading(line)).toBe(true);
21
25
  });
22
26
 
23
- it.each(["See the references below", "References to prior work", "Refs", ""])(
24
- "%j is not",
25
- (line) => {
26
- expect(isReferencesHeading(line)).toBe(false);
27
- },
28
- );
27
+ it.each([
28
+ "See the references below",
29
+ "References to prior work",
30
+ "References to prior work 346",
31
+ "Refs",
32
+ "",
33
+ ])("%j is not", (line) => {
34
+ expect(isReferencesHeading(line)).toBe(false);
35
+ });
29
36
  });
30
37
 
31
38
  describe("bodyEnd", () => {
39
+ it("🔴 a line-numbered submission: the heading with its line number still ends the body", () => {
40
+ expect(
41
+ bodyEnd([
42
+ "Intro1\nbody2",
43
+ "end of the body345\nReferences346\n[1] A.347",
44
+ ]),
45
+ ).toEqual({ kind: "found", by: "references", page: 2, bodyPages: 2 });
46
+ });
47
+
32
48
  it("a heading below body text on its page: that page is a body page", () => {
33
49
  expect(
34
50
  bodyEnd([
@@ -65,9 +65,11 @@ export type BodyEnd =
65
65
  /**
66
66
  * A line that is a references heading: `References` or `Bibliography`, in any case (IEEEtran sets
67
67
  * `REFERENCES` in small caps, which pdf.js may split as `R EFERENCES`), optionally numbered
68
- * (`7 References`, `VII. REFERENCES`). The line is compared with every space removed.
68
+ * (`7 References`, `VII. REFERENCES`), and with the line number `lineno` sets in a submission's
69
+ * margin, which pdf.js reads glued to the end of the line (`References346`). The line is compared
70
+ * with every space removed.
69
71
  */
70
- const HEADING = /^(?:(?:\d+|[ivxlcdm]+)\.?)?(?:references|bibliography)$/iu;
72
+ const HEADING = /^(?:(?:\d+|[ivxlcdm]+)\.?)?(?:references|bibliography)\d*$/iu;
71
73
 
72
74
  /** Whether one line of a page's text is the references heading. */
73
75
  export const isReferencesHeading = (line: string): boolean =>
@@ -24,18 +24,56 @@ export interface DocumentClass {
24
24
  readonly options: readonly string[];
25
25
  }
26
26
 
27
- /** One `\documentclass` line: one that names no class, or a class with its options. */
27
+ /**
28
+ * Options given to a class before its line, by `\PassOptionsToClass{options}{class}`: in effect as
29
+ * if the line carried them. Each option as written; `unread` holds the ones built by a macro.
30
+ */
31
+ export interface PassedOptions {
32
+ readonly options: readonly string[];
33
+ readonly unread: readonly string[];
34
+ readonly place: Place;
35
+ }
36
+
37
+ /**
38
+ * One `\documentclass` line: one that names no class; one whose class is built by a macro
39
+ * (`\documentclass{\cls}`), which no macro is expanded to read; or a class with each option as
40
+ * written. Of those options, `unread` holds the ones built by a macro (`[\opts]`): what they carry
41
+ * is not known. `passed` are the options `\PassOptionsToClass` gave this class before the line.
42
+ */
28
43
  export type ClassCandidate =
29
44
  | { readonly kind: "empty"; readonly place: Place }
30
- | ({ readonly kind: "class"; readonly place: Place } & DocumentClass);
45
+ | { readonly kind: "unread"; readonly place: Place }
46
+ | ({
47
+ readonly kind: "class";
48
+ readonly place: Place;
49
+ readonly unread: readonly string[];
50
+ readonly passed: readonly PassedOptions[];
51
+ } & DocumentClass);
52
+
53
+ /** Every option a class line puts in effect: its own, then the ones passed to its class before it. */
54
+ export const optionsInEffect = (
55
+ line: Extract<ClassCandidate, { readonly kind: "class" }>,
56
+ ): DocumentClass => ({
57
+ cls: line.cls,
58
+ options: [...line.options, ...line.passed.flatMap((p) => p.options)],
59
+ });
60
+
61
+ /** Whether every option a class line puts in effect was read: none is built by a macro. */
62
+ export const readWhole = (
63
+ line: Extract<ClassCandidate, { readonly kind: "class" }>,
64
+ ): boolean =>
65
+ line.unread.length === 0 && line.passed.every((p) => p.unread.length === 0);
31
66
 
32
67
  /**
33
- * A paper's `\documentclass`: none, exactly one, or several — a source that picks its class behind
34
- * a TeX switch (`\if\venue1 \documentclass{article} \fi …`). Which branch builds is not
35
- * evaluated, so several lines are candidates, in source order, and none of them is THE class.
68
+ * A paper's `\documentclass`: none; none the reader can see, though one may stand where it does not
69
+ * look (`unseen`: inside another macro's argument, or in a file the preamble `\input`s that was not
70
+ * read); exactly one; or several — a source that picks its class behind a TeX switch
71
+ * (`\if\venue1 \documentclass{article} \fi …`). Which branch builds is not evaluated, so several
72
+ * lines are candidates, in source order, and none of them is THE class.
36
73
  */
37
74
  export type ClassLine =
38
75
  | { readonly kind: "missing" }
76
+ | { readonly kind: "unseen" }
39
77
  | ClassCandidate
40
78
  | {
41
79
  readonly kind: "ambiguous";
@@ -78,6 +116,27 @@ export function venueClass(
78
116
  export const documentClassLine = (d: DocumentClass): string =>
79
117
  `\\documentclass${d.options.length > 0 ? `[${d.options.join(",")}]` : ""}{${d.cls}}`;
80
118
 
119
+ /** A style package as a template names it: the package and the options it requires. */
120
+ export interface StylePackage {
121
+ readonly name: string;
122
+ readonly options: readonly string[];
123
+ }
124
+
125
+ /**
126
+ * One package a `\usepackage`, `\RequirePackage` or `\RequirePackageWithOptions` of the paper
127
+ * loads, with every option LaTeX hands it, as written (whitespace collapsed): the class line's, those
128
+ * passed to it before the load, the load's own. Of those, `unread` holds the ones built by a macro,
129
+ * whose content is not known. A line loading several packages (`\usepackage{a,b}`) gives one each.
130
+ */
131
+ export interface PackageLoad extends StylePackage {
132
+ readonly unread: readonly string[];
133
+ readonly place: Place;
134
+ }
135
+
136
+ /** A style package as a `\usepackage` line, for a message. */
137
+ export const usepackageLine = (s: StylePackage): string =>
138
+ `\\usepackage${s.options.length > 0 ? `[${s.options.join(",")}]` : ""}{${s.name}}`;
139
+
81
140
  /** One `\section` or `\section*`, its title's text with whitespace collapsed. */
82
141
  export interface Heading {
83
142
  readonly title: string;