SuperAPI AI Directory

z-md-to-pdf

Office & productivity

View repository

Updated 10-16 09:29

About this skill

Markdown → Multi-style PDF

Hand Markdown to Pandoc, then let XeLaTeX handle Chinese fonts, pages, table of contents, headers and footers, and PDF output

Completion criteria

A task is only complete when all of the following conditions are met:

  1. Environment check passes
  2. A non-empty PDF is generated for each style specified by the user
  3. The PDF can be read by pdfinfo , and the page count is reasonable
  4. pdftotext can extract the Chinese body text, indicating there are no blank pages or garbled characters
  5. In batch mode, if any style is missing, the task fails and must be fixed

Style selection

Style parameter Chinese name Use case
academic Plain academic style Paper notes, research reports, course materials
book Wenkai book style Long-form articles, essays, ebooks, personal portfolios
report Modern report style Technical white papers, proposals, business reports
all All styles Generate three PDFs from the same content at once for comparison

When the user does not specify a style, use all

First-time use

Check first:

bash <skill目录>/scripts/setup.sh --check

Automatically install when the check fails:

bash <skill目录>/scripts/setup.sh

The installation script prepares Pandoc, a lightweight TeX environment, and Chinese typesetting components. The build script automatically discovers TinyTeX, with no need to modify terminal configuration

Generate PDF

Specify one style:

bash <skill目录>/scripts/build.sh \
  -i /absolute/path/article.md \
  -o /absolute/path/dist/article \
  --style book \
  --title "文章标题" \
  --author "作者"

Generate all styles at once:

bash <skill目录>/scripts/build.sh \
  -i /absolute/path/article.md \
  -o /absolute/path/dist/article \
  --style all

Output files automatically carry a Chinese style suffix:

  • article-学术朴素风.pdf
  • article-文楷书籍风.pdf
  • article-现代报告风.pdf

The first level-1 heading in the body is used as the default PDF title. Use --no-toc to disable the table of contents

Recompiling the Sun Yuchen project

When the user provides the my-girlfriend-jingtian-latex local directory and asks for it to be turned into a PDF, use:

bash <skill目录>/scripts/build-upstream.sh \
  /absolute/path/my-girlfriend-jingtian-latex \
  /absolute/path/output/我的女友景甜.pdf

This entry point directly uses the upstream repository's main.tex, cover, and fonts, compiles twice in a row, and preserves the original project's 5×8 inch layout

The upstream's current assets/cover.pdf displays as a blank page in common renderers. When the repository includes a finished PDF, the script temporarily extracts the first page of the finished product as a normal cover, without modifying any upstream files throughout the process

The upstream repository currently declares no open-source license. Do not copy its body text, cover, fonts, or main.tex into this Skill, and do not interpret this Skill's MIT license as authorization for upstream files. For exact recompilation, have the user provide the downloaded upstream project directory themselves

Input compatibility

  • Standard Markdown headings, lists, quotes, code blocks, tables, and links
  • Obsidian image syntax ![[image.png]], converted to standard Markdown images before building
  • Mixed Chinese and English typesetting
  • Relative image paths, resolved based on the directory containing the source Markdown

When downloading external images fails, keep the compilation log and give a clear warning. Do not treat a PDF with missing images as a successful delivery

Acceptance

After the build is complete, run:

pdfinfo /absolute/path/output.pdf
pdftotext /absolute/path/output.pdf - | head

When you need to regress all three templates and the upstream project at the same time, run:

bash <skill目录>/scripts/smoke-test.sh \
  --upstream /absolute/path/my-girlfriend-jingtian-latex

Extending templates

The three styles are controlled by the following files respectively:

  • scripts/academic-style.tex
  • scripts/book-style.tex
  • scripts/modern-report-style.tex

When adding a new style, copy the closest style among them, then in build.sh add an explicit style name, output suffix, and font fallback. The new style must be added to smoke-test.sh, ensuring that both standalone generation and batch generation can be verified

FAQ

Symptom Handling
Cannot find xelatex Run setup.sh, the build script will also automatically look for TinyTeX
Chinese font error On macOS enable Songti/Hiragino Sans GB, on Linux install Noto CJK fonts
LXGW WenKai is not installed The book style automatically falls back to Songti or Noto Serif CJK
External image missing Check the network and rerun, or first save the image to the same directory as the Markdown
Only want one PDF Pass --style academic/book/report, avoid using all
Original project compilation fails First confirm that the cover, the two fonts, and main.tex are all in the original repository directory