practice / blog

For personal blogging
1 stars 0 forks source link

pandoc 으로 markdown -> pdf 변환 #37

Open practice opened 7 years ago

practice commented 7 years ago

기술문서를 작성해야 하는데, scrivener나 word, hwp 등으로 작성하기는 싫고 오로지 markdown만 눈에 들어와서 여기까지 왔다.

pandoc이 우선 눈에 들어 왔는데 docker 이미지로 사용하자는 생각에 https://github.com/jagregory/pandoc-docker 에 있는 것을 좀 수정했다.

FROM ubuntu:16.10

MAINTAINER Shawn Won <shawn.won@gmail.com>

## ensure locale is set during build
ENV LANG            C.UTF-8

RUN apt-get update && \
    apt-get install -y --no-install-recommends haskell-platform git

ENV PATH /root/.cabal/bin:/root/.local/bin:/opt/cabal/1.24/bin:/opt/ghc/8.0.1/bin:/opt/happy/1.19.5/bin:/opt/alex/3.1.7/bin:$PATH

# will ease up the update process
# updating this env variable will trigger the automatic build of the Docker image
ENV PANDOC_VERSION "1.18"

# install pandoc
RUN cabal update && cabal install pandoc-${PANDOC_VERSION}

# install latex packages
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common python-software-properties wget
RUN add-apt-repository -y ppa:jonathonf/texlive
RUN  apt-get install -y --no-install-recommends texlive-full fontconfig lmodern
RUN  apt-get install -y --no-install-recommends xzdec

RUN tlmgr init-usertree
RUN tlmgr repository add http://ftp.ktug.org/KTUG/texlive/tlnet ktug
RUN tlmgr pinning add ktug "*"
RUN tlmgr install nanumttf hcr-lvt
RUN tlmgr update --all --self

RUN apt-get install fonts-nanum fonts-nanum-coding fonts-nanum-extra
RUN fc-cache -fv

WORKDIR /source

ENTRYPOINT ["/root/.cabal/bin/pandoc"]

CMD ["--help"]

그리고 한글 처리도 필요하기 때문에 아래 내용도 좀 참고했다. 위 Dockerfile은 아래 내용을 반영한 것이다.

https://github.com/Jaimyoung/data-science-in-korean/blob/master/writing-korean-books-in-r-markdown.md

이제 위 pandoc을 실행하려면 다음과 같이 실행하자.

#!/bin/bash

docker run --rm -v `pwd`:/source pandoc:1.18-ko -f markdown -t latex \
  $1 -o $2 --latex-engine=xelatex --variable CJKmainfont="나눔명조" \
  --include-in-header=/source/pandoc/use-kotex --variable fontsize=12pt \
  -V documentclass=report --toc
\usepackage[cjk,hangul]{kotex}