TANKENQI.cn

May 27, 2024

Linux上Pandoc的使用

LinuxOffice4.8 min to read

如果你需要在不同的文件格式之间相互转换,多半听说或使用过文档转换的瑞士军刀——Pandoc。事实上,不仅人类知道 Pandoc,最近很火的人工智能 ChatGPT 也知道「将 Markdown 转换为 docx」,首选方案是使用 Pandoc。

Pandoc 官网:https://www.pandoc.org/

1 安装

wget https://github.com/jgm/pandoc/releases/download/2.14.0.3/pandoc-2.14.0.3-linux-amd64.tar.gz
tar -xvf pandoc-2.14.0.3-linux-amd64.tar.gz
ln -s /root/pandoc-2.14.0.3/bin/pandoc /usr/bin/pandoc
yum install texlive-xetex
pandoc -v 

2 使用

To see the output created by each of the commands below, click on the name of the output file:

pandoc MANUAL.txt -o example1.html
pandoc -s MANUAL.txt -o example2.html
pandoc -s --toc -c pandoc.css -A footer.html MANUAL.txt -o example3.html
pandoc -s MANUAL.txt -o example4.tex
pandoc -s example4.tex -o example5.text
pandoc -s -t rst --toc MANUAL.txt -o example6.text
pandoc -s MANUAL.txt -o example7.rtf
pandoc -t beamer SLIDES -o example8.pdf
pandoc -s -t docbook MANUAL.txt -o example9.db
pandoc -s -t man pandoc.1.md -o example10.1
pandoc -s -t context MANUAL.txt -o example11.tex
pandoc -s -r html http://www.gnu.org/software/make/ -o example12.text
pandoc MANUAL.txt --pdf-engine=xelatex -o example13.pdf
pandoc -N --variable "geometry=margin=1.2in" --variable mainfont="Palatino" --variable sansfont="Helvetica" --variable monofont="Menlo" --variable fontsize=12pt --variable version=2.0 MANUAL.txt --include-in-header fancyheaders.tex --pdf-engine=lualatex --toc -o example14.pdf
pandoc example15.md -o example15.ipynb
pandoc -s --mathml -i -t dzslides SLIDES -o example16a.htmlpandoc -s --webtex -i -t slidy SLIDES -o example16b.htmlpandoc -s --mathjax -i -t revealjs SLIDES -o example16d.html
pandoc math.text -s -o mathDefault.htmlpandoc math.text -s --mathml  -o mathMathML.htmlpandoc math.text -s --webtex  -o mathWebTeX.htmlpandoc math.text -s --mathjax -o mathMathJax.htmlpandoc math.text -s --katex   -o mathKaTeX.html
pandoc code.text -s --highlight-style pygments -o example18a.htmlpandoc code.text -s --highlight-style kate -o example18b.htmlpandoc code.text -s --highlight-style monochrome -o example18c.htmlpandoc code.text -s --highlight-style espresso -o example18d.htmlpandoc code.text -s --highlight-style haddock -o example18e.htmlpandoc code.text -s --highlight-style tango -o example18f.htmlpandoc code.text -s --highlight-style zenburn -o example18g.html
pandoc MANUAL.txt -s -o example19.texi
pandoc MANUAL.txt -s -t opendocument -o example20.xml
pandoc MANUAL.txt -o example21.odt
pandoc -s -t mediawiki --toc MANUAL.txt -o example22.wiki
pandoc MANUAL.txt -o MANUAL.epub
pandoc -s --bibliography biblio.bib --citeproc CITATIONS -o example24a.htmlpandoc -s --bibliography biblio.json --citeproc --csl chicago-fullnote-bibliography.csl CITATIONS -o example24b.htmlpandoc -s --bibliography biblio.yaml --citeproc --csl ieee.csl CITATIONS -t man -o example24c.1
pandoc -s MANUAL.txt -t textile -o example25.textile
pandoc -s example25.textile -f textile -t html -o example26.html
pandoc -s MANUAL.txt -o example27.org
pandoc -s MANUAL.txt -t asciidoc -o example28.txt
pandoc -s MANUAL.txt -o example29.docx
pandoc -s math.tex -o example30.docx
pandoc -f docbook -t markdown -s howto.xml -o example31.text
pandoc -f mediawiki -t html5 -s haskell.wiki -o example32.html
pandoc -t chunkedhtml --split-level=2 --toc --toc-depth=2 --number-sections -o example33 MANUAL.txt
pandoc --reference-doc twocolumns.docx -o UsersGuide.docx MANUAL.txt
pandoc -s example30.docx -t markdown -o example35.md
pandoc MANUAL.epub -t plain -o example36.text
pandoc fishwatch.yaml -t rst --template fishtable.rst -o fish.rst # see also the partial species.rst
pandoc biblio.bib -t csljson -o biblio2.json
pandoc biblio.bib --citeproc --csl ieee.csl -s -o biblio.html

3 中文乱码问题

中文乱码问题,大多与字体有关,解决方案详见文章 系统字体安装:https://tankenqi.cn/posts/2de821dc/