pandoc is a document markup language conversion tool, which can realize format conversion between different document markup languages. It is written in Haskell language and realizes interaction with users in the form of command lines. It can support multiple platforms, windows\linux\mac, etc. It is said that it is also used in the publishing industry.
Official website: https://pandoc.org/
Since the haskell-related versions in the yum source of Centos6 are relatively old, all need to be installed from the source code, and the contents to be installed are: ghc, cabal, pandoc, texlive.
ghc is a compiler of Haskell, cabal is a package manager, which can easily install various packages and dependencies automatically, pandoc is installed using cabal, TeX is a document typesetting system, texlive is a kind of unix like This kind of TeX implementation does not have a deep understanding of TeX, so it is so simple to understand first, and PDF generation needs to rely on it.
The official pandoc document mentions:
Note that pandoc requires GHC >= 7.8.
So I downloaded and installed 7.8.2, downloaded and installed the source package
$ wget http://www.haskell.org/ghc/dist/7.8.2/ghc-7.8.2-x86_64-unknown-linux-centos65.tar.bz2
$ tar xf ghc-7.8.2-x86_64-unknown-linux-centos65.tar.bz2
$ cd ghc-7.8.2
$ ./configure
$ make install
$ wget http://www.haskell.org/cabal/release/cabal-install-1.20.0.3/cabal-install-1.20.0.3.tar.gz
$ tar xf cabal-install-1.20.0.3.tar.gz
$ cd cabal-install-1.20.0.3
As the domestic environment is slow to access Haskell's official source network, the address of the source is modified below to be the mirror station of Nanjing University.
Modify the bootstrap.sh file
HACKAGE_URL="https://hackage.haskell.org/package"
for
HACKAGE_URL="http://mirrors.nju.edu.cn/hackage/package"
Revised draft
URL=${HACKAGE_URL}/${PKG}-${VER}/${PKG}-${VER}.tar.gz
for
URL=${HACKAGE_URL}/${PKG}-${VER}.tar.gz
$ ./bootstrap.sh
After the installation is successful, link the cabal command to /usr/bin so that cabal can be found in the PATH
ln -s /root/.cabal/bin/cabal /usr/bin/cabal
Execute cabal update. After the following prompt appears, execute Ctrl+C to interrupt the command, or because the official source network of Haskell is slow, modify the source address in the generated configuration file to the mirror station of Nanjing University
$ cabal update
Config file path source is default config file.
Config file /root/.cabal/config not found.
Writing default configuration to /root/.cabal/config
Downloading the latest package list from hackage.haskell.org
Modify ~/.cabal/config remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive
for
remote-repo: mirrors.nju.edu.cn:http://mirrors.nju.edu.cn/hackage
Execute cable update again, you will be prompted to execute cabal install cabal-install
$ cable update
Downloading the latest package list from mirrors.nju.edu.cn
Skipping download: Local and remote files match.
Note: there is a newversionof cabal-install available.
To upgrade, run: cabal install cabal-install
$ cabal install cabal-install
To be installed
Very simple, execute
$ cabal install pandoc --enable-tests
It may take a little longer, so be patient.
After the installation is complete, add /root/.cabal/bin to the PATH environment variable. Then the pandoc command can be found.
Download the source package and execute the installation script
$ wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
$ tar zxvf install-tl-unx.tar.gz
$ cd install-tl-20170930
$ ./install-tl
It takes a long time, wait patiently.
After the installation is complete, its package directory is /usr/local/texlive/2017/bin/x86_64-linux, which needs to be added to the PATH variable, PATH=$PATH:/usr/local/texlive/2017/bin/ x86_64-linux
.
After installation, you can use the pandoc command to perform the conversion operation. Use pandoc to convert markdown with Chinese to pdf
$ pandoc -N --toc --columns=10--latex-engine=xelatex -V CJKmainfont=STSong -V geometry:margin=1in -o test.pdf test.md
Parameter Description:
N is the number of chapters
V CJKmainfont=STSong If you want to output Chinese correctly, you must specify a suitable Chinese font. This font needs to be installed on Centos.
V geometry:margin=1in specifies the blank size of up, down, left, and right
o Specify the output file name
Pandoc is very powerful and can convert almost all document formats, such as markdown, docx, pdf, html, docbook, epub, etc. In addition, there are many parameters of pandoc, which need to be further studied.
In addition, this article only introduces more suitable installation methods on CentOS operating system. Others such as Ubuntu may have better and more convenient installation methods. Please refer to the official Pandoc document http://pandoc.org/installing.html
Recommended Posts