Pandoc installation to realize Markdown to PDF (CentOS6)

Introduction to Pandoc#

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/

Pandoc installation#

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.

ghc installation##

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

cabal installation##

$ 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

pandoc install##

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.

texlive installation##

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.

Pandoc use#

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:

to sum up#

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

Pandoc installation to realize Markdown to PDF (CentOS6)
2019-07-09 CentOS7 installation
centos7_1708 installation
(1) Centos7 installation to build a cluster environment
Centos5 installation guide
Python - centos6 installation
Docker installation (CentOS7 installation)
CentOS7 docker installation
From installation to entry of FastDFS under Centos7
CentOS online installation RabbitMQ3.7
Centos 6.4 python 2.6 upgrade to 2.7
Zabbix 2.2.20 installation details (Centos6.9)
Centos 6.4 python 2.6 upgrade to 2.7
Centos source installation Python3
lamp (centos7) installation lamp environment
CentOS6.5 upgrade kernel to 3.10.28
Centos7 mqtt cluster installation
Graphical installation of CentOS8
Mysql8.0.15 installation configuration (centos7)
Linux notes (1): CentOS-7 installation
Redis3 installation under Centos7
CentOS online installation RabbitMQ3.7
CentOS 5 to CentOS 5.8 YUM source
Docker CentOS installation method
Linux CentOS 7 installation tutorial
Centos7 docker installation details
Introduction to CentOS7 installation process of openjdk, tomcat and mysql