zcode-app-cli 3.3.5-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 (169) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +642 -0
  3. package/bin/zcode.js +848 -0
  4. package/config.example.json +110 -0
  5. package/package.json +81 -0
  6. package/vendor/.node-bundle-meta.json +6 -0
  7. package/vendor/extraction.json +11 -0
  8. package/vendor/node_modules/@zcode/tui/dist/index.js +161875 -0
  9. package/vendor/node_modules/@zcode/tui/package.json +14 -0
  10. package/vendor/packages/android-emulator-plugin/.mcp.json +19 -0
  11. package/vendor/packages/android-emulator-plugin/.zcode-plugin/plugin.json +63 -0
  12. package/vendor/packages/android-emulator-plugin/README.md +134 -0
  13. package/vendor/packages/android-emulator-plugin/commands/android-dev.md +11 -0
  14. package/vendor/packages/android-emulator-plugin/dist/lib/path.d.ts +4 -0
  15. package/vendor/packages/android-emulator-plugin/dist/lib/path.js +17 -0
  16. package/vendor/packages/android-emulator-plugin/dist/lib/result.d.ts +5 -0
  17. package/vendor/packages/android-emulator-plugin/dist/lib/result.js +22 -0
  18. package/vendor/packages/android-emulator-plugin/dist/lib/run.d.ts +18 -0
  19. package/vendor/packages/android-emulator-plugin/dist/lib/run.js +99 -0
  20. package/vendor/packages/android-emulator-plugin/dist/mcp/server.d.ts +3 -0
  21. package/vendor/packages/android-emulator-plugin/dist/mcp/server.js +47607 -0
  22. package/vendor/packages/android-emulator-plugin/dist/providers/app.d.ts +39 -0
  23. package/vendor/packages/android-emulator-plugin/dist/providers/app.js +50 -0
  24. package/vendor/packages/android-emulator-plugin/dist/providers/avd.d.ts +37 -0
  25. package/vendor/packages/android-emulator-plugin/dist/providers/avd.js +185 -0
  26. package/vendor/packages/android-emulator-plugin/dist/providers/build.d.ts +68 -0
  27. package/vendor/packages/android-emulator-plugin/dist/providers/build.js +131 -0
  28. package/vendor/packages/android-emulator-plugin/dist/providers/config.d.ts +7 -0
  29. package/vendor/packages/android-emulator-plugin/dist/providers/config.js +29 -0
  30. package/vendor/packages/android-emulator-plugin/dist/providers/device.d.ts +20 -0
  31. package/vendor/packages/android-emulator-plugin/dist/providers/device.js +91 -0
  32. package/vendor/packages/android-emulator-plugin/dist/providers/logs.d.ts +15 -0
  33. package/vendor/packages/android-emulator-plugin/dist/providers/logs.js +31 -0
  34. package/vendor/packages/android-emulator-plugin/dist/providers/preflight.d.ts +15 -0
  35. package/vendor/packages/android-emulator-plugin/dist/providers/preflight.js +123 -0
  36. package/vendor/packages/android-emulator-plugin/dist/providers/project-template.d.ts +13 -0
  37. package/vendor/packages/android-emulator-plugin/dist/providers/project-template.js +211 -0
  38. package/vendor/packages/android-emulator-plugin/dist/providers/project.d.ts +33 -0
  39. package/vendor/packages/android-emulator-plugin/dist/providers/project.js +195 -0
  40. package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.d.ts +14 -0
  41. package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.js +73 -0
  42. package/vendor/packages/android-emulator-plugin/dist/providers/sdk.d.ts +14 -0
  43. package/vendor/packages/android-emulator-plugin/dist/providers/sdk.js +185 -0
  44. package/vendor/packages/android-emulator-plugin/dist/providers/ui.d.ts +92 -0
  45. package/vendor/packages/android-emulator-plugin/dist/providers/ui.js +146 -0
  46. package/vendor/packages/android-emulator-plugin/hooks/hooks.json +3 -0
  47. package/vendor/packages/android-emulator-plugin/package.json +35 -0
  48. package/vendor/packages/android-emulator-plugin/skills/android-dev/INSTALL_ENVIRONMENT.md +357 -0
  49. package/vendor/packages/android-emulator-plugin/skills/android-dev/SKILL.md +73 -0
  50. package/vendor/packages/android-emulator-plugin/templates/compose-app/README.md +5 -0
  51. package/vendor/packages/document-skills-plugin/.zcode-plugin/plugin.json +8 -0
  52. package/vendor/packages/document-skills-plugin/package.json +8 -0
  53. package/vendor/packages/document-skills-plugin/skills/docx/LICENSE.txt +13 -0
  54. package/vendor/packages/document-skills-plugin/skills/docx/SKILL.md +201 -0
  55. package/vendor/packages/document-skills-plugin/skills/docx/references/chart-templates.md +386 -0
  56. package/vendor/packages/document-skills-plugin/skills/docx/references/common-rules.md +419 -0
  57. package/vendor/packages/document-skills-plugin/skills/docx/references/decorations.md +537 -0
  58. package/vendor/packages/document-skills-plugin/skills/docx/references/design-system.md +1797 -0
  59. package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-advanced.md +257 -0
  60. package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-core.md +332 -0
  61. package/vendor/packages/document-skills-plugin/skills/docx/references/faq.md +323 -0
  62. package/vendor/packages/document-skills-plugin/skills/docx/references/math-formulas.md +276 -0
  63. package/vendor/packages/document-skills-plugin/skills/docx/references/ooxml.md +222 -0
  64. package/vendor/packages/document-skills-plugin/skills/docx/references/toc.md +264 -0
  65. package/vendor/packages/document-skills-plugin/skills/docx/routes/comment.md +88 -0
  66. package/vendor/packages/document-skills-plugin/skills/docx/routes/create.md +207 -0
  67. package/vendor/packages/document-skills-plugin/skills/docx/routes/edit.md +115 -0
  68. package/vendor/packages/document-skills-plugin/skills/docx/routes/format.md +120 -0
  69. package/vendor/packages/document-skills-plugin/skills/docx/routes/read.md +114 -0
  70. package/vendor/packages/document-skills-plugin/skills/docx/scenes/academic.md +783 -0
  71. package/vendor/packages/document-skills-plugin/skills/docx/scenes/contract.md +463 -0
  72. package/vendor/packages/document-skills-plugin/skills/docx/scenes/copywriting.md +139 -0
  73. package/vendor/packages/document-skills-plugin/skills/docx/scenes/exam.md +698 -0
  74. package/vendor/packages/document-skills-plugin/skills/docx/scenes/official-doc.md +411 -0
  75. package/vendor/packages/document-skills-plugin/skills/docx/scenes/report.md +340 -0
  76. package/vendor/packages/document-skills-plugin/skills/docx/scenes/resume.md +534 -0
  77. package/vendor/packages/document-skills-plugin/skills/docx/scripts/__init__.py +1 -0
  78. package/vendor/packages/document-skills-plugin/skills/docx/scripts/add_toc_placeholders.py +749 -0
  79. package/vendor/packages/document-skills-plugin/skills/docx/scripts/document.py +1333 -0
  80. package/vendor/packages/document-skills-plugin/skills/docx/scripts/postcheck.py +807 -0
  81. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/comments.xml +3 -0
  82. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  83. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  84. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsIds.xml +3 -0
  85. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/people.xml +3 -0
  86. package/vendor/packages/document-skills-plugin/skills/docx/scripts/utilities.py +374 -0
  87. package/vendor/packages/document-skills-plugin/skills/docx/setup.sh +177 -0
  88. package/vendor/packages/document-skills-plugin/skills/pdf/LICENSE.txt +13 -0
  89. package/vendor/packages/document-skills-plugin/skills/pdf/SKILL.md +919 -0
  90. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/academic.md +1058 -0
  91. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/creative.md +770 -0
  92. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/poster.md +702 -0
  93. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process-advanced.md +284 -0
  94. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process.md +319 -0
  95. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/report.md +1659 -0
  96. package/vendor/packages/document-skills-plugin/skills/pdf/configs/components.md +153 -0
  97. package/vendor/packages/document-skills-plugin/skills/pdf/configs/fonts.md +93 -0
  98. package/vendor/packages/document-skills-plugin/skills/pdf/configs/visual_framework.md +263 -0
  99. package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-academic.tex +130 -0
  100. package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-altacv.tex +190 -0
  101. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/cover_validate.js +367 -0
  102. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/design_engine.py +2816 -0
  103. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2pdf-next.js +754 -0
  104. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2poster.js +256 -0
  105. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf.py +2959 -0
  106. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf_qa.py +901 -0
  107. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/poster_validate.py +1337 -0
  108. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/setup.sh +269 -0
  109. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/toc_validate.py +2075 -0
  110. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/charts.md +320 -0
  111. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover-backgrounds.md +384 -0
  112. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover.md +1442 -0
  113. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/fill-engine.md +527 -0
  114. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/geometry.md +142 -0
  115. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/overflow.md +630 -0
  116. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/pagination.md +367 -0
  117. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/palette.md +217 -0
  118. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/typography.md +20 -0
  119. package/vendor/packages/ios-simulator-plugin/.mcp.json +15 -0
  120. package/vendor/packages/ios-simulator-plugin/.zcode-plugin/plugin.json +34 -0
  121. package/vendor/packages/ios-simulator-plugin/README.md +111 -0
  122. package/vendor/packages/ios-simulator-plugin/commands/ios-dev.md +11 -0
  123. package/vendor/packages/ios-simulator-plugin/dist/lib/path.d.ts +4 -0
  124. package/vendor/packages/ios-simulator-plugin/dist/lib/path.js +18 -0
  125. package/vendor/packages/ios-simulator-plugin/dist/lib/result.d.ts +5 -0
  126. package/vendor/packages/ios-simulator-plugin/dist/lib/result.js +20 -0
  127. package/vendor/packages/ios-simulator-plugin/dist/lib/run.d.ts +17 -0
  128. package/vendor/packages/ios-simulator-plugin/dist/lib/run.js +83 -0
  129. package/vendor/packages/ios-simulator-plugin/dist/mcp/server.d.ts +3 -0
  130. package/vendor/packages/ios-simulator-plugin/dist/mcp/server.js +46833 -0
  131. package/vendor/packages/ios-simulator-plugin/dist/providers/build.d.ts +112 -0
  132. package/vendor/packages/ios-simulator-plugin/dist/providers/build.js +99 -0
  133. package/vendor/packages/ios-simulator-plugin/dist/providers/logs.d.ts +21 -0
  134. package/vendor/packages/ios-simulator-plugin/dist/providers/logs.js +26 -0
  135. package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.d.ts +12 -0
  136. package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.js +62 -0
  137. package/vendor/packages/ios-simulator-plugin/dist/providers/project.d.ts +35 -0
  138. package/vendor/packages/ios-simulator-plugin/dist/providers/project.js +288 -0
  139. package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.d.ts +22 -0
  140. package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.js +30 -0
  141. package/vendor/packages/ios-simulator-plugin/dist/providers/sim.d.ts +60 -0
  142. package/vendor/packages/ios-simulator-plugin/dist/providers/sim.js +116 -0
  143. package/vendor/packages/ios-simulator-plugin/dist/providers/ui.d.ts +57 -0
  144. package/vendor/packages/ios-simulator-plugin/dist/providers/ui.js +67 -0
  145. package/vendor/packages/ios-simulator-plugin/hooks/hooks.json +3 -0
  146. package/vendor/packages/ios-simulator-plugin/package.json +35 -0
  147. package/vendor/packages/ios-simulator-plugin/skills/ios-dev/SKILL.md +45 -0
  148. package/vendor/packages/ios-simulator-plugin/templates/swiftui-app/README.md +5 -0
  149. package/vendor/packages/restore-legacy-sessions-plugin/.zcode-plugin/plugin.json +9 -0
  150. package/vendor/packages/restore-legacy-sessions-plugin/README.md +35 -0
  151. package/vendor/packages/restore-legacy-sessions-plugin/commands/restore-legacy-sessions.md +11 -0
  152. package/vendor/packages/restore-legacy-sessions-plugin/package.json +8 -0
  153. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/SKILL.md +92 -0
  154. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/restore-conversation.mjs +648 -0
  155. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/scan-legacy-sessions.mjs +422 -0
  156. package/vendor/packages/skill-creator-plugin/.zcode-plugin/plugin.json +8 -0
  157. package/vendor/packages/skill-creator-plugin/package.json +8 -0
  158. package/vendor/packages/skill-creator-plugin/skills/skill-creator/SKILL.md +159 -0
  159. package/vendor/packages/zcode-guide-plugin/.zcode-plugin/plugin.json +8 -0
  160. package/vendor/packages/zcode-guide-plugin/README.md +22 -0
  161. package/vendor/packages/zcode-guide-plugin/package.json +8 -0
  162. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-commands/SKILL.md +66 -0
  163. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-hooks/SKILL.md +66 -0
  164. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-mcp/SKILL.md +97 -0
  165. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-plugins/SKILL.md +59 -0
  166. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-skills/SKILL.md +61 -0
  167. package/vendor/packages/zcode-guide-plugin/skills/zcode-configuration-guide/SKILL.md +99 -0
  168. package/vendor/zcode.cjs +2926 -0
  169. package/zcode-runtime.lock.json +8 -0
@@ -0,0 +1,1058 @@
1
+ # Brief: Academic Production
2
+
3
+ Scholarly documents via LaTeX/Tectonic: academic papers, theses, dissertations, mathematical manuscripts, IEEE/ACM submissions, academic CVs.
4
+
5
+ ```
6
+ Academic request
7
+ โ”œโ”€ Paper / thesis / journal โ†’ ยงStandard Paper Workflow
8
+ โ”‚ Embed as needed during Phase 3:
9
+ โ”‚ โ”œโ”€ Heavy math (>3 equations) โ†’ use ยงScenario A preamble + environments
10
+ โ”‚ โ”œโ”€ Vector diagrams โ†’ ยงScenario B (simpleโ†’TikZ, complexโ†’Playwright+CSS)
11
+ โ”‚ โ””โ”€ Algorithm pseudocode โ†’ use ยงScenario C template
12
+ โ”‚
13
+ โ””โ”€ Standalone diagram for other brief โ†’ ยงScenario B Path B (Playwright+CSS โ†’ PNG)
14
+ โ”‚
15
+ โ””โ”€ Resume / CV
16
+ โ”œโ”€ Creative / tech / startup โ†’ ยงTemplate A (AltaCV dual-column)
17
+ โ””โ”€ Academic position / PhD โ†’ ยงTemplate B (Academic CV)
18
+ ```
19
+
20
+ **No typesetting assets needed** - LaTeX templates handle their own design system. The `palette.md` color system does not apply to LaTeX documents.
21
+
22
+ ---
23
+
24
+ ## ยงStandard Paper Workflow
25
+
26
+ Six phases. Rules and guardrails are embedded in each phase where they apply.
27
+
28
+ ### Phase 1 - BRIEF
29
+
30
+ Confirm with the user:
31
+ - Document type (journal article, thesis chapter, conference paper, technical report)
32
+ - Template requirement (IEEE, ACM, custom class, or plain `article`)
33
+ - Bibliography format (natbib superscript, numeric brackets, biblatex)
34
+ - Expected length โ†’ if >5 pages or 3+ complex elements (wide tables, block equations, TikZ), split into `\input{}` modules (~500 lines each)
35
+
36
+ **Recognising the document's personality:**
37
+
38
+ | Personality | Examples | Key concern |
39
+ |-------------|----------|-------------|
40
+ | Scholarly | Journal articles, conference proceedings | Academic conventions, bibliography accuracy |
41
+ | Utilitarian | Technical reports, manuals, specs | Information density + scannability |
42
+ | Persuasive | Proposals, pitch documents | Professional polish + 1-2 visual high-points |
43
+ | Expressive | Portfolios, brand guidebooks | Bold typographic choices |
44
+
45
+ ### Phase 2 - SETUP
46
+
47
+ **Title Page (Cover) Rules:**
48
+ - **Academic route covers are generated via HTML/Playwright**, using Templates 08-11 from `typesetting/cover.md`. Templates 08-10 replicate LaTeX title page aesthetics (dark backgrounds, serif titles, symmetric layouts) in HTML/CSS. **Template 11 (Institutional)** is for thesis proposals, dissertations, and formal institutional submissions (white bg + black border frame).
49
+ - **Pipeline:** Generate body PDF via Tectonic (no title page in `.tex`) โ†’ Generate cover HTML (Template 08/09/10/11) โ†’ Playwright `page.pdf()` โ†’ Merge cover as page 0 via pypdf
50
+ - **Template selection:** For thesis proposals (ๅผ€้ข˜ๆŠฅๅ‘Š), dissertations (ๆฏ•ไธš่ฎบๆ–‡), and institutional submissions โ†’ **default to Template 11**. For research papers, preprints, journal submissions โ†’ Templates 08-10.
51
+ - **NEVER use `\maketitle`** - it produces ugly default output with cramped spacing
52
+ - **NEVER use `\begin{titlepage}...\end{titlepage}`** - the cover is generated separately via HTML/Playwright
53
+ - **NEVER use LaTeX TikZ overlay for full-page covers** - TikZ `current page` coordinates are unreliable with `margin=0pt`, causing backgrounds to not fill the page (right/bottom white edges). HTML/CSS full-bleed is pixel-exact.
54
+ - Title page is OPTIONAL - skip it for short documents (โ‰ค 2 pages), letters, memos, or when content scanning is priority
55
+ - **`\tableofcontents` must be the FIRST page** of the body PDF (after merge, it becomes page 2)
56
+ - If no TOC, content starts on page 1 of the body PDF
57
+
58
+ **Cover Generation Pipeline (Academic route):**
59
+ ```
60
+ 1. Write .tex WITHOUT any title page
61
+ 2. Run poster_validate.py check-tex on .tex file - fix table overflow / image width ERRORs
62
+ 3. Compile with tectonic โ†’ body.pdf
63
+ 4. Write cover HTML using Template 08/09/10/11 from typesetting/cover.md (Template 11 for thesis proposals/dissertations)
64
+ 5. Run poster_validate.py check-html on cover HTML - fix any ERRORs
65
+ 6. Run cover_validate.js on cover HTML - fix any text-line overlaps
66
+ 7. Render cover HTML โ†’ PDF via Playwright (`html2poster.js`) โ€” **NOT `html2pdf-next.js`** (which converts absoluteโ†’static and destroys cover layout)
67
+ 8. Merge: insert cover as page 0 of body PDF via pypdf
68
+ ```
69
+
70
+ **Cover HTML โ†’ PDF rendering:**
71
+ ```bash
72
+ # ALWAYS use html2poster.js for cover rendering (NOT html2pdf-next.js)
73
+ # Cover pages use position:absolute layout โ€” html2pdf-next.js pre-render hooks
74
+ # convert absoluteโ†’static and destroy the layout. html2poster.js preserves it.
75
+ node "$PDF_SKILL_DIR/scripts/html2poster.js" cover.html --output cover.pdf --width 794px
76
+ ```
77
+
78
+ Or from Python:
79
+ ```python
80
+ import subprocess, os
81
+
82
+ def render_cover(html_path, pdf_path):
83
+ """
84
+ Render HTML cover to PDF via html2poster.js.
85
+
86
+ โš ๏ธ ALWAYS use html2poster.js for covers (NOT html2pdf-next.js).
87
+ Cover HTML uses position:absolute for layout. html2pdf-next.js pre-render
88
+ hooks convert absoluteโ†’static to prevent multi-page overlap, which
89
+ destroys cover layouts. html2poster.js preserves absolute positioning.
90
+ """
91
+ scripts_dir = os.path.join(PDF_SKILL_DIR, 'scripts') # PDF_SKILL_DIR from SKILL.md ยง Script Path Setup
92
+ subprocess.run([
93
+ 'node', os.path.join(scripts_dir, 'html2poster.js'),
94
+ html_path, '--output', pdf_path,
95
+ '--width', '794px',
96
+ ], check=True)
97
+ ```
98
+
99
+ **Merge cover + body:**
100
+ ```python
101
+ from pypdf import PdfReader, PdfWriter, Transformation
102
+
103
+ A4_W, A4_H = 595.28, 841.89 # A4 in points
104
+
105
+ def normalize_page_to_a4(page):
106
+ """Scale a page to A4 if its dimensions don't match."""
107
+ box = page.mediabox
108
+ w, h = float(box.width), float(box.height)
109
+ if abs(w - A4_W) > 2 or abs(h - A4_H) > 2:
110
+ sx, sy = A4_W / w, A4_H / h
111
+ page.add_transformation(Transformation().scale(sx=sx, sy=sy))
112
+ page.mediabox.lower_left = (0, 0)
113
+ page.mediabox.upper_right = (A4_W, A4_H)
114
+ return page
115
+
116
+ writer = PdfWriter()
117
+ cover_page = normalize_page_to_a4(PdfReader('cover.pdf').pages[0])
118
+ writer.add_page(cover_page)
119
+ for page in PdfReader('body.pdf').pages:
120
+ writer.add_page(page)
121
+ with open('final.pdf', 'wb') as f:
122
+ writer.write(f)
123
+ ```
124
+
125
+ **โ†’ Full cover templates: see ยงPART 4.5 in `typesetting/cover.md` (Templates 08-10).**
126
+
127
+ > **โš ๏ธ Why HTML/Playwright covers?** LaTeX TikZ `remember picture, overlay` with `margin=0pt` frequently fails to fill the page (right/bottom edges show white). HTML/CSS with `@page { margin: 0 }` and full-bleed background is pixel-exact, with zero ambiguity. This also unifies all three routes (Report, Creative, Academic) under one cover system.
128
+
129
+ Write the preamble. Start from this foundation and customise per document:
130
+
131
+ ```latex
132
+ \documentclass{article}
133
+
134
+ \usepackage{graphicx}
135
+ \usepackage{xcolor}
136
+ \usepackage{geometry}
137
+ \usepackage{amsmath} % Load before hyperref
138
+
139
+ % hyperref - ALWAYS last among content packages
140
+ \usepackage[
141
+ colorlinks=true,
142
+ linkcolor=blue,
143
+ citecolor=darkgray,
144
+ urlcolor=blue,
145
+ bookmarks=true,
146
+ bookmarksnumbered=true,
147
+ unicode=true
148
+ ]{hyperref}
149
+
150
+ \geometry{a4paper, top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm}
151
+ % โš ๏ธ left and right MUST be equal - asymmetric margins cause off-center content
152
+
153
+ \usepackage[numbers,super,sort&compress]{natbib}
154
+ \bibliographystyle{unsrtnat}
155
+
156
+ \usepackage{tcolorbox}
157
+ \usepackage{colortbl}
158
+ \usepackage{booktabs}
159
+ \usepackage{enumitem}
160
+ \usepackage{tabularx} % Auto-width columns (X type) - prevents table overflow
161
+ \usepackage{adjustbox} % \adjustbox{max width=\columnwidth} for emergency table fitting
162
+ ```
163
+
164
+ **Guardrails for SETUP:**
165
+ - `hyperref` must load after virtually every other package - option clashes are the #1 preamble bug
166
+ - When using a Scenario template (A/B/C) or Resume template, use that template's own preamble instead
167
+ - `babel` and `polyglossia` are incompatible - load only one
168
+ - CJK: `\usepackage{ctex}` - Tectonic auto-downloads fonts, zero manual setup
169
+ - System fonts via `\setmainfont{}`: probe first with `fc-list :lang=XX`
170
+ - **๐Ÿ”ด Margin symmetry:** `\geometry{left=X, right=X}` - left and right MUST be equal. Asymmetric margins = off-center content = critical bug
171
+ - **๐Ÿ”ด Minimum margins with fancyhdr:** When using `fancyhdr` for headers/footers, `geometry` margins must leave enough room. **Minimum: `top >= 2.0cm`, `bottom >= 1.8cm`**. Also set `\setlength{\headheight}{14pt}` in the preamble. Margins smaller than this cause headers/footers to be pushed outside the page boundary (negative y-coordinates), making them invisible in print.
172
+ - **๐Ÿ”ด Quotation marks (English):** NEVER use straight quotes `"..."`ใ€‚English text must use LaTeX curly quotes: ` ``left quote'' ` for double, `` `single' `` for single. Straight `"` in LaTeX means right double quote only.
173
+ - **๐Ÿ”ด Quotation marks (Chinese โ€” CRITICAL):** Chinese quoted text like "ๅŒ—ๆผ‚" MUST use Unicode smart quotes "โ€ฆ" (U+201C/U+201D) directly in the `.tex` source. **NEVER use ASCII `"` for Chinese quotes** โ€” LaTeX interprets `"` as a right double quote (`"`), so `"ๅŒ—ๆผ‚"` renders as `"ๅŒ—ๆผ‚"` (two right quotes, no left quote). The correct LaTeX source is: `"ๅŒ—ๆผ‚"` (literal Unicode characters). `\usepackage{csquotes}` is a safety net but does NOT fix raw ASCII `"` in Chinese text.
174
+ - **Scope:** This rule applies ONLY to Chinese-language body text. Do NOT replace `"` in English paragraphs (use ` ``...'' ` instead), `verbatim`/`lstlisting`/`minted` environments, `\texttt{}`/`\verb||`/`\url{}`/`\href{}{}` arguments, or BibTeX `.bib` field values.
175
+ - **๐Ÿ”ด Title page isolation:** Cover is generated via HTML/Playwright and merged as page 0 via pypdf - isolation is inherent in the merge pipeline. `\tableofcontents` should be the first page of the `.tex` body. Verify: does TOC start on the page immediately after the cover in the merged PDF?
176
+ - **๐Ÿ”ด TOC requires a cover page:** Unless the user explicitly requests no cover, if the document has `\tableofcontents`, it MUST have a cover page. Structure: Cover (page 1) โ†’ TOC (page 2) โ†’ Content (page 3+). Do not generate a TOC without a preceding cover page. This rule is consistent with `briefs/report.md`.
177
+
178
+ **When no style is specified**, apply a measured, high-craft system:
179
+ 1. **Contrast** - clear figure-ground separation
180
+ 2. **Hierarchy** - size, weight, hue variation for reading order
181
+ 3. **White space** - ample margins and leading
182
+ 4. **Coherence** - one typeface family, one accent colour, one spacing rhythm
183
+
184
+ Add enrichment proactively when content benefits:
185
+ - Callout boxes, sidebars โ†’ `tcolorbox`
186
+ - Theorem/definition/proof โ†’ `amsthm` + `tcolorbox`
187
+ - Headers/footers โ†’ `fancyhdr`; chapter openers โ†’ `titlesec`
188
+
189
+ ### Phase 3 - BUILD
190
+
191
+ Write LaTeX content: sections, equations, figures, tables, bibliography.
192
+
193
+ **โ†’ Overflow prevention**: See `typesetting/overflow.md` for the LaTeX-specific patterns (tabularx, adjustbox, widowpenalty, etc.). Key rules:
194
+ - Tables: always use `tabularx` or `tabular*` with `\columnwidth` constraint - never plain `tabular` for 5+ columns
195
+ - Images: always `\includegraphics[max width=\columnwidth, max height=0.4\textheight]` or `adjustbox` - the `max height` prevents a single figure from occupying an entire page
196
+ - Orphans/widows: set `\widowpenalty=10000` and `\clubpenalty=10000`
197
+ - Long tables: use `longtable` with `\endhead` for header repetition on every page
198
+
199
+ **Embedding components**: If the document needs heavy math, diagrams, or algorithms, refer to the Scenario sections below and embed their templates/environments into your `.tex` file. Scenarios are not separate tasks - they are building blocks for Phase 3.
200
+
201
+ **Content density guidance (for textbooks, lecture notes, tutorials):**
202
+
203
+ Documents meant for learning should maintain a healthy balance of prose and formal elements. A page full of equations with no explanation reads like a reference manual, not a textbook.
204
+
205
+ Guidelines:
206
+ - Every equation/equation group should be **preceded** by a sentence explaining what it represents and **followed** by a sentence interpreting the result or stating its significance
207
+ - Every figure should have (a) a descriptive `\caption{}` and (b) at least one sentence in the surrounding text referencing it
208
+ - Every theorem/definition should be followed by an intuitive explanation or worked example before proceeding to the next theorem
209
+ - Avoid stacking 3+ formal elements (equations, figures, tables) with zero narrative text between them
210
+ - For worked examples: state the problem, show the solution steps, then summarize the key takeaway
211
+
212
+ **When high density is acceptable**: research papers (especially methods sections where equation groups naturally cluster), formula sheets, reference appendices, and conference papers with tight page limits. In these cases, prioritise completeness over readability padding.
213
+
214
+ **Source hygiene - catch these model-generation slips:**
215
+ - **Prohibited**: emoji glyphs (tofu), markdown `*asterisk*` formatting (compile errors)
216
+ - **Use instead**: `\textbf{bold}`, `\emph{emphasis}`
217
+
218
+ **Table placement - prevent header orphans:**
219
+ - Short tables (โ‰ค15 rows): wrap in `\begin{table}[htbp]` - LaTeX keeps it together
220
+ - Long tables (>15 rows): use `longtable` with repeated header:
221
+ ```latex
222
+ \usepackage{longtable}
223
+ \begin{longtable}{lll}
224
+ \toprule
225
+ Header 1 & Header 2 & Header 3 \\
226
+ \midrule
227
+ \endfirsthead
228
+ \toprule
229
+ Header 1 & Header 2 & Header 3 \\ % repeated on continuation pages
230
+ \midrule
231
+ \endhead
232
+ \bottomrule
233
+ \endfoot
234
+ Row 1 & data & data \\
235
+ Row 2 & data & data \\
236
+ \end{longtable}
237
+ ```
238
+ - **Never** let a table header sit alone at the bottom of a page with no data rows following it
239
+
240
+ **Table width management - prevent column overflow (โš ๏ธ CRITICAL):**
241
+
242
+ Tables overflowing the column width is the most common LaTeX layout bug in dual-column papers. The table looks fine in single-column preview but clips in IEEE/ACM two-column format.
243
+
244
+ **Prevention strategy (in priority order):**
245
+
246
+ 1. **Use `tabular*` or `tabularx` to constrain width** (RECOMMENDED):
247
+ ```latex
248
+ % tabular* - fixed total width, stretches inter-column space
249
+ \begin{table}[htbp]
250
+ \centering
251
+ \caption{Results.}\label{tab:results}
252
+ \begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} l cccc}
253
+ \toprule
254
+ Method & P@10 & R@10 & NDCG@10 & MRR \\
255
+ \midrule
256
+ Ours & \textbf{0.082} & \textbf{0.054} & \textbf{0.043} & \textbf{0.029} \\
257
+ \bottomrule
258
+ \end{tabular*}
259
+ \end{table}
260
+
261
+ % tabularx - fixed total width, X columns auto-stretch
262
+ \usepackage{tabularx}
263
+ \begin{tabularx}{\columnwidth}{l X X X X}
264
+ ...
265
+ \end{tabularx}
266
+ ```
267
+
268
+ 2. **Reduce font size inside table** (common in conference papers):
269
+ ```latex
270
+ \begin{table}[htbp]
271
+ \centering
272
+ \small % or \footnotesize for very wide tables
273
+ \caption{Comparison.}\label{tab:comp}
274
+ \begin{tabular}{lcccccccc}
275
+ ...
276
+ \end{tabular}
277
+ \end{table}
278
+ ```
279
+
280
+ 3. **`\resizebox` as last resort** (scales the entire table to fit):
281
+ ```latex
282
+ \begin{table}[htbp]
283
+ \centering
284
+ \caption{Full results.}\label{tab:full}
285
+ \resizebox{\columnwidth}{!}{%
286
+ \begin{tabular}{lcccccccc}
287
+ \toprule
288
+ ...
289
+ \bottomrule
290
+ \end{tabular}
291
+ }
292
+ \end{table}
293
+ ```
294
+ โš ๏ธ `\resizebox` scales fonts too - verify the smallest text is still readable (โ‰ฅ 6pt effective).
295
+
296
+ 4. **Span both columns** for genuinely wide tables (8+ data columns):
297
+ ```latex
298
+ \begin{table*}[t] % table* spans full width in twocolumn
299
+ \centering
300
+ \caption{Cross-dataset results.}\label{tab:cross}
301
+ \begin{tabular}{lccccccccccc}
302
+ ...
303
+ \end{tabular}
304
+ \end{table*}
305
+ ```
306
+
307
+ **Decision checklist before writing any table:**
308
+ | Data columns | Single-column (`\columnwidth`) | Action |
309
+ |-------------|-------------------------------|--------|
310
+ | โ‰ค 4 | Fits comfortably | Normal `tabular` |
311
+ | 5-6 | Tight fit | `\small` + `tabular*{\columnwidth}` |
312
+ | 7-8 | Won't fit | `\footnotesize` + `tabular*`, or `\resizebox` |
313
+ | โ‰ฅ 9 | Definitely won't fit | Use `table*` (full width), or split into two tables |
314
+
315
+ **Never**: use a plain `tabular` with 8+ columns in a two-column paper without width constraint - it WILL overflow.
316
+
317
+ **โš ๏ธ CRITICAL: `\resizebox{\columnwidth}` NOT `\resizebox{\textwidth}` in two-column layouts!**
318
+ In dual-column documents (`twocolumn`, `sigconf`, etc.), `\textwidth` = **full page width** (both columns), while `\columnwidth` = **single column width**. Using `\resizebox{\textwidth}` inside a `table` (single-column float) scales the table to the full page width, causing it to overflow the column boundary by ~50%. **Always use `\resizebox{\columnwidth}` for single-column floats.** Only use `\resizebox{\textwidth}` inside `table*` (full-width float).
319
+
320
+ ```latex
321
+ % โŒ WRONG in two-column layout
322
+ \begin{table}[t]
323
+ \resizebox{\textwidth}{!}{% <-- \textwidth = full page, table overflows column!
324
+ \begin{tabular}{lcccccccc} ... \end{tabular}}
325
+ \end{table}
326
+
327
+ % โœ… CORRECT for single-column float
328
+ \begin{table}[t]
329
+ \resizebox{\columnwidth}{!}{% <-- \columnwidth = single column width
330
+ \begin{tabular}{lcccccccc} ... \end{tabular}}
331
+ \end{table}
332
+
333
+ % โœ… CORRECT for full-width float
334
+ \begin{table*}[t]
335
+ \resizebox{\textwidth}{!}{% <-- \textwidth OK here because table* spans both columns
336
+ \begin{tabular}{lcccccccc} ... \end{tabular}}
337
+ \end{table*}
338
+ ```
339
+
340
+ ---
341
+
342
+ **Equation overflow prevention (โš ๏ธ CRITICAL for dual-column papers):**
343
+
344
+ Long equations are the **#2 overflow source** after tables in dual-column papers. Column width in ACM `sigconf` is ~241pt; in IEEE `twocolumn` ~252pt. Many standard math expressions exceed this.
345
+
346
+ **Overflow patterns and fixes:**
347
+
348
+ | Pattern | Problem | Fix |
349
+ |---------|---------|-----|
350
+ | Two equations side-by-side with `\quad` | Combined width > column | Split into `align` with one equation per line |
351
+ | Deep fraction nesting (softmax, attention) | Denominator sum too wide | Use `\smash` + separate definition, or `split` |
352
+ | Long subscripts/superscripts with `\text{}` | `\text{collab}`, `\text{social}` are wide | Use short math abbreviations: `c`, `s`, or define `\newcommand` |
353
+ | `equation` with multiple terms separated by `\quad` | Horizontal overflow | Use `aligned` inside `equation`, or `align` |
354
+
355
+ **Rule M1 โ€” Never put two independent equations on one line in dual-column:**
356
+ ```latex
357
+ % โŒ WRONG โ€” two full equations on one line, guaranteed overflow in sigconf
358
+ \begin{equation}
359
+ \mathbf{e}_u^{(l+1)} = \sum_{i} \frac{1}{\sqrt{|N_R(u)|\cdot|N_R(i)|}} \mathbf{e}_i^{(l)}, \quad
360
+ \mathbf{e}_i^{(l+1)} = \sum_{u} \frac{1}{\sqrt{|N_R(i)|\cdot|N_R(u)|}} \mathbf{e}_u^{(l)}
361
+ \end{equation}
362
+
363
+ % โœ… CORRECT โ€” split into aligned or separate equations
364
+ \begin{align}
365
+ \mathbf{e}_u^{(l+1)} &= \sum_{i \in \mathcal{N}_R(u)} \frac{\mathbf{e}_i^{(l)}}{\sqrt{|\mathcal{N}_R(u)| \cdot |\mathcal{N}_R(i)|}}, \label{eq:collab_u} \\
366
+ \mathbf{e}_i^{(l+1)} &= \sum_{u \in \mathcal{N}_R(i)} \frac{\mathbf{e}_u^{(l)}}{\sqrt{|\mathcal{N}_R(i)| \cdot |\mathcal{N}_R(u)|}}. \label{eq:collab_i}
367
+ \end{align}
368
+ ```
369
+
370
+ **Rule M2 โ€” Wide fractions: use `split` or `multline`:**
371
+ ```latex
372
+ % โŒ WRONG โ€” softmax with long denominator
373
+ \begin{equation}
374
+ \alpha_{uv} = \frac{\exp(\text{LeakyReLU}(\mathbf{a}^{\top}[\mathbf{W}\mathbf{e}_u \| \mathbf{W}\mathbf{e}_v]))}{\sum_{k \in \mathcal{N}_S(u)} \exp(\text{LeakyReLU}(\mathbf{a}^{\top}[\mathbf{W}\mathbf{e}_u \| \mathbf{W}\mathbf{e}_k]))}
375
+ \end{equation}
376
+
377
+ % โœ… CORRECT โ€” define numerator/denominator separately
378
+ \begin{equation}
379
+ \alpha_{uv} = \frac{\exp\bigl(f(\mathbf{e}_u, \mathbf{e}_v)\bigr)}{\sum_{k \in \mathcal{N}_S(u)} \exp\bigl(f(\mathbf{e}_u, \mathbf{e}_k)\bigr)},
380
+ \end{equation}
381
+ \text{where } f(\mathbf{e}_u, \mathbf{e}_v) = \text{LeakyReLU}\bigl(\mathbf{a}^{\top} [\mathbf{W}\mathbf{e}_u \| \mathbf{W}\mathbf{e}_v]\bigr).
382
+ ```
383
+
384
+ **Rule M3 โ€” Self-check: if `equation` body > 60 characters (excluding `\label`), it probably overflows dual-column:**
385
+ This is a quick mental check. If the raw LaTeX math string is very long, it almost certainly won't fit in ~241pt. Use `align`, `split`, `multline`, or factor out sub-expressions.
386
+
387
+ **Rule M4 โ€” Contrastive loss / InfoNCE: always use `multline` or `split`:**
388
+ Contrastive losses with `\frac{\exp(...)}{\sum \exp(...)}` inside `\log` are notoriously wide. Always break them across lines:
389
+ ```latex
390
+ \begin{multline}
391
+ \mathcal{L}_{\text{SSL}}^u = -\log \frac{\exp\bigl(\text{sim}(\mathbf{z}_u', \mathbf{z}_u'') / \tau\bigr)}
392
+ {\sum_{v \neq u} \exp\bigl(\text{sim}(\mathbf{z}_u', \mathbf{z}_v'') / \tau\bigr)}.
393
+ \end{multline}
394
+ ```
395
+
396
+ ---
397
+
398
+ **Algorithm overflow prevention (dual-column papers):**
399
+
400
+ Algorithm boxes with long `\KwInput` lines or verbose pseudocode frequently overflow column width.
401
+
402
+ **Rule A1 โ€” Always set `\SetAlFnt{\small}` and limit line width:**
403
+ ```latex
404
+ \SetAlFnt{\small} % Smaller font inside algorithm
405
+ \SetAlCapFnt{\small} % Smaller caption font
406
+ \SetAlCapNameFnt{\small} % Smaller "Algorithm N:" prefix
407
+ ```
408
+
409
+ **Rule A2 โ€” Break long Input/Output lines:**
410
+ ```latex
411
+ % โŒ WRONG โ€” all parameters on one line
412
+ \KwInput{Interaction graph $\mathcal{G}_R$, social graph $\mathcal{G}_S$, embedding dimension $d$, number of GNN layers $L$, learning rate $\eta$, regularization $\lambda$, SSL weight $\gamma$, temperature $\tau$}
413
+
414
+ % โœ… CORRECT โ€” break into multiple lines
415
+ \KwInput{Interaction graph $\mathcal{G}_R$, social graph $\mathcal{G}_S$\\\quad embedding dim $d$, GNN layers $L$, learning rate $\eta$\\\quad regularization $\lambda$, SSL weight $\gamma$, temperature $\tau$}
416
+ ```
417
+
418
+ **Rule A3 โ€” Use `algorithm*` for genuinely wide algorithms:**
419
+ If the algorithm has many columns or very long lines that can't be shortened, use `\begin{algorithm*}` to span both columns.
420
+
421
+ **Rule A4 โ€” Abbreviate variable names in pseudocode:**
422
+ Use compact notation: `emb` not `embedding`, `lr` not `learning\_rate`, `reg` not `regularization`. Define abbreviations in the Input line.
423
+
424
+ ---
425
+
426
+ **Clickable navigation - every reference must be a live link:**
427
+
428
+ Attach `\label{}` right after each numbered element, cite with `\ref{}`:
429
+
430
+ ```latex
431
+ \section{Background}\label{sec:bg}
432
+ \begin{figure}[htbp]
433
+ \includegraphics{...}
434
+ \caption{Overview}\label{fig:overview}
435
+ \end{figure}
436
+ \begin{equation}\label{eq:energy}
437
+ E = mc^2
438
+ \end{equation}
439
+
440
+ % All produce clickable hyperlinks:
441
+ Section~\ref{sec:bg}...
442
+ Figure~\ref{fig:overview}...
443
+ Equation~\eqref{eq:energy}... % \eqref auto-wraps in parentheses
444
+ ```
445
+
446
+ **Label conventions**: `sec:`, `fig:`, `tab:`, `eq:`, `lst:` - use `~` (non-breaking space) before `\ref`.
447
+
448
+ **Bibliography** (three approaches):
449
+
450
+ ```latex
451
+ % Approach 1: natbib superscript (preferred academic)
452
+ \usepackage[numbers,super,sort&compress]{natbib}
453
+ This has been studied\cite{smith2023}. % โ†’ studied^[1]
454
+ \bibliography{refs}
455
+
456
+ % Approach 2: natbib brackets
457
+ \usepackage[numbers]{natbib}
458
+ \cite{smith2023} % [1]
459
+ \citet{smith2023} % Smith (2023)
460
+
461
+ % Approach 3: biblatex
462
+ \usepackage[backend=biber,style=numeric-comp]{biblatex}
463
+ \addbibresource{refs.bib}
464
+ \printbibliography
465
+ ```
466
+
467
+ **PDF metadata** (add before `\end{document}`):
468
+ ```latex
469
+ \hypersetup{
470
+ pdftitle={Document Title},
471
+ pdfauthor={Author Name},
472
+ pdfsubject={Topic},
473
+ pdfkeywords={keyword1, keyword2}
474
+ }
475
+ ```
476
+
477
+ **Table of Contents** (auto-clickable with hyperref):
478
+ ```latex
479
+ \tableofcontents
480
+ \listoffigures % optional
481
+ \listoftables % optional
482
+ ```
483
+
484
+ ### Phase 4 - COMPILE
485
+
486
+ ```bash
487
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.latex main.tex --runs 2
488
+ ```
489
+
490
+ Default: 2 passes (resolves cross-references). Use `--runs 3` when bibliography back-references are needed. Add `--keep-logs` for debugging.
491
+
492
+ **NEVER invoke Tectonic directly** - always use the wrapper. It strips noise, surfaces errors, and reports PDF statistics.
493
+
494
+ ### Phase 5 - PREFLIGHT
495
+
496
+ The wrapper classifies diagnostics into three tiers:
497
+
498
+ | Tier | Impact | Action |
499
+ |------|--------|--------|
500
+ | Errors | Build aborts | Fix before anything else |
501
+ | Layout defects | Overfull/underfull boxes, missing glyphs | Repair prior to delivery |
502
+ | Advisories | Other warnings | Assess individually; fix when feasible |
503
+
504
+ **Never acceptable**: shrugging off warnings with "they don't affect the final PDF."
505
+
506
+ **Navigation troubleshooting:**
507
+
508
+ | Symptom | Fix |
509
+ |---------|-----|
510
+ | `??` in text | Recompile with `--runs 2` |
511
+ | Links not coloured | Add `colorlinks=true` to hyperref |
512
+ | `[?]` beside citations | Check `.bib` path; rebuild |
513
+ | No PDF bookmarks | Set `bookmarks=true` |
514
+
515
+ ### Phase 6 - DELIVER
516
+
517
+ Final PDF. Confirm page count, cross-references resolved, no `??` placeholders.
518
+
519
+ ---
520
+
521
+ ## ยงScenario A: Math-Heavy Technical Documents
522
+
523
+ > Use standalone for a pure-math document, or embed the preamble additions + environments into a ยงStandard Paper Workflow document.
524
+
525
+ When the document has **more than 3 non-trivial equations** (matrices, aligned systems, integrals, summations), use this template instead of plain `article`.
526
+
527
+ **Decision rule**: If you find yourself writing `<super>` tags or KaTeX CDN includes for math, stop and switch here.
528
+
529
+ ```latex
530
+ \documentclass[11pt,a4paper]{article}
531
+ \usepackage{amsmath,amssymb,amsthm}
532
+ \usepackage[margin=2.5cm]{geometry}
533
+ \usepackage{ctex} % CJK support via Tectonic
534
+ \usepackage{booktabs}
535
+ \usepackage{hyperref}
536
+
537
+ \theoremstyle{definition}
538
+ \newtheorem{definition}{Definition}[section]
539
+ \newtheorem{theorem}{Theorem}[section]
540
+ \newtheorem{lemma}[theorem]{Lemma}
541
+
542
+ \title{Document Title}
543
+ \author{Author}
544
+ \date{\today}
545
+
546
+ \begin{document}
547
+
548
+ % โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
549
+ % NO TITLE PAGE IN .tex - Cover is generated separately
550
+ % via HTML/Playwright and merged as page 0.
551
+ % Body PDF starts directly with TOC or content.
552
+ % โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
553
+
554
+ \tableofcontents
555
+ \newpage
556
+
557
+ % Aligned equation group
558
+ \begin{align}
559
+ \nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \\
560
+ \nabla \times \mathbf{B} &= \mu_0 \mathbf{J} + \mu_0\varepsilon_0 \frac{\partial \mathbf{E}}{\partial t}
561
+ \end{align}
562
+
563
+ % Matrix
564
+ \[
565
+ A = \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix}
566
+ \]
567
+
568
+ \end{document}
569
+ ```
570
+
571
+ ---
572
+
573
+ ## ยงScenario B: Diagram Generation for Academic Papers
574
+
575
+ > **Complexity-based routing**: Simple diagrams use TikZ natively (vector, font-consistent). Complex diagrams use Playwright+CSS โ†’ PNG โ†’ `\includegraphics` (models produce broken TikZ for complex branching logic).
576
+
577
+ ### Decision: TikZ or Playwright+CSS?
578
+
579
+ | Criteria | โ†’ TikZ native | โ†’ Playwright+CSS โ†’ PNG |
580
+ |---|---|---|
581
+ | Node count | โ‰ค6 | >6 |
582
+ | Topology | Linear chain, simple tree, layer stack | Branching, multi-path, feedback loops |
583
+ | Annotations | Minimal (labels only) | Side notes, legends, callout boxes |
584
+ | Math in nodes | Yes (LaTeX math rendering matters) | No (plain text labels) |
585
+ | Output | Vector (`tikzpicture` in document) | Raster PNG @2ร— (300dpi, publication-ready) |
586
+
587
+ ### Path A: Simple Diagrams โ†’ TikZ Native
588
+
589
+ For โ‰ค6 node linear/tree diagrams, embed `tikzpicture` directly or use standalone:
590
+
591
+ ```latex
592
+ \documentclass[tikz,border=5pt]{standalone}
593
+ \usetikzlibrary{arrows.meta,positioning,calc,shapes.geometric}
594
+
595
+ \begin{document}
596
+ \begin{tikzpicture}[
597
+ box/.style={draw, rounded corners=2pt, minimum width=2.4cm,
598
+ minimum height=0.7cm, align=center, font=\small\sffamily},
599
+ arr/.style={-{Stealth[length=4pt]}, thick, gray!70}
600
+ ]
601
+ \node[box, fill=blue!8] (a) {Input};
602
+ \node[box, fill=orange!8, right=1.2cm of a] (b) {Process};
603
+ \node[box, fill=green!8, right=1.2cm of b] (c) {Output};
604
+ \draw[arr] (a) -- (b);
605
+ \draw[arr] (b) -- (c);
606
+ \end{tikzpicture}
607
+ \end{document}
608
+ ```
609
+
610
+ **Node text overflow prevention:**
611
+
612
+ When nodes contain multi-word labels (e.g. "CNN Spatial Encoder", "Multi-Head Attention"), text can overflow or overlap adjacent nodes. Prevent this:
613
+
614
+ ```latex
615
+ % Use text width (not minimum width) to enable line wrapping inside nodes
616
+ box/.style={draw, rounded corners=2pt, text width=2.8cm,
617
+ minimum height=0.7cm, align=center, font=\small\sffamily},
618
+
619
+ % For nodes with long labels, use explicit line breaks
620
+ \node[box] {CNN Spatial\\Encoder};
621
+ \node[box] {Multi-Head\\Attention};
622
+ ```
623
+
624
+ Rules:
625
+ - Prefer `text width` over `minimum width` when labels exceed 2 words - it wraps text instead of clipping
626
+ - When 3+ nodes sit side by side, verify total width fits within `\columnwidth` (single-column) or `0.45\textwidth` (dual-column)
627
+ - If labels still overflow, use abbreviations or `\scriptsize` - never let text clip outside node borders
628
+ - Always `\resizebox{\columnwidth}{!}{...}` when embedding in dual-column papers (see TikZ in multi-column section below)
629
+
630
+ **TikZ standalone embedding (simple diagrams only):**
631
+
632
+ ```bash
633
+ # 1. Compile TikZ standalone to PDF
634
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.latex diagram.tex # โ†’ diagram.pdf (tight-cropped)
635
+
636
+ # 2. Embed as vector in LaTeX
637
+ # \begin{figure}[t]
638
+ # \centering
639
+ # \includegraphics[width=\columnwidth]{diagram.pdf} % vector, not PNG
640
+ # \caption{System Architecture}\label{fig:arch}
641
+ # \end{figure}
642
+ ```
643
+
644
+ **๐Ÿšซ FORBIDDEN: Using TikZ standalone for Report or Creative briefs.** Those routes have no LaTeX compiler. See SKILL.md ยง "Diagram Generation Strategy".
645
+
646
+ ### Path B: Complex Diagrams โ†’ Playwright+CSS โ†’ PNG
647
+
648
+ For >6 node diagrams with branching, annotations, or multi-path flows:
649
+
650
+ ```bash
651
+ # 1. LLM generates diagram.html (CSS grid/flexbox nodes + SVG/CSS arrows)
652
+ # 2. Screenshot at 2ร— device scale factor for 300dpi print quality
653
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.blueprint diagram.html --device-scale-factor 2 --output diagram.png
654
+
655
+ # 3. Embed in LaTeX
656
+ # \begin{figure}[t]
657
+ # \centering
658
+ # \includegraphics[width=\columnwidth]{diagram.png}
659
+ # \caption{System Architecture}\label{fig:arch}
660
+ # \end{figure}
661
+ ```
662
+
663
+ **Why not TikZ for complex diagrams?** Models frequently produce broken TikZ code for >6 node graphs with conditional branches, multi-path convergence, and side annotations. The compilation-debug cycle wastes time. Playwright+CSS handles any layout natively, and 2ร— screenshots at A4 width give ~300dpi - indistinguishable from vector at print resolution.
664
+
665
+ ### Complex Diagram Decomposition
666
+
667
+ When a diagram exceeds **12 nodes, 3 subgroups, or fills more than 40% of page height**, decompose into table + simplified overview:
668
+
669
+ ```latex
670
+ % Step 1: Table carries the details
671
+ \begin{table}[htbp]
672
+ \centering
673
+ \caption{System Pipeline - Detailed Phases}\label{tab:pipeline}
674
+ \begin{tabular}{llp{5cm}}
675
+ \toprule
676
+ Phase & Module & Key Tasks \\
677
+ \midrule
678
+ Data Collection & Crawler & Crawl reviews, scrape prices, API calls \\
679
+ Data Processing & ETL Pipeline & Clean, tokenize, label, validate \\
680
+ Model Training & Trainer & Fine-tune LLM, distributed 64-GPU \\
681
+ Evaluation & Benchmark & A/B test, offline metrics, human eval \\
682
+ \bottomrule
683
+ \end{tabular}
684
+ \end{table}
685
+
686
+ % Step 2: Simplified TikZ shows only the flow skeleton
687
+ \begin{figure}[htbp]
688
+ \centering
689
+ \begin{tikzpicture}[
690
+ box/.style={draw, rounded corners=2pt, minimum width=2cm,
691
+ minimum height=0.6cm, align=center, font=\small\sffamily, fill=blue!5},
692
+ arr/.style={-{Stealth[length=4pt]}, thick, gray!60}
693
+ ]
694
+ \node[box] (a) {Collection};
695
+ \node[box, right=0.8cm of a] (b) {Processing};
696
+ \node[box, right=0.8cm of b] (c) {Training};
697
+ \node[box, right=0.8cm of c] (d) {Evaluation};
698
+ \draw[arr] (a)--(b); \draw[arr] (b)--(c); \draw[arr] (c)--(d);
699
+ \end{tikzpicture}
700
+ \caption{Pipeline overview (see Table~\ref{tab:pipeline} for details).}\label{fig:pipeline-overview}
701
+ \end{figure}
702
+ ```
703
+
704
+ **Rule of thumb**: The diagram gives intuition at a glance; the table carries precision.
705
+
706
+ **Common TikZ patterns**:
707
+ - Flowcharts: `positioning` + `arrows.meta` libraries
708
+ - Neural network layers: `fit` library + nested nodes
709
+ - Timelines: single axis with `\draw` segments
710
+ - Tree diagrams: `child` syntax or `forest` package
711
+
712
+ **CRITICAL: TikZ in multi-column documents (IEEE, ACM)**
713
+
714
+ Never place `tikzpicture` directly in multi-column body text - it overflows. Always wrap:
715
+
716
+ ```latex
717
+ % Single-column figure (fits one column)
718
+ \begin{figure}[t]
719
+ \centering
720
+ \resizebox{\columnwidth}{!}{%
721
+ \begin{tikzpicture}[...]
722
+ ...
723
+ \end{tikzpicture}
724
+ }
725
+ \caption{Architecture.}\label{fig:arch}
726
+ \end{figure}
727
+
728
+ % Full-width figure (spans both columns)
729
+ \begin{figure*}[t]
730
+ \centering
731
+ \resizebox{0.85\textwidth}{!}{%
732
+ \begin{tikzpicture}[...]
733
+ ...
734
+ \end{tikzpicture}
735
+ }
736
+ \caption{System pipeline.}\label{fig:pipeline}
737
+ \end{figure*}
738
+ ```
739
+
740
+ Rules: `\resizebox{\columnwidth}{!}` constrains width; `figure*` for tall diagrams; every figure needs `\caption` + `\label`; prefer `[t]` placement in two-column mode.
741
+
742
+ ---
743
+
744
+ ## ยงScenario C: Algorithm Pseudocode
745
+
746
+ > Use standalone for a single algorithm sheet, or embed the `algorithm` environment into a ยงStandard Paper Workflow document.
747
+
748
+ For formal algorithm descriptions (research papers, technical specs):
749
+
750
+ ```latex
751
+ \documentclass[11pt,a4paper]{article}
752
+ \usepackage[margin=2.5cm]{geometry}
753
+ \usepackage[ruled,vlined,linesnumbered]{algorithm2e}
754
+
755
+ \begin{document}
756
+
757
+ \begin{algorithm}[H]
758
+ \SetAlgoLined
759
+ \KwIn{Training set $\mathcal{D} = \{(x_i, y_i)\}_{i=1}^N$, learning rate $\eta$}
760
+ \KwOut{Optimized parameters $\theta^*$}
761
+ Initialize $\theta$ randomly\;
762
+ \For{epoch $= 1$ \KwTo $T$}{
763
+ \ForEach{mini-batch $B \subset \mathcal{D}$}{
764
+ $\mathcal{L} \leftarrow \frac{1}{|B|}\sum_{(x,y)\in B} \ell(f_\theta(x), y)$\;
765
+ $\theta \leftarrow \theta - \eta \nabla_\theta \mathcal{L}$\;
766
+ }
767
+ }
768
+ \Return{$\theta$}\;
769
+ \caption{Stochastic Gradient Descent}
770
+ \end{algorithm}
771
+
772
+ \end{document}
773
+ ```
774
+
775
+ ---
776
+
777
+ ## ยงExam Paper Rules (LaTeX)
778
+
779
+ > **Load this section** when generating exam papers, quizzes, worksheets, or exercises with mathematical content via LaTeX.
780
+
781
+ ### Critical Anti-Pattern: `\parskip` + Loose Numbering = Blank Lines After Question Numbers
782
+
783
+ **This is the #1 visual defect in LaTeX exam papers.** When `\parskip` is set (e.g. `0.5em`) and question numbers are separated from question text by a blank line in the `.tex` source, LaTeX treats them as separate paragraphs โ€” the `\parskip` gap makes it look like an intentional blank line after every number.
784
+
785
+ ```latex
786
+ % โŒ WRONG โ€” blank line between number and text = new paragraph + parskip gap
787
+ \noindent\textbf{3.}
788
+
789
+ ๆŸๅทฅๅŽ‚ๅŽŸ่ฎกๅˆ’็”Ÿไบง1200ไปถไบงๅ“โ€ฆโ€ฆ
790
+
791
+ % โŒ ALSO WRONG โ€” even without blank line, if \parskip is large
792
+ \noindent\textbf{3.} % line break here
793
+ ๆŸๅทฅๅŽ‚ๅŽŸ่ฎกๅˆ’็”Ÿไบง1200ไปถไบงๅ“โ€ฆโ€ฆ % LaTeX treats this as same paragraph, but confusing
794
+
795
+ % โœ… CORRECT โ€” number and text on the SAME LINE, no break
796
+ \noindent\textbf{3.}\;ๆŸๅทฅๅŽ‚ๅŽŸ่ฎกๅˆ’็”Ÿไบง1200ไปถไบงๅ“โ€ฆโ€ฆ
797
+ ```
798
+
799
+ ### Iron Rules
800
+
801
+ **Rule E1 โ€” Question number + text = same paragraph (MANDATORY):**
802
+ The question number (`\textbf{3.}`) and the question text MUST be on the same line in the `.tex` source, joined by `\;` or `\quad`. NEVER put a blank line or even a line break between them.
803
+
804
+ **Rule E2 โ€” `\parskip` must be 0 or minimal for exam papers:**
805
+ ```latex
806
+ % RECOMMENDED for exams: no parskip, control spacing explicitly
807
+ \setlength{\parskip}{0pt} % No automatic paragraph spacing
808
+ \setlength{\parindent}{0pt} % No indentation
809
+ % Use \vspace{} explicitly between questions for precise control
810
+ ```
811
+ If `\parskip` is needed for other reasons, keep it โ‰ค0.3em and be extra careful about blank lines in the source.
812
+
813
+ **Rule E3 โ€” Use `enumitem` for structured numbering (PREFERRED):**
814
+ Instead of manual `\noindent\textbf{1.}\;`, prefer `enumitem` with custom formatting:
815
+ ```latex
816
+ \usepackage{enumitem}
817
+
818
+ % Section-level numbering: ไธ€ใ€ไบŒใ€ไธ‰
819
+ % Question-level: use enumerate with custom label
820
+ \begin{enumerate}[label=\textbf{\arabic*.}, leftmargin=0pt, itemindent=2em,
821
+ labelsep=0.5em, itemsep=0.8em, parsep=0pt]
822
+ \item 2024ๅนดๅทด้ปŽๅฅฅ่ฟไผšๅ…ฑ่ฎพๆœ‰32ไธชๅคง้กนโ€ฆโ€ฆ
823
+ \item ไธญๅ›ฝ็ฉบ้—ด็ซ™โ€œๅคฉๅฎซโ€ๅœจ่ทๅœฐ้ขโ€ฆโ€ฆ
824
+ \end{enumerate}
825
+ ```
826
+ This guarantees number and text are in the same paragraph (LaTeX `\item` handles it internally).
827
+
828
+ **Rule E4 โ€” `tasks` environment for multi-column calculation items:**
829
+ ```latex
830
+ \usepackage{tasks}
831
+ % 4-column oral calculation
832
+ \begin{tasks}[counter-format={(1)}, label-align=left,
833
+ label-offset={0.5em}, label-width={2.5em},
834
+ item-indent=3em, column-sep=2em](4)
835
+ \task $\dfrac{3}{4}\times\dfrac{2}{9}=$ \underline{\hspace{2cm}}
836
+ \task $\dfrac{5}{6}\div\dfrac{1}{3}=$ \underline{\hspace{2cm}}
837
+ \end{tasks}
838
+ ```
839
+
840
+ **Rule E5 โ€” Answer space reservation:**
841
+
842
+ | Question Type | LaTeX Implementation |
843
+ |--------------|---------------------|
844
+ | Fill-in-the-blank | `\underline{\hspace{2cm}}` inline |
845
+ | Short answer | `\vspace{2cm}` after question |
846
+ | Calculation | `\vspace{4cm}` (show-your-work space) |
847
+ | Proof / derivation | `\vspace{5cm}` |
848
+ | Drawing / graphing | TikZ grid or `\vspace{4cm}` |
849
+
850
+ **Rule E6 โ€” Page breaks for exams:**
851
+ - `page-break-after: always` between major sections (ไธ€ใ€ไบŒใ€ไธ‰) is OK
852
+ - NEVER break within a single question (keep question + options + answer space together)
853
+ - Use `\needspace{5cm}` before long questions to prevent orphaning
854
+
855
+ ### Complete Exam Preamble Template
856
+
857
+ ```latex
858
+ \documentclass[12pt,a4paper]{article}
859
+ \usepackage[margin=2cm]{geometry}
860
+ \usepackage{ctex} % CJK support
861
+ \usepackage{amsmath,amssymb} % Math
862
+ \usepackage{enumitem} % Structured lists
863
+ \usepackage{tasks} % Multi-column exercises
864
+ \usepackage{tikz} % Diagrams
865
+ \usepackage{graphicx}
866
+ \usepackage{array,tabularx}
867
+
868
+ \pagestyle{plain}
869
+ \setlength{\parindent}{0pt} % No indent for exam papers
870
+ \setlength{\parskip}{0pt} % โ— ZERO parskip โ€” control spacing via \vspace
871
+
872
+ % Utility commands
873
+ \newcommand{\blank}[1]{\underline{\hspace{#1}}}
874
+ \newcommand{\fn}[2]{\dfrac{#1}{#2}}
875
+
876
+ % Section header: ไธ€ใ€ๅกซ็ฉบ้ข˜๏ผˆๆฏ็ฉบ1ๅˆ†๏ผŒๅ…ฑ่ฎก10ๅˆ†๏ผ‰
877
+ \newcommand{\examsection}[1]{%
878
+ \vspace{0.5cm}
879
+ \noindent{\heiti #1}
880
+ \vspace{0.3cm}
881
+ }
882
+ ```
883
+
884
+ ---
885
+
886
+ ## ยงResume / CV Templates
887
+
888
+ > **Skip this section** unless building a resume or CV.
889
+
890
+ Two templates available as separate files. Load the one you need:
891
+
892
+ | Template | Style | Best for | File |
893
+ |----------|-------|----------|------|
894
+ | **A: AltaCV** | Dual-column, sidebar, skill dots | Creative/tech/startup roles | `references/resume-altacv.tex` |
895
+ | **B: Academic CV** | Single-column, multi-page, publications | PhD apps, academic positions | `references/resume-academic.tex` |
896
+
897
+ **Route selection:**
898
+
899
+ | Scenario | Recommended |
900
+ |----------|-------------|
901
+ | Corporate job / ATS parsing | **Report brief** - ReportLab ATS-friendly template |
902
+ | Creative/tech/startup | **This brief** - Template A |
903
+ | Academic position / PhD | **This brief** - Template B |
904
+ | Chinese-only, simple format | **Report brief** - ReportLab (best CJK support) |
905
+
906
+ **Usage:**
907
+
908
+ 1. Read the template file: `references/resume-altacv.tex` or `references/resume-academic.tex`
909
+ 2. Replace placeholder content with user's information
910
+ 3. Compile: `python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.latex resume.tex --runs 2`
911
+
912
+ **๐Ÿ”ด Resume Text Overlap Prevention:**
913
+
914
+ > AltaCV dual-column resumes are the #1 source of text overlap bugs. The sidebar and main column share vertical space but are positioned independently.
915
+
916
+ - **Column ratio sanity check:** `\columnratio{0.62}` means left column = 62%, right = 38%. If either column overflows, content bleeds into the other. Reduce ratio if left column has too much content.
917
+ - **Section spacing:** Always use `\medskip` or `\smallskip` between items - zero spacing causes lines to overlap
918
+ - **Skill dots:** Each `\cvskill` row has fixed height. If more than 8-10 skills, switch to a compact text list instead of dots
919
+ - **Experience entries:** Long descriptions in `\cvevent` can push content below the page. Use \textbf{max 3-4 bullet points per entry}
920
+ - **Two-page overflow:** If content exceeds 1 page, explicitly add `\newpage` and restart column layout. Do NOT let LaTeX auto-break the `paracol` environment - it misaligns columns on page 2
921
+ - **Compile twice:** Always `--runs 2` to resolve cross-references and stabilize column breaks
922
+
923
+ **๐Ÿ”ด Resume Minimum Font Size:**
924
+ - **Hard floor: 12px (9pt).** No text in the resume may render smaller than 12px, including footnotes, contact info, dates, and skill labels.
925
+
926
+ **๐Ÿ”ด Resume Line-Break Rules:**
927
+ - English: prefer breaking at word boundaries. Long words may be split at syllable boundaries with a hyphen (`-`) - standard typographic practice (e.g., `experi-\nence`).
928
+ - CJK: break between characters, but never separate punctuation from preceding character.
929
+ - Mixed content: respect both rules.
930
+ - Dates/ranges ("Jan 2022 - Present") must stay as one unit.
931
+
932
+ **๐Ÿ”ด Resume Page-Fill:**
933
+ - Content must fill โ‰ฅ85% of page height. If content is sparse, increase spacing (`\medskip` โ†’ `\bigskip`), increase font size slightly, or add sections (Summary, Awards, Projects). Never leave visible blank area > 3cm at page bottom.
934
+
935
+ **Template A customisation quick-reference:**
936
+
937
+ | What to change | How |
938
+ |---------------|-----|
939
+ | Column ratio | `\columnratio{0.62}` โ†’ e.g. `{0.55}` |
940
+ | Accent colour | `\definecolor{accent}{HTML}{3B82F6}` โ†’ any hex |
941
+ | Skill dot count | `\foreach \x in {1,...,5}` โ†’ `{1,...,4}` |
942
+ | Icons | [FontAwesome5 gallery](http://texdoc.net/pkg/fontawesome5) |
943
+ | Font family | Replace `roboto`/`lato` with any LaTeX font package |
944
+ | Page margins | `\geometry{margin=1.25cm,...}` |
945
+
946
+ **Template B customisation:**
947
+
948
+ | What to change | How |
949
+ |---------------|-----|
950
+ | Accent colour | `\definecolor{accent}{HTML}{1F4E79}` โ†’ any hex |
951
+ | Header text | `\fancyhead[L]` content |
952
+ | Section style | `\titleformat{\section}` block |
953
+
954
+ ---
955
+
956
+ ## Reference
957
+
958
+ ### Package Catalogue
959
+
960
+ **Foundational**: `hyperref` ยท `geometry` ยท `listings` ยท `enumitem`
961
+
962
+ **Tabular**: `booktabs` ยท `longtable` ยท `multirow` ยท `array` ยท `colortbl`
963
+
964
+ **Visual & Charting**: `tikz` ยท `pgfplots` ยท `float` ยท `wrapfig` ยท `subfig` / `subcaption`
965
+
966
+ **International & Typography**: `fontspec` (XeLaTeX/LuaLaTeX) ยท `ctex`
967
+
968
+ **Mathematical**: `amsmath` ยท `amssymb` ยท `amsthm` ยท `natbib` ยท `biblatex` ยท `siunitx`
969
+
970
+ **Algorithmic & Domain-Specific**: `algorithm` + `algpseudocode` ยท `chemfig`
971
+
972
+ **Page Design**: `tcolorbox` ยท `fancyhdr` ยท `titlesec` ยท `tocloft` ยท `multicol` ยท `setspace` ยท `microtype` ยท `parskip` ยท `adjustbox` ยท `marginnote`
973
+
974
+ **Code Listings**: `listings` ยท `minted` (depends on Pygments)
975
+
976
+ ### Scripts & Backends
977
+
978
+ | Script | Purpose |
979
+ |--------|---------|
980
+ | `pdf.py convert.latex` | Tectonic wrapper - log sanitisation, error highlighting, PDF metrics |
981
+
982
+ ### Operational Notes
983
+
984
+ **CJK**: `\usepackage{ctex}` - Tectonic pulls font bundles on the fly, zero manual install.
985
+
986
+ **Cold-start**: First compilation downloads packages (1-5 min). Cached builds: 10-30s.
987
+
988
+ **Offline**: Cached packages in `~/.cache/Tectonic/` work offline. New packages require network.
989
+
990
+ **Tectonic vs TeX Live:**
991
+
992
+ | Dimension | Tectonic | Traditional pdflatex |
993
+ |-----------|----------|---------------------|
994
+ | Package acquisition | On-demand, transparent | Manual via `tlmgr` |
995
+ | Multi-pass compilation | Handled by engine | Explicit re-invocations |
996
+ | Disk footprint | Single binary | Full TeX Live โ‰ˆ 4 GB |
997
+
998
+ **Bundled binary note:** The `scripts/tectonic` binary shipped with this skill is a **macOS arm64 (Apple Silicon)** executable. It will NOT work on other platforms. If `pdf.py convert.latex` reports "tectonic command not found", run `python3 pdf.py status` to see platform-specific installation instructions, or install manually:
999
+
1000
+ | Platform | Install Command |
1001
+ |----------|----------------|
1002
+ | macOS (Homebrew) | `brew install tectonic` |
1003
+ | macOS (binary) | `curl -sSL https://drop-sh.fullyjustified.net \| sh` |
1004
+ | Debian / Ubuntu | `apt install tectonic` (if available) or conda/binary |
1005
+ | Arch Linux | `pacman -S tectonic` |
1006
+ | Conda (any OS) | `conda install -c conda-forge tectonic` |
1007
+ | Windows (scoop) | `scoop install tectonic` |
1008
+ | Windows (choco) | `choco install tectonic` |
1009
+
1010
+ After installing, verify: `tectonic --version`. The `_find_tectonic()` function searches: `scripts/tectonic` โ†’ `~/tectonic` โ†’ system PATH.
1011
+
1012
+
1013
+ ---
1014
+
1015
+ > **โš ๏ธ Legacy Note:** Academic covers previously used ReportLab canvas API (cover_recipe_A/B/C/D/L). This approach is **fully deprecated**. All academic covers now use HTML/Playwright Templates 08-11 (see `typesetting/cover.md` and the pipeline at line 58-118 of this file). Do NOT write ReportLab cover code.
1016
+
1017
+ ### โš ๏ธ Post-Cover Generation Checks (Mandatory)
1018
+
1019
+ After generating the cover HTML and before converting to PDF, run `poster_validate.py check-html`; after generating the cover PDF, run `pdf_qa.py`:
1020
+
1021
+ ```bash
1022
+ # Step 1: HTML check
1023
+ python3 "$PDF_SKILL_DIR/scripts/poster_validate.py" check-html cover.html
1024
+ # Step 2: Cover overlap check
1025
+ node "$PDF_SKILL_DIR/scripts/cover_validate.js" cover.html
1026
+ # Step 3: Convert to PDF
1027
+ node "$PDF_SKILL_DIR/scripts/html2poster.js" cover.html --output cover.pdf --width 794px
1028
+ # Step 4: PDF check
1029
+ python3 "$PDF_SKILL_DIR/scripts/pdf_qa.py" final.pdf --skip-cover --formulas
1030
+
1031
+ # MANDATORY: Post-generation pipeline
1032
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" meta.brand final.pdf
1033
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.clean final.pdf -o final_clean.pdf
1034
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" font.check final.pdf
1035
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" toc.check final.pdf
1036
+ ```
1037
+ - `poster_validate.py` checks: font fallback, overflow:hidden, @media screen, background color consistency, etc.
1038
+ - `pdf_qa.py` checks: cover full-bleed, blank pages, CJK punctuation, overflow, margin symmetry, font embedding, metadata, formula overflow
1039
+ - `meta.brand` writes Title/Author/Creator metadata
1040
+ - `pages.clean` removes accidental blank pages
1041
+ - `font.check` scans for missing glyphs (โ–ก tofu)
1042
+ - `toc.check` verifies TOC entries, page numbers, and links
1043
+ - Any ERROR item โ†’ fix and regenerate
1044
+
1045
+ ### Merging Cover with Body
1046
+
1047
+ ```python
1048
+ from pypdf import PdfReader, PdfWriter
1049
+
1050
+ def merge_cover_body(cover_path, body_path, output_path):
1051
+ writer = PdfWriter()
1052
+ for page in PdfReader(cover_path).pages:
1053
+ writer.add_page(page)
1054
+ for page in PdfReader(body_path).pages:
1055
+ writer.add_page(page)
1056
+ with open(output_path, 'wb') as f:
1057
+ writer.write(f)
1058
+ ```