with one click
markdown-to-pdf
当需要用 Python 将 Markdown 转为 PDF,并保留表格、代码块、图片路径和基础 CSS 样式时使用。
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
当需要用 Python 将 Markdown 转为 PDF,并保留表格、代码块、图片路径和基础 CSS 样式时使用。
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
将 arXiv、旧会议、旧期刊或自定义 LaTeX 论文工程迁移到目标会议/期刊投稿模板;用于模板 A 到模板 B 的 LaTeX class/style/bibliography/单双栏转换、全匿名投稿检查、页数约束、图表公式排版、PDF 可视化检查、文本/图片/表格/公式守恒、模板标准文件守恒和最终压页。
当需要部署或训练 LLM/VLM 时使用;覆盖 vLLM OpenAI-compatible 服务、多模态输入限制、Qwen3.5 工具调用、thinking/reasoning 控制、CUDA Graph 策略,以及 ms-swift SFT/DPO/GRPO full training、Megatron 长序列训练、messages loss/loss_scale、数据校验、显存排错和训练检查。
当需要在 lab cluster 1 / PJLAB 上使用开发机、rlaunch worker 或 rjob 任务时使用;覆盖交互 SSH、安全边界、路径规范、代理、CPU/GPU 分区、训练/部署、服务访问和排错,并要求使用原始 rlaunch/rjob 命令。
Use when installing, configuring, running, embedding, deploying, or debugging InternScience ResearchHarness as a lightweight tool-using LLM agent runtime, including CLI runs, local frontend UI, OpenAI-compatible API server, Python API, tool selection, workspaces, traces, compaction, tests, and read-only source inspection.
Use when configuring or debugging the context-overlay OpenAI-compatible proxy for deterministic prompt/context injection, prompt patching, rule matching, request routing, rejection rules, skill_dir retrieval, streaming forwarding, and local or tunneled proxy validation.
当需要用 structai.read_pdf 将 PDF 文档解析成本地 Markdown、抽取图片资源,并处理 MinerU 解析缓存或代理重试问题时使用。
| name | markdown-to-pdf |
| description | 当需要用 Python 将 Markdown 转为 PDF,并保留表格、代码块、图片路径和基础 CSS 样式时使用。 |
将 Markdown 文件转为 PDF。脚本会先用 markdown2 转 HTML,再用 WeasyPrint 输出 PDF。
pip install markdown2 weasyprint
WeasyPrint 可能还需要系统图形/字体相关依赖。如果运行时报 Cairo、Pango、fontconfig 等错误,按 WeasyPrint 官方文档补齐系统依赖。
检查:
python -c "import markdown2; from weasyprint import HTML; print('md2pdf deps ok')"
markdown2 和 WeasyPrint 决定;表格、代码块、图片路径、字体或 CSS 问题不确定时,先查看当前安装版本源码。module.__file__ 可定位安装路径。inspect.getsource(...) 可查看关键函数或类。site-packages;优先调整本仓库脚本的参数、CSS 或 wrapper。python - <<'PY'
import inspect
import markdown2
import weasyprint
from weasyprint import HTML
print("markdown2:", getattr(markdown2, "__version__", "unknown"), markdown2.__file__)
print("weasyprint:", getattr(weasyprint, "__version__", "unknown"), weasyprint.__file__)
print(inspect.getsource(markdown2.markdown))
print(inspect.getsource(HTML.write_pdf))
PY
优先使用 bundled script:
scripts/md_to_pdf.py
基本用法:
python scripts/md_to_pdf.py input.md output.pdf
指定输出目录:
python scripts/md_to_pdf.py input.md output_dir
指定图片和相对资源的起始路径。第三个参数会作为 WeasyPrint 的 base_url,用于解析 Markdown 中的相对图片路径、CSS 和本地资源:
python scripts/md_to_pdf.py input.md output.pdf /path/to/base_dir
如果 Markdown 中有相对图片路径,例如 ,把第三个参数设为 Markdown 资源所在目录。不要把第三个参数设成某个图片文件本身。
from scripts.md_to_pdf import md_to_pdf
md_to_pdf("input.md", "output.pdf", base_path=".")
markdown2 的 tables extra。markdown2 的 fenced-code-blocks extra。.pdf。转换后人工打开 PDF,检查中文、图片、表格、代码块换行缩进,以及页面是否有明显溢出、截断或空白。