Introduction
This is a post to show you how prepare for generating other various formats of documents from a markdown format using PANDOC.
If you need to convert files from one markup format into another, pandoc is your swiss-army knife. Pandoc can convert between almost all kinds of formats.
What is PANDOC?
Pandoc understands a number of useful markdown syntax extensions, including document metadata (title, author, date); footnotes; tables; definition lists; superscript and subscript; strikeout; enhanced ordered lists (start number and numbering style are significant); running example lists; delimited code blocks with syntax highlighting; smart quotes, dashes, and ellipses; markdown inside HTML blocks; and inline LaTeX. If strict markdown compatibility is desired, all of these extensions can be turned off.
LaTeX math (and even macros) can be used in markdown documents. Several different methods of rendering math in HTML are provided, including MathJax and translation to MathML. LaTeX math is converted (as needed by the output format) to unicode, native Word equation objects, MathML, or roff eqn.
Pandoc includes a powerful system for automatic citations and bibliographies. This means that you can write a citation like [see doe99, pp. 33-35; also smith04, ch. 1] and pandoc will convert it into a properly formatted citation using any of hundreds of CSL styles (including footnote styles, numerical styles, and author-date styles), and add a properly formatted bibliography at the end of the document. The bibliographic data may be in BibTeX, BibLaTeX, CSL JSON, or CSL YAML format. Citations work in every output format.
There are many ways to customize pandoc to fit your needs, including a template system and a powerful system for writing filters.
Pandoc includes a Haskell library and a standalone command-line program. The library includes separate modules for each input and output format, so adding a new input or output format just requires adding a new module.
Pandoc is free software, released under the GPL. Copyright 2006–2020 John MacFarlane.
Let’s install Korean fonts to the PANDOC.
apt-get install -y fonts-nanum
What is TinyTex?
We need a latex compiler to produce a PDF file with CJK (Chinese, Japanese, and Korean) fonts. TinyTeX is a custom LaTeX distribution based on TeX Live that is small in size (about 61Mb on macOS/Linux, and 94Mb on Windows when (g)zipped), but functions well in most cases, especially for R users. If you run into the problem of missing LaTeX packages, it should be super clear to you what you need to do (in fact, R users won’t need to do anything). You only install LaTeX packages you actually need.
The binary packages of TinyTeX are released on the monthly basis to the Github repo https://github.com/yihui/tinytex-releases.
For Linux users, TinyTeX will be installed to $HOME/.TinyTeX and symlinks of executables (such as pdflatex) are created under $HOME/bin, which should be on the PATH environment variable:
wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh
This section is only for those who are not R Markdown users — everything is automatic for R Markdown users, and you don’t need to manually search for or install missing LaTeX packages.
Install necessary packages.
Install gpg
tlmgr --repository http://www.preining.info/tlgpg/ install tlgpg
Install some packages
tlmgr install adjustbox amscls amsfonts amsmath babel beamer biblatex bibtex booktabs caption changepage cjk-ko cm collectbox dantelogo dehyph dtk dvipdfmx dvips ec enumitem environ etex etoolbox euenc expex fancyhdr fancyvrb float fontspec forloop framed fvextra geometry glyphlist graphics graphics-cfg graphics-def gsftopk helvetic hyperref hyphen-base ifluatex ifmtarg ifplatform iftex ifxetex inconsolata jknapltx knuth-lib kotex-plain kotex-utf kpathsea l3kernel l3packages latex latex-bin latex-fonts latexconfig latexmk lineno listings lm logreq lua-visual-debug luainputenc lualibs luaotfload luatex luatexko makeindex mathspec mathtools metafont mfware ms nanumtype1 natbib oberdiek pdftex pgf pgfplots plain relsize rsfs scheme-infraonly setspace tcolorbox tetex tex tex-ini-files texlive.infra tikz-cd times tipa titlesec titling tools translator trimspaces ulem unicode-data upquote url wrapfig xcolor xetex xetexconfig xifthen xkeyval xstring xunicode zapfding
tlmgr update --all
If you compile a LaTeX document and run into an error message like this:
! LaTeX Error: File `times.sty' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)
It basically indicates a missing LaTeX package. Do not panic. Open a command window, and use the command tlmgr search --global --file
followed by the filename, e.g.,
tlmgr search --global --file "/times.sty"
psnfss:
texmf-dist/tex/latex/psnfss/times.sty
...
Find the package that contains the file with the exact name in the error log above. In this case, the missing package is psnfss
, and we can install a package via tlmgr install
, e.g.,
tlmgr install psnfss