Typora, Pandoc and VS Code: fixing CJK fonts when exporting PDF
Quick answer
Each tool fails for a different reason. Pandoc's default pdflatex engine cannot typeset CJK, so switch to xelatex and name a CJK font. The VS Code Markdown PDF extension uses system fonts, so Linux machines without CJK fonts show boxes. Typora usually works, unless a theme sets a font without CJK glyphs. If you would rather not configure anything, export from your browser with MarkPDF.
Pandoc: use xelatex and a CJK font
Pandoc renders PDFs through LaTeX. With the default pdflatex engine, CJK text fails with Unicode character … not set up for use with LaTeX. Use xelatex and specify a CJK font:
pandoc input.md -o output.pdf \
--pdf-engine=xelatex \
-V CJKmainfont="Noto Serif CJK SC"- The font must be installed; list candidates with
fc-list :lang=zh(or:lang=ja,:lang=ko). - On Windows try
"Microsoft YaHei", on macOS"PingFang SC"or"Hiragino Sans". - You need a TeX distribution (TeX Live, MiKTeX…), typically several GB.
VS Code (Markdown PDF extension): install CJK fonts
The popular Markdown PDF extension renders with a bundled Chromium and uses operating-system fonts. Windows and macOS ship CJK fonts; Linux, WSL and Docker images often do not, which produces boxes.
# Debian / Ubuntu
sudo apt install fonts-noto-cjk
# then export againYou can also add a stylesheet via the markdown-pdf.styles setting with font-family: "Noto Sans SC", "Noto Sans JP", sans-serif;.
Try it with a technical document template
Open the tech doc templateTypora: check the theme font
Typora exports with its built-in browser engine and normally handles CJK. If a third-party theme causes boxes or odd fonts, open Preferences → Appearance → Open Theme Folder and add a CJK font to the font-family of body in the theme CSS.
No setup: export from the browser
- Nothing to install. Open the converter and paste.
- Noto Sans fonts for Simplified/Traditional Chinese, Japanese and Korean; the preview and the PDF use the same fonts.
- Files are processed locally and never uploaded.
- Limits: no LaTeX packages or cross-references (and text in the image download is not selectable; the text download keeps it). For theses and precise typesetting, Pandoc + xelatex is still the better tool.
Frequently asked questions
Pandoc with xelatex still shows boxes. Why?
Usually the CJKmainfont name is wrong or the font is not installed. Get the exact family name with fc-list :lang=zh family.
Can I use LaTeX math in MarkPDF?
Inline $ … $ and display $$ … $$ math is rendered with KaTeX. Full LaTeX documents and packages are not supported.
Does MarkPDF work offline?
Yes. After your first visit you can install it as an app and edit and export offline (fonts come from cache or the system).