Pandoc安装、使用、快速上手

Pandoc安装、使用、快速上手Markdown Microsoft Word OpenOffice LibreOffice Jupyter notebook HTML EPUB roff man LaTeX 甚至是 PDF

欢迎大家来到IT世界,在知识的湖畔探索吧!

Pandoc安装、使用、快速上手

Pandoc

安装

windows

下载地址:windows下载也可以通过Chocolatey来安装。

choco install pandoc # 其他Pandoc软件安装 choco install rsvg-convert python miktex

欢迎大家来到IT世界,在知识的湖畔探索吧!

macOS

欢迎大家来到IT世界,在知识的湖畔探索吧!brew install pandoc # Pandoc解析器 brew install pandoc-citeproc # 其他Pandoc软件安装 brew install librsvg python homebrew/cask/basictex

Linux

sudo yum install pandoc # 如果想输出PDF,可以安装TeX Live sudo yum install texlive

Ubuntu/Debian

欢迎大家来到IT世界,在知识的湖畔探索吧!sudo apt install pandoc # 如果想输出PDF,可以安装TeX Live sudo apt install texlive

使用

经过上面的安装,我们可以使用了。

验证

[frank@LAPTOP-0OCJTGJR ~]$ pandoc --version
pandoc 1.12.3.1
Compiled with texmath 0.6.6, highlighting-kate 0.5.6.
Syntax highlighting is supported for the following languages:
    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, email, 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, scheme,
    sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, texinfo, verilog, vhdl,
    xml, xorg, xslt, xul, yacc, yaml
Default user data directory: /home/frank/.pandoc
Copyright (C) 2006-2013 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.

小试牛刀

虽然下面的方法不怎么常用,我们先通过命令行的一个简单例子认识一下Pandoc

例子一:markdown 转 html

欢迎大家来到IT世界,在知识的湖畔探索吧![frank@LAPTOP-0OCJTGJR pandoc]$ pandoc # 标题一 标题二 > 摘要

这是按下Ctrl-D,看看会发生什么?

<h1 id="标题一">标题一</h1> <h2 id="标题二">标题二</h2> <blockquote> <p>摘要</p> </blockquote>

例子二:html 转 LaTeX

欢迎大家来到IT世界,在知识的湖畔探索吧![frank@LAPTOP-0OCJTGJR pandoc]$ pandoc -f html -t markdown
<h1 id="标题一">标题一</h1>
<h2 id="标题二">标题二</h2>
<blockquote>
<p>摘要</p>
</blockquote>

这时再次按下Ctrl-D,看看会发生了什么?

标题一 ====== 标题二 ------ > 摘要

我们是不是可以将markdown转换成LaTeX了?你会怎么使用命令组合呢?

文本转换

好了,玩够了,我们正式开始文本转换。

编辑文档

使用任意你喜欢的文本编辑器编辑如下文档并保持为.md文件。这里保持成test1.md

欢迎大家来到IT世界,在知识的湖畔探索吧!--- title: Test ... # Test! This is a test of *pandoc*. - list one - list two

markdown 转 html

[frank@LAPTOP-0OCJTGJR pandoc]$ pandoc test1.md -f markdown -t html -s -o test1.html
[frank@LAPTOP-0OCJTGJR pandoc]$ ll
total 4
-rw-rw-r-- 1 frank frank 629 Feb  4 22:06 test1.html
-rw-rw-r-- 1 frank frank  81 Feb  4 22:05 test1.md

介绍一下参数
-s选项表示创建一个“独立”文件,其中包含页眉和页脚,而不仅仅是片段
-o test1.html 将输出放入文件中test1.html
-f markdown和-t html 表示,from markdown格式 to html格式,Pandoc模式就是从markdown转成html。

markdown 转 LaTeX

欢迎大家来到IT世界,在知识的湖畔探索吧![frank@LAPTOP-0OCJTGJR pandoc]$ pandoc test1.md -f markdown -t latex -s -o test1.tex
[frank@LAPTOP-0OCJTGJR pandoc]$ ll
total 8
-rw-rw-r-- 1 frank frank  629 Feb  4 22:06 test1.html
-rw-rw-r-- 1 frank frank   81 Feb  4 22:05 test1.md
-rw-rw-r-- 1 frank frank 1627 Feb  4 22:17 test1.tex

当然,你也可以直接用下面的命令

[frank@LAPTOP-0OCJTGJR pandoc]$ pandoc test1.md -s -o test2.tex
[frank@LAPTOP-0OCJTGJR pandoc]$ ll
total 12
-rw-rw-r-- 1 frank frank  629 Feb  4 22:06 test1.html
-rw-rw-r-- 1 frank frank   81 Feb  4 22:05 test1.md
-rw-rw-r-- 1 frank frank 1627 Feb  4 22:17 test1.tex
-rw-rw-r-- 1 frank frank 1627 Feb  4 22:18 test2.tex

以为你的文件后缀是.tex,那么Pandoc就会知道你是想生成LaTeX文档,够贴心。

markdown 转 pdf

如果想转成pdf那么我们需要安装texlive这个工具包,在安装一节中我们已经做过这件事儿了。那么我们就直接运行吧。

欢迎大家来到IT世界,在知识的湖畔探索吧![frank@LAPTOP-0OCJTGJR pandoc]$ pandoc test1.md -s -o test1.pdf
[frank@LAPTOP-0OCJTGJR pandoc]$ ll
total 92
-rw-rw-r-- 1 frank frank   629 Feb  4 22:06 test1.html
-rw-rw-r-- 1 frank frank    81 Feb  4 22:05 test1.md
-rw-rw-r-- 1 frank frank 80599 Feb  4 22:20 test1.pdf
-rw-rw-r-- 1 frank frank  1627 Feb  4 22:17 test1.tex
-rw-rw-r-- 1 frank frank  1627 Feb  4 22:18 test2.tex

进阶

更高级的用法可以参考《Pandoc用户指南》

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/124155.html

(0)
上一篇 22分钟前
下一篇 2分钟前

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们YX

mu99908888

在线咨询: 微信交谈

邮件:itzsgw@126.com

工作时间:时刻准备着!

关注微信