Pandoc : First meet

Pandoc

pandoc首頁,關於Pandoc的引言如下:

If you need to convert files from one markup format into another, pandoc is your swiss-army knife. Pandoc can convert documents in markdown, reStructuredText, textile, HTML, DocBook, LaTeX, MediaWiki markup, TWiki markup, OPML, Emacs Org-Mode, Txt2Tags, Microsoft Word docx, LibreOffice ODT, EPUB, or Haddock markup to

  • HTML formats: XHTML, HTML5, and HTML slide shows using Slidy, reveal.js, Slideous, S5, or DZSlides.
  • Word processor formats: Microsoft Word docx, OpenOffice/LibreOffice ODT, OpenDocument XML
  • Ebooks: EPUB version 2 or 3, FictionBook2
  • Documentation formats: DocBook, TEI Simple, GNU TexInfo, Groff man pages, Haddock markup
  • Page layout formats: InDesign ICML
  • Outline formats: OPML
  • TeX formats: LaTeX, ConTeXt, LaTeX Beamer slides
  • PDF via LaTeX
  • Lightweight markup formats: Markdown (including CommonMark), reStructuredText, AsciiDoc, MediaWiki markup, DokuWiki markup, Emacs Org-Mode, Textile
  • Custom formats: custom writers can be written in lua.

讓我們來練習一下

安裝

  • 這裡下載 pandoc-1.17.2-windows.msi 並安裝 Pandoc。安裝完後,執行檔Pandoc會在路徑中。
  • 若要轉成Pdf檔,到這裡下載並安裝MikTex,安裝後產生TeXnicCenter執行檔,用它來編譯Latex檔案。

使用

Pandoc 是指令式的轉換工具,可在 Dos Prompt 或 PowerShell 下運作。

假設來源檔案為test.md,下面分別轉成:

  • html 格式
  • docx 格式
  • pdf 格式

html 格式

執行下面指令產生html格式的 test.html

pandoc -s test.md --mathjax  -o test.html

docx 格式

執行下面指令產生docx格式的 test.docx

pandoc -s test.md --mathjax -o test.docx

pdf 格式

先用下面指令產生Latex格式的檔案 test.tex。

pandoc -s test.md -o test.tex

假設裡面有中文,必須將 test.tex 略加修改,使得 Latex 能接受中文。

首先,將 test.tex 裡的

\begin{document}

改成

\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{bsmi}
\CJKtilde
\CJKspace

接著將

\end{document}

改成

\end{CJK*}
\end{document}

改完之後的檔案,用TeXnicCenter裡的Latex => Pdf 模式將test.tex編譯成test.pdf。

Share this

Previous
Next Post »

技術提供:Blogger.