pdf-generation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PDF Generation

PDF生成

Overview

概述

Generate professional PDFs from markdown files using Pandoc with Eisvogel template styling. Supports English and Russian documents with customizable themes, table of contents, and professional typography including EB Garamond font for Russian text.
借助带有Eisvogel模板样式的Pandoc,从Markdown文件生成专业级PDF。支持英文和俄文文档,可自定义主题、目录,并采用专业排版,其中俄文文本使用EB Garamond字体。

Quick Start

快速开始

Basic commands:
bash
undefined
基础命令:
bash
undefined

Desktop/Print PDF (A4 format)

桌面/打印版PDF(A4格式)

pandoc doc.md -o doc.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:margin=2.5cm -V fontsize=11pt -V documentclass=article
pandoc doc.md -o doc.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:margin=2.5cm -V fontsize=11pt -V documentclass=article

Mobile-friendly PDF (6x9 phone screen optimized)

移动端友好型PDF(适配6x9手机屏幕)

pandoc doc.md -o doc-mobile.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:paperwidth=6in -V geometry:paperheight=9in -V geometry:margin=0.5in -V fontsize=10pt -V linestretch=1.2
pandoc doc.md -o doc-mobile.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:paperwidth=6in -V geometry:paperheight=9in -V geometry:margin=0.5in -V fontsize=10pt -V linestretch=1.2

Russian PDF with EB Garamond

俄文PDF(使用EB Garamond字体)

pandoc doc-ru.md -o doc.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:margin=2.5cm -V fontsize=11pt -V documentclass=article -V mainfont="EB Garamond"
pandoc doc-ru.md -o doc.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:margin=2.5cm -V fontsize=11pt -V documentclass=article -V mainfont="EB Garamond"

Russian Mobile PDF

俄文移动端PDF

pandoc doc-ru.md -o doc-mobile.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:paperwidth=6in -V geometry:paperheight=9in -V geometry:margin=0.5in -V fontsize=10pt -V linestretch=1.2 -V mainfont="EB Garamond"
undefined
pandoc doc-ru.md -o doc-mobile.pdf --pdf-engine=xelatex --toc --toc-depth=2 -V geometry:paperwidth=6in -V geometry:paperheight=9in -V geometry:margin=0.5in -V fontsize=10pt -V linestretch=1.2 -V mainfont="EB Garamond"
undefined

Document Theme Colors

文档主题颜色

  • White Papers - Blue (1e3a8a)
  • Marketing - Green (059669)
  • Research - Purple (7c3aed)
  • Technical - Gray (374151)
  • 白皮书 - 蓝色(1e3a8a)
  • 营销材料 - 绿色(059669)
  • 研究文档 - 紫色(7c3aed)
  • 技术文档 - 灰色(374151)

YAML Frontmatter Example

YAML前置元数据示例

yaml
---
title: "Document Title"
subtitle: "Subtitle"
author: "Author"
date: "2025-11-18"
titlepage: true
titlepage-color: "1e3a8a"
titlepage-text-color: "ffffff"
book: true
---
See references/frontmatter_templates.md for complete templates.
yaml
---
title: "Document Title"
subtitle: "Subtitle"
author: "Author"
date: "2025-11-18"
titlepage: true
titlepage-color: "1e3a8a"
titlepage-text-color: "ffffff"
book: true
---
完整模板请查看references/frontmatter_templates.md。

Markdown Formatting Best Practices

Markdown格式最佳实践

For optimal PDF rendering, ensure:
  1. Blank lines before lists - Required for proper list rendering
  2. Blank lines after headings - Improves spacing
  3. Nested list indentation - Use 3 spaces for sub-items
为获得最佳PDF渲染效果,请确保:
  1. 列表前需空行 - 确保列表正确渲染的必要条件
  2. 标题后需空行 - 提升排版间距
  3. 嵌套列表缩进 - 子项使用3个空格缩进

Common Claude Code Pattern

常见Claude代码格式问题

Lists after colons need blank lines:
markdown
Your data spans 9 years with complete tracking:

- Item 1
- Item 2
Without blank line after colon, renders as inline text.
冒号后的列表需要空行:
markdown
您的数据涵盖9年完整追踪记录:

- 项1
- 项2
若冒号后没有空行,内容会被渲染为行内文本。

Automatic Fix

自动修复

Use preprocessing script:
bash
scripts/fix_markdown.py input.md output.md
Automatically detects and fixes:
  • Lists after colons (Claude Code format)
  • Lists after headings
  • Nested list spacing
使用预处理脚本:
bash
scripts/fix_markdown.py input.md output.md
自动检测并修复以下问题:
  • 冒号后的列表(Claude代码格式)
  • 标题后的列表
  • 嵌套列表间距

Layout Options

布局选项

Desktop/Print Layout (A4)

桌面/打印布局(A4)

  • Paper: 210mm x 297mm (A4)
  • Margins: 2.5cm
  • Font size: 11pt
  • Best for: Printing, reading on large screens, archival
  • 纸张尺寸:210mm x 297mm(A4)
  • 边距:2.5cm
  • 字号:11pt
  • 适用场景:打印、大屏阅读、存档

Mobile Layout (Phone-optimized)

移动端布局(适配手机)

  • Paper: 6in x 9in (phone aspect ratio)
  • Margins: 0.5in (minimal for screen space)
  • Font size: 10pt with 1.2 line spacing
  • Best for: Phone/tablet reading, Telegram/messaging apps
Default for Telegram Bot: Use mobile layout for all PDFs sent via Telegram unless user explicitly requests print/desktop version.
  • 纸张尺寸:6英寸 x 9英寸(手机比例)
  • 边距:0.5英寸(最小化边距以最大化内容区域)
  • 字号:10pt,行间距1.2
  • 适用场景:手机/平板阅读、Telegram/即时通讯应用
Telegram机器人默认设置:通过Telegram发送的所有PDF默认使用移动端布局,除非用户明确要求打印/桌面版。

Generation Workflows

生成工作流

Workflow 1: Simple PDF

工作流1:简单PDF生成

  1. Check context (Telegram = mobile, otherwise desktop)
  2. Check if Russian (use EB Garamond if yes)
  3. Run appropriate pandoc command
  4. Verify output
  1. 检查场景(Telegram则用移动端,否则用桌面端)
  2. 检查是否为俄文(若是则使用EB Garamond字体)
  3. 运行对应的pandoc命令
  4. 验证输出结果

Workflow 2: Professional Title Page

工作流2:专业标题页生成

  1. Add YAML frontmatter with theme color
  2. Include metadata (title, author, date)
  3. Choose layout (mobile vs desktop)
  4. Generate with xelatex
  1. 添加带主题颜色的YAML前置元数据
  2. 包含元数据(标题、作者、日期)
  3. 选择布局(移动端/桌面端)
  4. 使用xelatex生成

Workflow 3: Using Script

工作流3:使用脚本生成

bash
scripts/generate_pdf.py doc.md -t white-paper
scripts/generate_pdf.py doc.md -t marketing --russian
scripts/generate_pdf.py doc.md --mobile  # Mobile layout
bash
scripts/generate_pdf.py doc.md -t white-paper
scripts/generate_pdf.py doc.md -t marketing --russian
scripts/generate_pdf.py doc.md --mobile  # 移动端布局

Resources

资源

  • scripts/generate_pdf.py - Automated generation
  • references/frontmatter_templates.md - YAML templates
  • references/pandoc_reference.md - Command reference
  • scripts/generate_pdf.py - 自动化生成脚本
  • references/frontmatter_templates.md - YAML模板
  • references/pandoc_reference.md - 命令参考

Troubleshooting

故障排除

Install pandoc:
brew install pandoc
Install LaTeX:
brew install --cask mactex
安装pandoc:
brew install pandoc
安装LaTeX:
brew install --cask mactex

Mobile-Friendly PDFs

移动端友好型PDF

For phone and tablet reading, use the mobile layout option:
bash
undefined
针对手机和平板阅读,使用移动端布局选项:
bash
undefined

Using script (recommended)

推荐使用脚本

scripts/generate_pdf.py doc.md --mobile
scripts/generate_pdf.py doc.md --mobile

Direct pandoc command

直接使用pandoc命令

pandoc doc.md -o doc-mobile.pdf
--pdf-engine=xelatex
--toc --toc-depth=2
-V geometry:paperwidth=6in
-V geometry:paperheight=9in
-V geometry:margin=0.5in
-V fontsize=10pt
-V linestretch=1.2
-V colorlinks=true
-V linkcolor=blue
-V urlcolor=blue

**Mobile layout features**:
- 6x9 inch page size (optimal for mobile screens)
- 10pt font (readable on smaller screens)
- 0.5in margins (maximizes content area)
- 1.2 line spacing (improved readability)
- Auto-generated `-mobile.pdf` filename suffix

**When to use mobile layout**:
- Sharing research via Telegram/messaging apps
- Reading on phones or tablets
- Creating portable reference documents
- Quick consumption on the go

**Default context**: Mobile layout is used by default when generating PDFs through the Telegram bot for optimal mobile reading experience.
pandoc doc.md -o doc-mobile.pdf
--pdf-engine=xelatex
--toc --toc-depth=2
-V geometry:paperwidth=6in
-V geometry:paperheight=9in
-V geometry:margin=0.5in
-V fontsize=10pt
-V linestretch=1.2
-V colorlinks=true
-V linkcolor=blue
-V urlcolor=blue

**移动端布局特性**:
- 6x9英寸页面尺寸(适配移动端屏幕)
- 10pt字号(小屏幕可读)
- 0.5英寸边距(最大化内容区域)
- 1.2倍行间距(提升可读性)
- 自动添加`-mobile.pdf`文件名后缀

**何时使用移动端布局**:
- 通过Telegram/即时通讯应用分享研究资料
- 在手机或平板上阅读
- 创建便携参考文档
- 随时随地快速查阅

**默认场景**:通过Telegram机器人生成PDF时,默认使用移动端布局以优化移动端阅读体验。