Pandoc and foreign characters
Use the --pdf-engine=xelatex
option.
By default, Pandoc use the pdflatex
engine when converting markdown file to pdf files. pdflatex
can not handle Unicode characters very smoothly as xelatex
. You should try xelatex
instead. But, merely using xelatex
command is not enough. As is often the case, you need to choose a proper font which contains glyphs for the Unicode characters your want to typeset.
I am a Chinese user, so take Chinese for example. If you have a test.md
which contains the following content:
你好汉字
you can use the following command to compile this markdown file:
pandoc --pdf-engine=xelatex -V CJKmainfont="KaiTi" test.md -o test.pdf
In the above command, --pdf-engine=xelatex
is used to select the LaTeX engine (for the new version of Pandoc, --latex-engine
option is deprecated). -V CJKmainfont="KaiTi"
is used to select the proper font which support Chinese. For other languages, you may use the flag -C mainfont="<FONT_NAME>"
.
How to find a font which support your language
In order to find a font which supports your language, you need to know your language code. Then, if you are on Linux system or on Windows systems with TeX Live installed. You can use the following command to find a valid font for you language:
fc-list :lang=zh #find the font which support Chinese (language code is `zh`)
The output on my Linux system is shown below
If you choose to use, e.g. the font Source Han Serif CN
, then use the following command to compile your markdown file:
pandoc --pdf-engine=xelatex -V CJKmainfont="Source Han Serif CN" test.md -o test.pdf