本章導(dǎo)航:
- 介紹 pandoc 處理 office 文檔的基本語法族操。
5.1 安裝 pandoc
- 下載 Windows 安裝包 Pandoc尺借,并按照提示進(jìn)行安裝顶岸。為了更好的支持 latex 數(shù)學(xué)公式芯丧,您還需要安裝 Tex Live芍阎。
-
pandoc -v
查看版本
更多內(nèi)容可以參考資源:markdown 轉(zhuǎn) docx 及 pdf 轉(zhuǎn) docx|MPE。
5.2 在 vscode 中使用 pandoc 導(dǎo)出 word
如何需要將 markdown 導(dǎo)出為 word缨恒,那么谴咸,您可以設(shè)置如下:
---
title: 構(gòu)建屬于自己的項(xiàng)目
author: xinetzone
date: 2019/10/17
output:
word_document:
highlight: "tango"
---
其中 highlight
用于設(shè)置代碼的高亮的主題。上面的設(shè)置便可以輸出一個十分美觀的 word 版本的文檔骗露。下圖對比代碼高亮與不高亮的區(qū)別:
圖5.1 代碼高亮對比
圖5.1 的左邊是代碼沒有高亮的岭佳,而右邊是代碼高亮的。兩者的優(yōu)劣一眼便可看出萧锉。
這里的高亮主題可以選擇 zenburn
來獲取更好的觀感體驗(yàn):
圖5.2 高亮主題設(shè)置為 `zenburn`
5.2.1 依據(jù)給定的模板輸出 word 文檔
有時珊随,我們想要依據(jù)給定的模板 mystyles.docx
來輸出 word 文檔,您可以這樣設(shè)置:
---
title: 構(gòu)建屬于自己的項(xiàng)目
author: xinetzone
date: 2019/10/17
output:
word_document:
highlight: "tango"
reference_doc: mystyles.docx
---
5.2.2 設(shè)置多文件生成 word 的模板
如果想要在同一個文件夾下的 markdown 文檔以相同的模板生成 word 文檔柿隙,您可以在該目錄下設(shè)置文件 _output.yaml
并輸入模板配置叶洞,比如:
word_document:
highlight: zenburn
這樣,您不必在 markdown 中再次設(shè)置上述參數(shù)禀崖,即可達(dá)到設(shè)置 _output.yaml
中參數(shù)的效果京办。
5.2.3 設(shè)置自動目錄
如果需要設(shè)置自動目錄,可以這樣:
---
title: 構(gòu)建屬于自己的項(xiàng)目
author: xinetzone
date: 2019/10/17
output:
word_document:
highlight: zenburn
reference_doc: mystyles.docx
toc: true
toc_depth: 2
---
5.2.4 自動導(dǎo)出為 word
如果您不想每次都在預(yù)覽 markdown 的時候帆焕,手動生成 word惭婿,您可以設(shè)置 export_on_save
自動生成 word:
---
output: word_document
export_on_save:
pandoc: true
---
5.3 pandoc 轉(zhuǎn)換為 pdf 等文檔
如果存在中文,最好使用命令行的形式生成 pdf 等文檔叶雹。比如:
front-matter 輸入:
---
title: 構(gòu)建屬于自己的項(xiàng)目
author: xinetzone
date: 2019/10/17
output:
beamer_presentation:
incremental: true
theme: "AnnArbor"
colortheme: "dolphin"
fonttheme: "structurebold"
highlight: tango
slide_level: 2
toc: true
---
命令行輸入:
$ pandoc k.md -o k.pdf -V CJKmainfont=KaiTi --pdf-engine=xelatex