Markdown to PDF using Pandoc
Convert to PDF file
When I use pandoc to convert markdown to pdf on Windows. The command below fails and give me an error message.
pandoc file.md -o output.pdf
Typing the command below and then convert again will work.
updmap
Picture in wrong position
The pictures in output all goes to the end of the file. The command below fixes it.
pandoc file.md -o output.pdf -f markdown-implicit_figures
Ugly code blocks
Using Eisvogel can output beautiful code blocks by the command below after installing the template.
pandoc file.md -o output.pdf --template eisvogel --listings
Chinese
fc-list :lang=zh
Find the available font, then execute the code below with the font you want.
pandoc file.md -o output.pdf --latex-engine=xelatex -V mainfont="Microsoft JhengHei"
::Or
pandoc file.md -o output.pdf --pdf-engine=xelatex -V CJKmainfont="Microsoft JhengHei"
Chinese auto-wrap (instead of slicing)
pandoc file.md -o output.pdf --pdf-engine=xelatex -V CJKmainfont="Microsoft JhengHei" --wrap=preserve
Full command
pandoc file.md -o output.pdf --template eisvogel -f markdown-implicit_figures --listings --pdf-engine=xelatex -V CJKmainfont="Microsoft JhengHei" --wrap=preserve
Download pandoc template Eisvogel.
Further research
Someday I’ll have a test on code highlighting. Pandoc: What are the available syntax highlighters?.
Further Reading
- pdfTeX error (font expansion): auto expansion is only possible with scalable fonts | GitHub
- Error: pdfTeX error (font expansion): auto expansion is only possible with scalable fonts | GitHub
- Pandoc Markdown to PDF image position | Stack Overflow
- Pandoc with Chinese | GitHub
- Pandoc and foreign characters | Stack Overflow