The working environment is:
- OS: Mac OS X EI Capitan
- Sublime Text 3
Take use of Sublime Text 3 (ST3) Package Unicode Character Highlighter to check whether the file contains unicode characters, such as Hanzi.
Read more about ST3:
- SUBLIME TEXT下使用MARKDOWN
- MARKDOWN+SUBLIME TEXT 3+PANDOC+MACTEX
- MAC上使用SUBLIME TEXT3编写LATEX
- 用Sublime Text 3管理文献
If .md doesn’t contains unicode characters
You can directly use ST3 Package Pandoc to convert .md file into .pdf:
Command+Shift+P- Enter
Pandoc - Choose
PDF
Bingo!
If .md contains unicode characters
If the markdown file contains unicode characters, you can use the command as follow to convert the .md into .pdf1:
1 | $pandoc -N -s --smart --latex-engine=xelatex -V CJKmainfont='Hiragino Sans GB' -V mainfont='Monaco' -V geometry:margin=1in XXX.md -o XXX.pdf |
where XXX.md is the name of your markdown file and XXX.pdf is the name of the PDF file.
Follow the Pandoc User’s Guide, you can change the options of pandoc.
pandoc options
-N,--number-sections- Number section headings in LaTeX, ConTeXt, HTML, or EPUB output. By default, sections are not numbered. Sections with class unnumbered will never be numbered, even if
--number-sectionsis specified.
- Number section headings in LaTeX, ConTeXt, HTML, or EPUB output. By default, sections are not numbered. Sections with class unnumbered will never be numbered, even if
-s,--standalone- Produce output with an appropriate header and footer (e.g. a standalone HTML, LaTeX, TEI, or RTF file, not a fragment). This option is set automatically for
pdf,epub,epub3,fb2,docx, andodtoutput. --latex-engine=xelatexmeans that we use XeTeX as the TeX typesetting engine.
- Produce output with an appropriate header and footer (e.g. a standalone HTML, LaTeX, TEI, or RTF file, not a fragment). This option is set automatically for
-VKEY[=VAL],--variable=KEY[:VAL]- Set the template variable KEY to the value VAL when rendering the document in standalone mode. This is generally only useful when the
--templateoption is used to specify a custom template, since pandoc automatically sets the variables used in the default templates. If no VAL is specified, the key will be given the valuetrue. CJKmainfont: Choose a font from List of CJK fonts and make sure the font is available on your OS.PingFang SC&PingFang TC&PingFang HK: 苹方-简 & 蘋方-繁 & 蘋方-港WenQuanYiorZen Hei: 文泉驿正黑Heiti SC&Heiti TC: 黑体-简 & 黑體-繁Hiragino Sans GB: 冬青黑体简体中文
- Set the template variable KEY to the value VAL when rendering the document in standalone mode. This is generally only useful when the
Variables for LaTeX
mainfont,sansfont,monofont,mathfont,CJKmainfont- font families for use with
xelatexorlualatex: take the name of any system font, using thefontspecpackage. Note that ifCJKmainfontis used, thexecjkpackage must be available.mainfont: 衬线字体sansfont: 无衬线字体monofont: 等宽字体
- font families for use with
geometry- option for
geometrypackage, e.g.margin=1in; may be repeated for multiple options
- option for
Comments
In fact, generally you can take use of the Print function of Google Chrome Explorer to easily fulfill the conversion. For example, my explorer is Google Chrome, Version 63.0.3239.84 (Official Build) (64-bit) and in ST3:
Command+Shift+P- Enter
mp - Choose
Markdown Preview: Preview in Browser - Choose
githubormarkdown - In the pop-up Chrome page, you can check the corresponding
htmlfile - Press
Command+Pto print the web page
However, this method is not meticulous enough.
1. https://www.zhihu.com/question/20849824 ↩