> For the complete documentation index, see [llms.txt](https://hayashier.gitbook.io/article/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hayashier.gitbook.io/article/others/pandoc-get-started.md).

# Pandoc 導入

## Pandoc 導入

## Install

```
$ brew install pandoc
$ brew cask install mactex
```

zshを使用しているため、.zshrc に以下を追記

```
PATH=/usr/local/texlive/2019/bin/x86_64-darwin/:$PATH
```

変更内容を読み込む

```
$ source ~/.zshrc
```

以下のように実行

```
$ pandoc *.md -o sample.pdf --latex-engine=xelatex -V documentclass=bxjsarticle -V classoption=pandoc
```

### Error

#### pandoc: pdflatex not found. pdflatex is needed for pdf output.

Pandocを実行すると以下のエラー

```
$ pandoc *.md -o sample.pdf
pandoc: pdflatex not found. pdflatex is needed for pdf output.
```

Pandocがpdflatexに依存していて、これがインストールされていないかららしい

```
$ pdflatex -v
zsh: command not found: pdflatex
```

mactex をbrewでインストール

```
$ brew cask install mactex
```

**参考 <https://superuser.com/questions/1038612/where-do-i-get-the-pdflatex-program-for-mac>**

#### command not found: pdflatex

```
$ pdflatex -v
zsh: command not found: pdflatex
```

パスを設定で実行できるようになった

```
$ pdflatex -v                                          
pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019)
kpathsea version 6.3.1
Copyright 2019 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.36; using libpng 1.6.36
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.01
```

#### ! Package inputenc Error: Unicode character は (U+306F)

以下実行で上記エラー文

```
$ pandoc *.md -o sample.pdf
```

指示文どおりに以下のオプションで解消

```
Try running pandoc with --latex-engine=xelatex.
```

#### ! Undefined control sequence.

以下のエラーはエスケープで解消

```
$ pandoc *.md -o sample.pdf --latex-engine=xelatex
! Undefined control sequence.
&lt;argument&gt; \n 

l.935 エラー &amp; - &amp; &#x60;&#x60;-Error message\r\n
```

#### 日本語が表示されない

`-V documentclass=bxjsarticle -V classoption=pandoc` オプションを追加で解消

```
$ pandoc chapter1.md -o sample.pdf --latex-engine=xelatex -V documentclass=bxjsarticle -V classoption=pandoc
```

**参考 <https://qiita.com/sky\\_y/items/15bf7737f4b37da50372>**

#### ! Text line contains an invalid character.

一回削除して同じ文章を打ち直すと解消

### Reference

* Pandoc Manual
  * <https://pandoc.org/MANUAL.html>
