美文网首页
pandoc实现文本格式转换

pandoc实现文本格式转换

作者: rx_rx | 来源:发表于2020-04-18 07:44 被阅读0次

Pandoc 是一款免费的开源文档转换器,通过命令操作实现各种文本格式文件间的转换。它是由加州大学伯克利分校的 John MacFarlane 教授创造。

其支持的文本格式特别广泛,与我相关的主要包括:

  • docx

  • pdf

  • markdown

  • latex

  • epub

  • html

官网Pandoc

下载地址GitHub - jgm/pandoc

tex -> docx

参考自How to Convert from Latex to MS Word with ‘Pandoc’

最简单命令

pandoc main.tex -o main.docx

其中,main.tex 为源码文件名称,参数-o后面连接输出文件名称main.docx

注意,对于main.tex中的数学模式内容,即公式,直接转化为office word可编辑公式

文献引用

当存在引用文献,并使用了.bib文件时,可以添加参数--bibliography来指定.bib文件的路径和名称

pandoc main.tex --bibliography=ref.bib -o main.docx

文档格式

对于不同的期刊,会有不同的文档格式要求。如果期刊给定了doc模板的话,可通过参数--reference-docx进行套用

pandoc main.tex --bibliography=ref.bib --reference-docx=template.doc -o main.docx

需要说明的是,根据模板质量和tex的复杂程度,这个套用过程不一定成功。

docx -> tex

参考自Converting from docx to tex · grattan/grattex Wiki · GitHub

pandoc main.docx --wrap=none -o test.tex

其中,参数--wrap=none可去除段落内部的换行。当为书籍时,可添加参数--chapters,从而指定section的最高级为\chapter,而非\section。

经过上述转换,再对tex文件指定cls,以及相应的公式、图表、文献索引的编辑。

更多类型的文档格式转换见Pandoc - Demos

相关文章

网友评论

      本文标题:pandoc实现文本格式转换

      本文链接:https://www.haomeiwen.com/subject/yiemvhtx.html