$npx -y skills add Aperivue/medsci-skills --skill render-pdf-docRender academic Markdown documents (English or Korean) to publication-quality PDF via pandoc + xelatex. Targets non-bibliography artifacts: research proposals, IRB cover letters, briefing handouts, anchor docs (Q&A grids), and reference tables. Auto-infers pipe-table column width
| 1 | # Render-PDF-Doc Skill |
| 2 | |
| 3 | Markdown + frontmatter → publication-quality academic PDF (English or Korean). |
| 4 | |
| 5 | ## Why This Skill Exists |
| 6 | |
| 7 | In real circulation cycles for academic PDFs, two recurring failure patterns appear: |
| 8 | 1. v1 drafts: change-history, version numbers, and PI attribution leak into the attached PDF, confusing the first recipient. |
| 9 | 2. v2 drafts: pandoc pipe-table dash ratios are misjudged, narrowing the first column and forcing label wrapping that hurts readability. |
| 10 | |
| 11 | Manual fixes work but the same pattern recurs across proposals, briefings, IRB covers, exemption applications. This skill focuses on **layout** (CJK fonts + table column widths). Bibliography and CSL are handled by `/manage-refs`. |
| 12 | |
| 13 | ## Boundary (separation from other skills) |
| 14 | |
| 15 | | Task | Skill | |
| 16 | |---|---| |
| 17 | | Manuscript + bibliography → DOCX/PDF | `/manage-refs scripts/render_pandoc.sh` (CSL + .bib) | |
| 18 | | Filling an institutional .docx form | `/fill-protocol` | |
| 19 | | ICMJE COI form | `/fill-icmje-coi` | |
| 20 | | Figure / PPTX | `/make-figures`, `/present-paper` | |
| 21 | | **This skill**: non-bib academic markdown → PDF (proposal, briefing, anchor doc, IRB cover) | `/render-pdf-doc` | |
| 22 | |
| 23 | ## Core Principles |
| 24 | |
| 25 | 1. **Pipe table column widths must be inferred from content.** No equal splitting. Size the first column (label) to the longest label, and distribute the remaining width content-proportionally across the data columns. |
| 26 | 2. **Set the CJK font explicitly** — `mainfont` + `CJKmainfont`. The default fallback is OS-detected. |
| 27 | 3. **For circulation PDFs, remove change history / version numbers / PI attribution** (or split them into a supplementary). Use the frontmatter `redact_internal: true` option. |
| 28 | 4. **No Quarto dependency** — raw pandoc + xelatex. Quarto's `tbl-colwidths` has reported PDF regressions (issues 6089/9200). |
| 29 | |
| 30 | ## Dependencies |
| 31 | |
| 32 | ```bash |
| 33 | # macOS |
| 34 | brew install pandoc |
| 35 | brew install --cask mactex-no-gui # xelatex + xeCJK (~5 GB) |
| 36 | |
| 37 | # Linux |
| 38 | sudo apt-get install pandoc texlive-xetex texlive-lang-cjk fonts-noto-cjk |
| 39 | |
| 40 | # Windows (PowerShell) — run in Git Bash afterwards |
| 41 | winget install --id JohnMacFarlane.Pandoc |
| 42 | winget install --id MiKTeX.MiKTeX # xelatex; installs missing LaTeX packages on demand |
| 43 | # No CJK font download needed: Malgun Gothic ships with Windows 7+ and is the default here. |
| 44 | ``` |
| 45 | |
| 46 | Detection: |
| 47 | ```bash |
| 48 | bash scripts/check_deps.sh |
| 49 | ``` |
| 50 | |
| 51 | **Windows / Git Bash note.** MiKTeX's binary directory |
| 52 | (`%LOCALAPPDATA%\Programs\MiKTeX\miktex\bin\x64`) is often not on the Git Bash `PATH`, |
| 53 | so `xelatex` can read as `[MISS]` even after install. Both `check_deps.sh` and |
| 54 | `render_pdf.sh` now auto-probe that location; if `xelatex` still isn't found, add the |
| 55 | directory to your `PATH` (or run from the *MiKTeX Console → Settings*-configured shell). |
| 56 | The Windows CJK/main font default is **Malgun Gothic** (preinstalled); override per document |
| 57 | via frontmatter, or with `--font` / `--cjk-font`. |
| 58 | |
| 59 | ## Workflow |
| 60 | |
| 61 | ### Step 1 — Author markdown with frontmatter |
| 62 | |
| 63 | ```yaml |
| 64 | --- |
| 65 | title: "Paper 2 Calibration Anchor — Q&A Grid" |
| 66 | author: "<Author Group>" |
| 67 | date: "2026-05-01" |
| 68 | mainfont: "Apple SD Gothic Neo" # macOS default |
| 69 | CJKmainfont: "Apple SD Gothic Neo" |
| 70 | geometry: "margin=0.85in" |
| 71 | fontsize: 11pt |
| 72 | linestretch: 1.25 |
| 73 | colorlinks: true |
| 74 | --- |
| 75 | ``` |
| 76 | |
| 77 | For Linux/CI, use `Noto Sans CJK KR`; on Windows, use `Malgun Gothic`. The render script auto-detects the default per OS. |
| 78 | |
| 79 | ### Step 2 — Infer column widths |
| 80 | |
| 81 | ```bash |
| 82 | python scripts/infer_colwidths.py input.md > input.colwidths.md |
| 83 | ``` |
| 84 | |
| 85 | The script: |
| 86 | 1. Finds every pipe table block. |
| 87 | 2. For each column, computes display width = `max(len(header), max(len(cell)))` (CJK = 2 cells, ASCII = 1). |
| 88 | 3. Generates dash-row separator with proportional dash counts. |
| 89 | 4. Writes a new file with separator rows replaced. |
| 90 | |
| 91 | Override per-table via attribute: `{tbl-colwidths="[20,40,40]"}` after caption — passes through unchanged. |
| 92 | |
| 93 | ### Step 3 — Render |
| 94 | |
| 95 | ```bash |
| 96 | bash scripts/render_pdf.sh -i input.colwidths.md -o output.pdf |
| 97 | ``` |
| 98 | |
| 99 | Or one-shot: |
| 100 | ```bash |
| 101 | bash scripts/render_pdf.sh -i input.md -o output.pdf --infer-colwidths |
| 102 | ``` |
| 103 | |
| 104 | ### Step 3.5 — Scientific-symbol + CJK glyph scan (before render) |
| 105 | |
| 106 | xelatex **silently drops** any character the chosen font d |