Pandoc如果你需要将文档从一种格式转换成另一种格式,那么Pandoc就是你的瑞士军刀。Pandoc可以将以下格式的文件相互转换。Markdown、MicrosoftWord、OpenOffice/LibreOffice、Jupyternotebook、HTML、EPUB、roffman、LaTeX,甚至PDF。当然,Pandoc也包含了很多类型文档的转换,这里就不一一列举了。可以参考关于pandoc。安装windows下载地址:windows下载也可以通过Chocolatey安装。chocoinstallpandoc#其他Pandoc软件安装chocoinstallrsvg-convertpythonmiktexmacOSbrewinstallpandoc#Pandocparserbrewinstallpandoc-citeproc#其他Pandoc软件安装brewinstalllibrsvgpythonhomebrew/cask/basictexLinuxsudoyuminstallpandoc#如果要输出PDF,你可以安装TeXLivesudoyuminstalltexliveUbuntu/Debiansudoaptinstallpandoc#如果你想输出PDF,可以安装TeXLivesudoaptinstalltexlive来使用经过上面的安装,我们就可以使用了。验证[frank@LAPTOP-0OCJTGJR~]$pandoc--versionpandoc1.12.3.1用texmath0.6.6编译,highlighting-kate0.5.6。以下语言支持语法高亮:actionscript,ada,apache,asn1,asp,awk,bash,bibtex,boo,c,changelog,clojure,cmake,coffee,coldfusion,commonlisp,cpp,cs,css,curry,d,diff,djangotemplate,doxygen,doxygenlua,dtd,eiffel,电子邮件,erlang,fortran,fsharp,gnuassembler,go,haskell,haxe,html,ini,java,javadoc,javascript,json,jsp,julia,latex,lex,literatecurry,literatehaskell,lua,makefile,mandoc,markdown,matlab,maxima,metafont,mips,modelines,modula2,modula3,monobasic,nasm,noweb,objectivec,objectivecpp,ocaml,octave,pascal,perl,php,pike,postscript,prolog,python,r,relaxngcompact,restructuredtext,rhtml,roff,ruby??,rust,scala,方案、sci、sed、sgml、sql、sqlmysql、sqlpostgresql、tcl、texinfo、verilog、vhdl、xml、xorg、xslt、xul、yacc、yaml默认用户数据目录:/home/frank/.pandoc版权所有(C)2006-2013JohnMacFarlaneWeb:http://johnmacfarlane.net/pandoc这是免费软件;有关复制条件,请参阅来源。现在没有保证,甚至不针对特定用途的适销性或适用性。下面的方法虽然不是很常用,但还是先通过一个简单的命令行例子来认识一下Pandoc。示例1:markdown到html[frank@LAPTOP-0OCJTGJRpandoc]$pandoc#HeadingOne##HeadingTwo>Summary这是Ctrl-D,看看会发生什么?
示例2:HTML传输LaTeX[frank@LAPTOP-0OCJTGJRpandoc]$pandoc-fhtml-tmarkdownSummary
现在再次按下Ctrl-D,看看会发生什么?标题1======标题2------>总结我们可以将markdown转换为LaTeX吗?您将如何使用命令组合?文本转换完成,玩够了,我们正式开始文本转换编辑文档使用任何你喜欢的文本编辑器编辑以下文档并将其保存为.md文件。保留为test1.md---title:Test...#Test!Thisisatestof*pandoc*.-listone-listtwomarkdowntohtml[frank@LAPTOP-0OCJTGJRpandoc]$pandoctest1.md-fmarkdown-thtml-s-otest1.html[frank@LAPTOP-0OCJTGJRpandoc]$lltotal4-rw-rw-r--1frankfrank629Feb422:06test1.html-rw-rw-r--1frankfrank81Feb422:05test1.md引入参数-s选项意味着创建一个带有页眉和页脚的“独立”文件,而不仅仅是片段-otest1.html将输出放入文件test1.html-fmarkdown和-thtml表示,从markdown格式转html格式,Pandoc模式就是从markdown转html。降价到LaTeX[frank@LAPTOP-0OCJTGJRpandoc]$pandoctest1.md-fmarkdown-tlatex-s-otest1.tex[frank@LAPTOP-0OCJTGJRpandoc]$lltotal8-rw-rw-r--1frankfrank629Feb422:06test1.html-rw-rw-r--1frankfrank81Feb422:05test1.md-rw-rw-r--1frankfrank1627Feb422:17test1.tex当然你也可以直接使用如下命令[frank@LAPTOP-0OCJTGJRpandoc]$pandoctest1.md-s-otest2.tex[frank@LAPTOP-0OCJTGJRpandoc]$lltotal12-rw-rw-r--1frankfrank629Feb422:06test1.html-rw-rw-r--1frankfrank81Feb422:05test1.md-rw-rw-r--1frankfrank1627Feb422:17test1.tex-rw-rw-r--1frankfrank1627Feb422:18test2.tex认为你的文件后缀是.tex,那么Pandoc就知道你要生成LaTeX文档,够贴心了。如果要将markdown转为pdf,那么我们需要安装texlive工具包,我们在安装部分已经做好了。所以让我们运行它。[frank@LAPTOP-0OCJTGJRpandoc]$pandoctest1.md-s-otest1.pdf[frank@LAPTOP-0OCJTGJRpandoc]$lltotal92-rw-rw-r--1frankfrank629Feb422:06test1。html-rw-rw-r--1frankfrank81Feb422:05test1.md-rw-rw-r--1frankfrank80599Feb422:20test1.pdf-rw-rw-r--1frankfrank1627Feb422:17test1.tex-rw-rw-r--1frankfrank1627Feb422:18test2.tex进阶更进阶的用法可以参考《Pandoc用户指南》总结