SkilVaultSign inStart free

Catalogue / pandoc-pdf-review

pandoc-pdf-review

Older skill: source not recordedSignedPrepares Markdown for clean Pandoc PDF output: renderer differences, the blank-line rules for labels, anchors and metadata, an idempotent spacing repair routine, a reviewed build command, and page-by-page visual checks. Use when the user says "generate a PDF from this markdown", "the bullets render…
---
name: pandoc-pdf-review
description: >-
  Prepares Markdown for clean Pandoc PDF output: renderer differences, the
  blank-line rules for labels, anchors and metadata, an idempotent spacing
  repair routine, a reviewed build command, and page-by-page visual checks.
  Use when the user says "generate a PDF from this markdown", "the bullets
  render inline in the PDF", "fix the Pandoc formatting", "headers show as
  literal ## signs", or reports font, table, or page-break defects. Not for
  HTML site generation alone, and never a substitute for actually looking at
  the produced PDF.
---

Decide how the document is built

Identify first: the installed Pandoc and PDF engine, fonts, template, Markdown extensions, input order, output path, and any MkDocs configuration. Ask before editing source, writing output, running build scripts, opening applications, installing anything, or committing artifacts. Inspect existing build scripts before running them; this skill relies on no unnamed helpers.

Pandoc and Python-Markdown (MkDocs) disagree on several constructs:

| Construct | Python-Markdown (MkDocs) | Pandoc (PDF) | | --- | --- | --- | | Roman-numeral ordered lists | not supported | supported | | Grid tables | extension needed | native | | Raw LaTeX (\pagebreak) | printed as text | native | | Nested list indent | four spaces, strict | more flexible | | Footnote continuation | four-space indent | more flexible |

Pandoc is the more capable reader, so Markdown that builds a fine PDF can still break MkDocs. Verify the actual renderer instead of adopting an untested indentation convention. In both readers, keep blank lines between labels and lists, after HTML anchors before headings, between adjacent paragraph-like metadata fields, and around headings — those rules hold for both, so one fix serves both outputs.

Pick a sourcing strategy deliberately:

  1. One shared source tuned to pass both renderers — simplest to maintain.
  2. Separate HTML and PDF sources, with reviewed synchronization of common content.
  3. Shared source transformed at build time by approved Pandoc filters or MkDocs plugins.

Raw LaTeX page breaks and landscape or font commands belong on a PDF-specific path when HTML cannot interpret them.

Detect and preview spacing repairs

The following pure function handles bold or plain colon labels before root lists, anchor lines before headings, and consecutive bold metadata paragraphs. It avoids fenced code and initial YAML frontmatter; inspect the diff for nested lists, raw HTML blocks, and dialect-specific constructs before applying it.

import re

def spaced_markdown(text):
    lines = text.splitlines(keepends=True)
    out, changes, fence, yaml = [], [], None, False
    for index, line in enumerate(lines):
        stripped = line.strip()
        if index == 0 and stripped == '---':
            yaml = True
            out.append(line)
            continue
        if yaml:
            out.append(line)
            if stripped in ('---', '...'):
                yaml = False
            continue
        marker = re.match(r'^ {0,3}(`{3,}|~{3,})', line)
        if marker:
            token = marker.group(1)
            if fence is None:
                fence = (token[0], len(token))
            elif token[0] == fence[0] and len(token) >= fence[1] and not line[marker.end():].strip():
                fence = None
            out.append(line)
            continue
        if fence is None and out and out[-1].strip():
            previous = out[-1].strip()
            label = previous.endswith(':') or bool(re.fullmatch(r'\*\*[^*]+:\*\*', previous))
            root_list = bool(re.match(r'^(?:[-+*] |\d+[.)] )', line))
            anchor = bool(re.fullmatch(r'<a\s+[^>]+></a>', previous, re.I))
            heading = bool(re.match(r'^#{1,6} ', line))
            metadata = lambda value: bool(re.match(r'^\*\*[^*]+:\*\*\s+\S', value))
            if (label and root_list) or (anchor and heading) or (metadata(previous) and metadata(stripped)):
                if not out[-1].endswith(('\n', '\r')):
                    out[-1] += '\n'
                out.append('\n')
                changes.append(index + 1)
        out.append(line)
    return ''.join(out), changes

Call it on explicitly selected UTF-8 inputs, report original line numbers, and show a unified diff. After approved edits, rerun it to verify idempotence. Do not recursively rewrite the repository or alter example code. Existing historical detection snippets are only hints; inspect actual adjacency rather than treating repeated identical labels as consecutive metadata.

Generate with a reviewed command

For independently installed Pandoc and XeLaTeX, an illustrative approved build is:

pandoc manual.md --from=markdown --to=pdf --pdf-engine=xelatex   --toc --toc-depth=3 --number-sections   --metadata title='Operator Handbook' --metadata author='Documentation Team'   --metadata date='2027-04-12' --output=manual.pdf

Check the installed help and required inputs first. Add --template=reviewed-template.tex only when that local template exists and has been inspected. TOC depth 3 is configurable. Preserve reader extensions and project metadata deliberately. Record exit status, missing-file/LaTeX errors, font warnings, output size, and page count. Do not dismiss a missing glyph until its impact is visually checked.

For shared sources, run the approved MkDocs build and inspect resulting HTML list/header structure as well as the PDF. pdftotext manual.pdf - supports searching a user-reported section; pdfinfo manual.pdf supports page-count checks. Neither proves layout correctness. A historical 100 KB to 10 MB size range and roughly 89-page expectation are project examples, not universal pass criteria; compare this document to its own content and previous output.

Repair the observed defect

| Observation | Inspect and repair | | --- | --- | | Heading is plain text or shows literal hashes | Confirm heading markers and separation from raw HTML; preview both renderers. | | Bullets/numbering appear inline | Separate preceding labels, use consistent markers, verify root/nested indentation. | | Metadata runs together | Separate paragraph fields or use a deliberate structured layout. | | Unicode glyphs disappear | Verify XeLaTeX and chosen font coverage; an available font such as DejaVu Sans may help. Replace cosmetic tree glyphs with approved ASCII or record the checked limitation. | | Tables overflow | Split/restructure, abbreviate clearly, or use reviewed landscape/smaller-font LaTeX with required packages; restore normal font afterward. | | Orphaned headings or poor breaks | Adjust structure, PDF-specific \pagebreak, geometry/pagestyle, or reviewed widow/club penalties. A one-inch margin and penalty 10000 are illustrative settings. |

Inspect every page and the reported sections

Open the generated PDF through the available viewer after confirmation. Review cover, complete TOC, heading hierarchy, bullet/numbered lists, label spacing, separate metadata, table width, code blocks, footnotes, glyphs, page transitions, and missing content. Compare each user-reported section with the original Markdown intent. A successful build may still have broken layout.

Record inputs, tool versions, generation errors/warnings, size/page-count observations, pages inspected, specific defects, repairs, remaining limitations, and next steps. Historical estimates of 2 minutes generating, 10 minutes inspecting, and 5 minutes checking sections are planning examples only. Commit only after separate explicit approval and verified output; do not automatically stage generated PDFs.

Never

  • Edit sources, run builds, open applications, or commit without the user confirming that exact scope.
  • Treat a zero exit status, file size, page count, or text extraction as proof the PDF looks right.
  • Run spacing repairs inside fenced code blocks, YAML frontmatter, or across a repository blindly.
  • Depend on absent project scripts or templates, or apply unreviewed filters and LaTeX snippets.
  • Replace missing Unicode glyphs with invented characters instead of a checked font or documented limitation.