diff --git a/.gitattributes b/.gitattributes index 397af035f..16baea2c0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -61,3 +61,7 @@ Dockerfile* text eol=lf # the content-addressed staged filename. lib/diagram-render/dist/*.html text eol=lf lib/diagram-render/dist/*.json text eol=lf + +# Byte-for-byte golden CSS for make-pdf --style plain; CRLF on a Windows +# checkout would break the exact comparison. +make-pdf/test/fixtures/print-css-plain/*.css text eol=lf diff --git a/changelog.d/make-pdf-swiss-style.md b/changelog.d/make-pdf-swiss-style.md new file mode 100644 index 000000000..affc9ae8f --- /dev/null +++ b/changelog.d/make-pdf-swiss-style.md @@ -0,0 +1,4 @@ +--- +bump: minor +--- +**make-pdf has a bold new default look, and `--style plain` keeps the old one.** PDFs now come out in a Swiss-poster layout: section headings in white on black bars, a red document title, small red sub-headings in a narrow left field beside the text, tables, code and diagrams across the full width, and a black cover block with a red bar. The text column holds about 70 characters a line (down from about 83), with 0.75in side margins and 11pt type on a 15pt line. `--style plain` produces exactly the previous look, and `--margins` still overrides either style. The same look applies to `--to html` and `preview`; Word output always uses the plain look. diff --git a/docs/skills.md b/docs/skills.md index 232f3720b..940ddd410 100644 --- a/docs/skills.md +++ b/docs/skills.md @@ -1300,7 +1300,7 @@ macOS may prompt for Keychain approval; Linux uses its supported keyring/fallbac ## `/make-pdf` -Turn any markdown file into a publication-quality PDF: proper margins, page numbers, cover page, clickable TOC, mermaid and excalidraw fences rendered as vector diagrams, `--to html|docx` when you need another format. The compiled `pdf` binary does the typesetting; the printing happens in a browser — your Aside browser first. make-pdf serves the finished HTML from your machine on loopback, opens it in a tab Aside closes when it is done, prints through the browser's own PDF engine (tagged PDF, document outline, header and footer templates all intact), and copies the file out. Nothing leaves the box. When Aside is absent (Linux, Windows, or the app closed) the same pipeline prints through gstack's bundled browser instead, so a PDF comes out on every platform. Full guide to fences and formats: [howto-diagrams-and-formats.md](howto-diagrams-and-formats.md). +Turn any markdown file into a publication-quality PDF: proper margins, page numbers, cover page, clickable TOC, mermaid and excalidraw fences rendered as vector diagrams, `--to html|docx` when you need another format. The default look is a bold Swiss layout (white-on-black section bars, red accents, sub-headings in a narrow left field); `--style plain` keeps the earlier quiet look, and Word output always uses plain. The compiled `pdf` binary does the typesetting; the printing happens in a browser — your Aside browser first. make-pdf serves the finished HTML from your machine on loopback, opens it in a tab Aside closes when it is done, prints through the browser's own PDF engine (tagged PDF, document outline, header and footer templates all intact), and copies the file out. Nothing leaves the box. When Aside is absent (Linux, Windows, or the app closed) the same pipeline prints through gstack's bundled browser instead, so a PDF comes out on every platform. Full guide to fences and formats: [howto-diagrams-and-formats.md](howto-diagrams-and-formats.md). --- diff --git a/make-pdf/SKILL.md b/make-pdf/SKILL.md index f34e512d0..6bf483ed3 100644 --- a/make-pdf/SKILL.md +++ b/make-pdf/SKILL.md @@ -196,9 +196,13 @@ Skills that run plan reviews (`/plan-*-review`, `/codex review`) include the EXI # make-pdf: publication-quality PDFs from markdown -Turn `.md` files into PDFs that look like Faber & Faber essays: 1in margins, -left-aligned body, Helvetica throughout, curly quotes and em dashes, optional -cover page and clickable TOC, diagonal DRAFT watermark when you need it. +Turn `.md` files into finished PDFs. The default look, `swiss`, is a bold Swiss +layout: section headings in white on black bars, a red title, small red +sub-headings in a narrow left field beside the text, a black cover block, and a +text column of about 70 characters a line. `--style plain` gives the quiet look +(1in margins, 12pt body, Faber & Faber essay style). Both are left-aligned, +Helvetica throughout, with curly quotes and em dashes, an optional cover page +and clickable TOC, and a diagonal DRAFT watermark when you need it. Copy-paste from the PDF produces clean words, never "S a i l i n g". On Linux, install `fonts-liberation` for correct rendering — Helvetica and Arial @@ -343,8 +347,13 @@ promoted page is vertically centered. When the heuristic guesses wrong, ## Common flags ``` +Look: + --style swiss|plain swiss (default): black heading bars, red accents, + a left field for sub-headings. plain: the quiet look. + Page layout: - --margins 1in (default) | 72pt | 2.54cm | 25mm + --margins swiss default 0.7in 0.75in 0.85in 0.75in; plain + default 1in | 72pt | 2.54cm | 25mm (sets all four) --page-size letter|a4|legal Structure: @@ -403,6 +412,8 @@ before running. (understand you're giving the markdown file permission to fetch from its image URLs). - Generated PDF too tall/wide → `--page-size a4` or `--margins 0.75in`. +- Someone wants the old, quiet look (or a document full of wide tables reads + better without the left field) → `--style plain`. ## Output contract diff --git a/make-pdf/SKILL.md.tmpl b/make-pdf/SKILL.md.tmpl index 27bed9e7a..f19d0853c 100644 --- a/make-pdf/SKILL.md.tmpl +++ b/make-pdf/SKILL.md.tmpl @@ -3,8 +3,8 @@ name: make-pdf preamble-tier: 1 version: 1.0.0 description: | - Turn any markdown file into a publication-quality PDF. Proper 1in margins, - intelligent page breaks, page numbers, cover pages, running headers, curly + Turn any markdown file into a publication-quality PDF. A bold Swiss layout + by default (--style plain for a quiet one), intelligent page breaks, page numbers, cover pages, running headers, curly quotes and em dashes, clickable TOC, diagonal DRAFT watermark. Not a draft artifact — a finished artifact. Use when asked to "make a PDF", "export to PDF", "turn this markdown into a PDF", or "generate a document". (gstack) @@ -32,9 +32,13 @@ allowed-tools: # make-pdf: publication-quality PDFs from markdown -Turn `.md` files into PDFs that look like Faber & Faber essays: 1in margins, -left-aligned body, Helvetica throughout, curly quotes and em dashes, optional -cover page and clickable TOC, diagonal DRAFT watermark when you need it. +Turn `.md` files into finished PDFs. The default look, `swiss`, is a bold Swiss +layout: section headings in white on black bars, a red title, small red +sub-headings in a narrow left field beside the text, a black cover block, and a +text column of about 70 characters a line. `--style plain` gives the quiet look +(1in margins, 12pt body, Faber & Faber essay style). Both are left-aligned, +Helvetica throughout, with curly quotes and em dashes, an optional cover page +and clickable TOC, and a diagonal DRAFT watermark when you need it. Copy-paste from the PDF produces clean words, never "S a i l i n g". On Linux, install `fonts-liberation` for correct rendering — Helvetica and Arial @@ -179,8 +183,13 @@ promoted page is vertically centered. When the heuristic guesses wrong, ## Common flags ``` +Look: + --style swiss|plain swiss (default): black heading bars, red accents, + a left field for sub-headings. plain: the quiet look. + Page layout: - --margins 1in (default) | 72pt | 2.54cm | 25mm + --margins swiss default 0.7in 0.75in 0.85in 0.75in; plain + default 1in | 72pt | 2.54cm | 25mm (sets all four) --page-size letter|a4|legal Structure: @@ -239,6 +248,8 @@ before running. (understand you're giving the markdown file permission to fetch from its image URLs). - Generated PDF too tall/wide → `--page-size a4` or `--margins 0.75in`. +- Someone wants the old, quiet look (or a document full of wide tables reads + better without the left field) → `--style plain`. ## Output contract diff --git a/make-pdf/src/cli.ts b/make-pdf/src/cli.ts index 956b6600f..9a092ae66 100644 --- a/make-pdf/src/cli.ts +++ b/make-pdf/src/cli.ts @@ -13,7 +13,8 @@ import { COMMANDS } from "./commands"; import { ExitCode, BrowserUnavailableError } from "./types"; -import type { GenerateOptions, PreviewOptions } from "./types"; +import type { GenerateOptions, PreviewOptions, Style } from "./types"; +import { STYLES } from "./style-swiss"; interface ParsedArgs { command: string; @@ -85,8 +86,14 @@ function printUsage(): void { lines.push(" html = single self-contained file, no network refs."); lines.push(" docx = content fidelity, diagrams as PNG."); lines.push(""); + lines.push("Look:"); + lines.push(" --style swiss|plain swiss (default): bold Swiss layout, black heading bars,"); + lines.push(" red accents, a left field for sub-headings."); + lines.push(" plain: the look before swiss, unchanged."); + lines.push(""); lines.push("Page layout:"); - lines.push(" --margins All four margins (default: 1in). in, pt, cm, mm."); + lines.push(" --margins All four margins (default: 0.7in 0.75in 0.85in 0.75in"); + lines.push(" under swiss, 1in under plain). in, pt, cm, mm."); lines.push(" --page-size letter|a4|legal (aliases: --format — page SIZE, not output format)"); lines.push(""); lines.push("Document structure:"); @@ -126,6 +133,15 @@ function printUsage(): void { console.error(lines.join("\n")); } +function styleFromFlags(f: Record, command: string): Style | undefined { + if (f.style === undefined) return undefined; + const value = typeof f.style === "string" ? f.style.toLowerCase() : ""; + if ((STYLES as readonly string[]).includes(value)) return value as Style; + const got = typeof f.style === "string" ? `'${f.style}'` : "no value"; + console.error(`$P ${command}: invalid --style (got ${got}). Expected ${STYLES.join(" or ")}, for example --style plain.`); + process.exit(ExitCode.BadArgs); +} + function generateOptionsFromFlags(parsed: ParsedArgs): GenerateOptions { const p = parsed.positional; if (p.length === 0) { @@ -149,6 +165,7 @@ function generateOptionsFromFlags(parsed: ParsedArgs): GenerateOptions { input: p[0], output: p[1], to: to as GenerateOptions["to"], + style: styleFromFlags(f, "generate"), margins: f.margins as string | undefined, marginTop: f["margin-top"] as string | undefined, marginRight: f["margin-right"] as string | undefined, @@ -192,6 +209,7 @@ function previewOptionsFromFlags(parsed: ParsedArgs): PreviewOptions { }; return { input: p[0], + style: styleFromFlags(f, "preview"), cover: f.cover === true, toc: f.toc === true, watermark: typeof f.watermark === "string" ? f.watermark : undefined, diff --git a/make-pdf/src/commands.ts b/make-pdf/src/commands.ts index 5ccb3aeda..4aeb813f7 100644 --- a/make-pdf/src/commands.ts +++ b/make-pdf/src/commands.ts @@ -20,6 +20,8 @@ export const COMMANDS = new Map [output.pdf] [options]", category: "Primary", flags: [ + // Look + "--style", // Page layout "--margins", "--margin-top", "--margin-right", "--margin-bottom", "--margin-left", "--page-size", "--format", @@ -41,6 +43,7 @@ export const COMMANDS = new Map [options]", category: "Primary", flags: [ + "--style", "--cover", "--toc", "--no-chapter-breaks", "--watermark", "--no-confidential", "--allow-network", "--title", "--author", "--date", diff --git a/make-pdf/src/diagram-prepass.ts b/make-pdf/src/diagram-prepass.ts index b3e2c8e95..3f5d2f9aa 100644 --- a/make-pdf/src/diagram-prepass.ts +++ b/make-pdf/src/diagram-prepass.ts @@ -833,6 +833,18 @@ const PAGE_HEIGHTS_IN: Record = { tabloid: 17, }; +export function contentHeightInches(opts: { + pageSize?: string; + margins?: string; + marginTop?: string; + marginBottom?: string; +}): number { + const pageH = PAGE_HEIGHTS_IN[opts.pageSize ?? "letter"] ?? 11; + const top = dimToInches(opts.marginTop ?? opts.margins, 1); + const bottom = dimToInches(opts.marginBottom ?? opts.margins, 1); + return Math.max(1, pageH - top - bottom); +} + /** * Content box of the rotated (landscape) named page: portrait page HEIGHT * becomes the landscape width; portrait WIDTH becomes the landscape height. diff --git a/make-pdf/src/orchestrator.ts b/make-pdf/src/orchestrator.ts index 4fe440546..474659548 100644 --- a/make-pdf/src/orchestrator.ts +++ b/make-pdf/src/orchestrator.ts @@ -23,7 +23,7 @@ import * as path from "node:path"; import { spawn } from "node:child_process"; import { render } from "./render"; -import { screenCss } from "./print-css"; +import { DEFAULT_STYLE, resolveMargins, screenCss } from "./print-css"; import type { GenerateOptions, PreviewOptions } from "./types"; import { ExitCode } from "./types"; import { pickEngine } from "../../lib/aside-render"; @@ -84,7 +84,9 @@ class ProgressReporter { /** * generate — full pipeline. Returns the output PDF path on success. */ -export async function generate(opts: GenerateOptions): Promise { +export async function generate(requested: GenerateOptions): Promise { + const style = requested.to === "docx" ? "plain" : requested.style ?? DEFAULT_STYLE; + const opts = resolveMargins(requested, style); const progress = new ProgressReporter(opts); const input = path.resolve(opts.input); @@ -118,6 +120,7 @@ export async function generate(opts: GenerateOptions): Promise { watermark: opts.watermark, noChapterBreaks: opts.noChapterBreaks, confidential: opts.confidential, + style, pageSize: opts.pageSize, margins: opts.margins, marginTop: opts.marginTop, @@ -182,7 +185,7 @@ export async function generate(opts: GenerateOptions): Promise { if (to === "html") { const withScreenLayer = finalHtml.replace( "", - `\n`, + `\n`, ); fs.writeFileSync(outputPath, withScreenLayer, "utf8"); const kb = Math.round(fs.statSync(outputPath).size / 1024); @@ -201,7 +204,8 @@ export async function generate(opts: GenerateOptions): Promise { if (opts.headerTemplate) printOnly.push("--header-template"); if (opts.footerTemplate) printOnly.push("--footer-template"); if (opts.pageSize) printOnly.push("--page-size"); - if (opts.margins || opts.marginTop || opts.marginRight || opts.marginBottom || opts.marginLeft) printOnly.push("--margins"); + if (requested.margins || requested.marginTop || requested.marginRight || requested.marginBottom || requested.marginLeft) printOnly.push("--margins"); + if (requested.style) printOnly.push("--style"); if (printOnly.length > 0) { warn(`docx is content-fidelity: ${printOnly.join(", ")} do not apply to Word output`); } @@ -240,7 +244,8 @@ export async function generate(opts: GenerateOptions): Promise { pageNumbers: false, tagged: opts.tagged !== false, outline: opts.outline !== false, - printBackground: !!opts.watermark, + // swiss paints black heading bars and a black cover block: backgrounds must print. + printBackground: !!opts.watermark || style === "swiss", // Named landscape pages only take effect when Chromium honors CSS page // sizes. Flip it ONLY when a promotion exists — minimal behavior change // for every other document. @@ -301,6 +306,7 @@ export async function preview(opts: PreviewOptions): Promise { noChapterBreaks: opts.noChapterBreaks, confidential: opts.confidential, pageNumbers: opts.pageNumbers, + style: opts.style, }); progress.end("Rendering HTML", `${rendered.meta.wordCount} words`); diff --git a/make-pdf/src/print-css.ts b/make-pdf/src/print-css.ts index 02137a11e..19763085a 100644 --- a/make-pdf/src/print-css.ts +++ b/make-pdf/src/print-css.ts @@ -34,6 +34,15 @@ * single source of truth (DRY) and every stack stays in sync. */ +import { + DEFAULT_STYLE, + SWISS_MARGIN_SHORTHAND, + SWISS_MARGINS, + swissRules, + swissScreenCss, + type Style, +} from "./style-swiss"; + // Metric-compatible sans stack: Helvetica (macOS), Liberation Sans (Linux, // ships via fonts-liberation), Arial (Windows). Shared by every text surface. const SANS_STACK = `Helvetica, "Liberation Sans", Arial`; @@ -42,7 +51,12 @@ const CJK_STACK = `"PingFang SC", "Heiti SC", "Noto Sans CJK SC", "Source Han Sa // Color-emoji families: Apple (macOS), Segoe (Windows), Noto (Linux). const EMOJI_FAMILIES = `"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji"`; +export { DEFAULT_STYLE, STYLES, type Style } from "./style-swiss"; + export interface PrintCssOptions { + // Look: "swiss" (default) or "plain" (the look before GSTA-849, byte for byte). + style?: Style; + // Document structure cover?: boolean; toc?: boolean; @@ -58,7 +72,7 @@ export interface PrintCssOptions { // Page size (in CSS `@page size:` terms) pageSize?: "letter" | "a4" | "legal" | "tabloid"; - // Margins (default 1in) + // Margins (default: 1in plain, 0.7in 0.75in 0.85in 0.75in swiss) margins?: string; // Whether to render "N of M" page numbers in the @page @bottom-center rule. @@ -71,8 +85,9 @@ export interface PrintCssOptions { * Produce a CSS block (no