// Generate professional PDF documents using Typst with proper Chinese font rendering (Source Han Serif/Sans) and syntax-highlighted code blocks that break across pages naturally. Includes visual validation by converting PDFs to PNG and inspecting with multimodal capabilities. Use when the user requests PDF generation, document creation with Chinese text, Typst compilation, or when working with Chinese fonts and long code examples that need proper page breaks.
| name | pdf-author |
| description | Generate professional PDF documents using Typst with proper Chinese font rendering (Source Han Serif/Sans) and syntax-highlighted code blocks that break across pages naturally. Includes visual validation by converting PDFs to PNG and inspecting with multimodal capabilities. Use when the user requests PDF generation, document creation with Chinese text, Typst compilation, or when working with Chinese fonts and long code examples that need proper page breaks. |
A skill for generating professional PDFs using Typst with proper Chinese font support and code block handling, with built-in validation using multimodal capabilities.
Generate PDF documents with:
When the user requests PDF generation with Chinese content or code examples, use this skill to:
A complete template is available at .claude/skills/pdf-author/template.typ that you can copy and modify.
Always include this header in Typst files for Chinese support and proper code block styling:
#set page(paper: "a4", margin: 2.5cm)
#set text(font: "Source Han Serif SC", lang: "zh")
// Code block styling with breakable frames
#show raw.where(block: true): it => block(
width: 100%,
fill: luma(245),
stroke: 1pt + luma(180),
radius: 4pt,
inset: 10pt,
breakable: true
)[#it]
Instead of inline code blocks, use external file inclusion:
// For any programming language
#raw(read("example.py"), lang: "python", block: true)
#raw(read("script.sh"), lang: "bash", block: true)
#raw(read("main.cpp"), lang: "cpp", block: true)
Create a .typ file with:
Use the Docker-based compilation:
docker run -v $(CURDIR):/workspace -w /workspace typst_cn typst compile <filename>.typ
Or if a Makefile exists with a compile target:
make compile
Convert the PDF to PNG images for visual inspection:
docker run --rm -v /home/wr/tmp/try_typst:/workspace -w /workspace minidocks/poppler pdftoppm <filename>.pdf output-page -png
Important: Use the full absolute path for the volume mount, not $(CURDIR) which doesn't work in bash.
Read the generated PNG files using the Read tool to visually inspect:
Check for common issues:
If issues are found:
= Section Title
Regular paragraph content with 中文支持.
== Subsection with Code
#raw(read("example.py"), lang: "python", block: true)
== Another Subsection
More content here.
Typst handles mixed content automatically when lang: "zh" is set.
数学公式测试:$E = m c^2$
- 项目一 (Item 1)
- 项目二 (Item 2)
- 项目三 (Item 3)
typst_cn: Custom image with Typst and Chinese fonts
docker build -t typst_cn -f .claude/skills/pdf-author/Dockerfile .make build_docker (if Makefile exists)minidocks/poppler: For PDF to PNG conversion
pdftoppm utilityThe Dockerfile in this skills folder creates an Alpine-based image with:
To build:
docker build -t typst_cn -f .claude/skills/pdf-author/Dockerfile .
Or if a Makefile with build_docker target exists:
make build_docker
Cause: Using rect() instead of block(breakable: true)
Solution: Ensure the show rule uses:
#show raw.where(block: true): it => block(
breakable: true,
...
)[#it]
Cause: Missing fonts in Docker image or wrong font name
Solution:
Cause: Show rule not applied or incorrect
Solution: Ensure show rule is defined before any content
Cause: Docker volume mount issue or compilation error
Solution:
# 1. Create document
# (Use Write tool to create .typ file with proper header)
# 2. Create code examples
# (Use Write tool to create external .py, .sh, .cpp files)
# 3. Compile
make compile
# 4. Convert to PNG
docker run --rm -v /home/wr/tmp/try_typst:/workspace -w /workspace minidocks/poppler pdftoppm output.pdf page -png
# 5. Validate
# (Use Read tool on page-01.png, page-02.png, etc.)
# 6. Report findings to user
A successful PDF generation includes: