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 .pdf
1:
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-sections
is 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
, andodt
output. --latex-engine=xelatex
means 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
-V
KEY[=
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
--template
option 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
: 苹方-简 & 蘋方-繁 & 蘋方-港WenQuanYi
orZen 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
xelatex
orlualatex
: take the name of any system font, using thefontspec
package. Note that ifCJKmainfont
is used, thexecjk
package must be available.mainfont
: 衬线字体sansfont
: 无衬线字体monofont
: 等宽字体
- font families for use with
geometry
- option for
geometry
package, 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
github
ormarkdown
- In the pop-up Chrome page, you can check the corresponding
html
file - Press
Command
+P
to print the web page
However, this method is not meticulous enough.
1. https://www.zhihu.com/question/20849824 ↩