Pandoc install Linux environment

Outline

This article mainly on:

  • pandoc installation and some notes
  • Use pandoc the md file transfer PDF, HTML file directive introduced
  • pandoc Advanced (with the instruction set of the picture)

In this paper the process of installation and use pandoc summary of some of the problems encountered and the use of my personal experience, for reference purposes only.

pandoc Profile

Pandoc is a command-line tool for converting files from a markup language to another markup language. Markup language uses tags to mark sections of a document. Common markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub and Microsoft Word DOCX.
In simple terms, Pandoc allows you to convert files from one markup language to another markup language. Typical examples include converting Markdown files to the presentation, LaTeX, HTML, PDF and other documents

1.pandoc before installation to know things

The first piece:

I personally do not recommend direct use sudo apt-get install pandocthis command to install pandoc
directly pandoc version of this command to install ubuntu system is subject to your current version, which means that if your current Ubuntu system version is lower, then pandoc version of the directive is also installed directly Low version.
Low version pandoc have any major problems head:
1.pandoc compiler directives not compile Beamer
2. not pass instructions to the code block, references, etc. set the background color syntax highlighting, etc.
(although there is a solution, but the one-time installation good high version of pandoc to bring you the silky feel Do not you?)

the second one:

If you want to pandoc turn PDF files, you need to install the support latex environments
Tex release, you can install texlive or MiKtex, after the installation is complete you need to configure the environment, it is recommended to install texlive
If you have enough space, then use: sudo apt-get install texlive-fullinstall the full version of tex kit, what packages have it all, do not toss the installation of other dependent package.
Usually a mounting kit is enough texlive provided herein under linux texlive installation tutorial

The third thing:

pandoc plug (recommended installation)
1.pandoc references supported plugin: pandoc-citeproc
2.pandoc cross referenced plug supported: pandoc-crossref (which is a "for graphs, equations, tables, and the cross-reference number filter")

2.pandoc installation

From the package manager to install Haskell platform cabal pandoc

  1. Haskell platform installation
sudo apt-get install haskell-platform    #安装Haskell的包管理器
  1. Installation pandoc
cabal update              #获取Haskell包信息
cabal install pandoc      #通过cabal安装pandoc
(或cabal install pandoc --force-reinstalls )
  1. Plug-in installation
cabal install pandoc-crossref  
cabal install pandoc-citeproc
  1. Configuration environment variable

Used vim ~/.bashrcin the .bashrcfinal surface to the file ~/.cabalto the route to the following

export PATH=/home/myzh/.cabal/bin:$PATH

If you need to remove the old version to the new version of pandoc update, use the following command:

sudo apt-get autoremove pandoc            #删除pandoc
sudo apt-get install cabal-install
cabal update
cabal install pandoc

Use 3.pandoc instructions

  1. Explain the use pandodc instruction to the code block, and other references provided the background color highlighted
  2. Liezi official website many pandoc instructions

3.1 PDF file generation instruction

Refer to the above "explain the use of pandodc instruction" command for more connections

pandoc --latex-engine=xelatex --template=mytemplate.latex --toc -N --highlight-style zenburn test.md -o test.pdf

-Toc: build directory
-N: add numbers to the title

-latex-engine = xelatex: This is designated specify xelatex compilation engine (support Chinese)

-template = mytemplate.latex: This is compiled using the specified latex template (the template into pandoc the default template folder)

-highlight-style zenburn: to set up a block of code syntax highlighting (recommended zenburn, espresso, breezedark, tango theme)

Some common commands introduced

-f: specifies the input format, such as docx, epub, md, html, etc.
-t: specify the output format, such as docx, epub, md, html, etc.
-o: file output to a file
-verbost: display detailed debugging information
-log: Specify output log information

-List-input-formats: lists the supported input format.
-List-output-formats: lists the supported output formats.
-List-extensions: Markdown list of supported extensions, with a + or later - whether in pandoc enabled by default in the Markdown.
-List-highlight-languages: lists the syntax highlighting language support.
-List-highlight-styles: lists the syntax highlighting styles. .
-v: print version information.
-h: displays syntax help

Mytemplate.latex template used in the above instructions,
click here to view connections latex template description pandoc turn pdf file with the (Linux environment)
understand the problem using the template should be noted.

Generate HTML 3.2

pandoc -s --self-contained -c mystyle.css test.md -o test.html

-s: generating a separate html files
-self-contained: This command will only css embedded into the html file, it will all external html files all compressed into a single file, including images, screen, music and the like.

-c mystyle.css: specify css style file, a simple html file is too monotonous, and only accompanied by corresponding CSS style to make text in a more beautiful way to show it.

Mystyle.css html file which is generated by the write style files, but the style.css should be placed where it? In the current directory, of course, no problem, but every time write markdown, should copy this css file to the current directory, it would mean a lot of trouble? So I find a way to put it in a fixed place, every directly call it.
This leads to the default directory of the pandoc, you can pandoc --versionview the current default directory pandoc command to linux for example, its default directory is /ussr/share/pandoc/date/templates/, simply put the style.css file to this directory, then any when using the directory pandoc, can automatically read into this file, and if needed some special css styles, you can write in the current directory, pandoc will automatically use mystyle.css mystyle.css file in the current directory instead of the default directory .

4.pandoc Advanced (Picture)

1. Image processing arbitrary row

When pandoc to convert files to PDF files md, arranged in advance with the markdown good picture position, changes in control of their own can not happen, they will heap together. I believe this is due to the conversion by LaTeX, but I'm not sure how to solve this problem in Markdown source.
If I use a placeholder image with sample text paragraphs and strategically place the images in the source code, it It will become too large to be placed on my page to its location, so LaTeX layout engine it on the next page. However, I would rather it did not happen, because it means that the image is not where I expected and more difficult references.
If necessary, I may contain one example, but it needs to reproduce a little wide and the source to fill the entire page.
the solution:
use the syntax try pandoc deactivation implicit_figures (can make pictures on the original position, if the image is too big since it will account for one, use their own discretion)

pandoc -f markdown-implicit_figures myfile.md -o myfile.pdf

You can use markdown syntax in markdown modify the image of the document sizes (Note: This method is also from the Internet to find their own pro-test does not work, I do not know what the reason, which it first put a person may use it on the line)

![图片名](image/hua.jpg){width=50%}
2 Align Picture

Want to align the two images on the same line, markdown syntax is as follows:

![图片名](image/aa.jpg)\ ![图片名](image/bb.jpg)

But pay attention to the size of the picture, if the image is too large, the two pictures side by side in pdf turn to be out of bounds

控制图片尺寸可以用html的语法,但该语法只是适合转成html文件才有效。  
通过pandoc使用xelatex引擎编译成pdf不生效, 

<img src="图片连接" width = "400" height = "400" alt="图片名称" align=center>
reference

Jane book pandoc installed
black magic weapon pandoc
via the command line to convert the file Pandoc

Released four original articles · won praise 4 · views 88

Guess you like

Origin blog.csdn.net/weixin_44375591/article/details/104005570