CircleCIでLaTeXメモをビルド
普段メモをLaTeXで書いてGitHubで管理しているのだが、コンパイル後のpdfをクラウド上で見られると便利そうなので実装した。
circleciではartifactsを3GBまでアップロードすることができる。
CircleCI CLI
(CircleCIのconfig.yml
をローカル実行できることを最近知った)
.circleci/config.yml
が間違っていないかチェック:
circleci config validate
ローカルでジョブを実行:
circleci local execute
CircleCI上でLaTeXをビルド
以下のような構成のレポジトリで*.tex
とcitation.bib
をもつディレクトリに対してlatexmkを実行して<ディレクトリ名>.pdf
を生成する。
+----.circleci | +----config.yaml +---- build_files.sh +---- artifacts +---- mynote +----mynote.tex +----citation.bib
# .circleci/config.yaml defaults: &defaults docker: - image: paperist/alpine-texlive-ja:2018 version: 2 jobs: build: <<: *defaults steps: - run: name: "Installing additional packages" command: | tlmgr update --self tlmgr install algorithms algorithmicx mhchem ulem apk add --no-cache git - checkout - run: name: Create artifact directory command: mkdir -p /artifacts - run: name: build pdf files command: | cp .latexmkrc ~/.latexmkrc bash build_files.sh cp -r artifacts /artifacts - store_artifacts: path: /artifacts
# build_files.sh #!/bin/bash -eu CURR_DIR=`pwd` SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ARTIFACTS_DIR="artifacts" cd $SCRIPT_DIR mkdir -p $ARTIFACTS_DIR for texpath in `find . -name "*.tex"`; do texdir=`dirname $texpath` # like "./notes/dft" texbasename=`basename $texpath` # like "main.tex" pdfbasename=`echo $texbasename | sed "s/tex$/pdf/"` # like "main.pdf" # ifgore template file if [ $texdir -e "." ]; then continue fi outbasename=`echo $texdir | sed -e "s@^\./@@g" -e "s@/@-@g"` # like notes-dft output="${SCRIPT_DIR}/${ARTIFACTS_DIR}/${outbasename}.pdf" cd $texdir latexmk $texbasename cp $pdfbasename $output cd $SCRIPT_DIR done cd $CURR_DIR
参考リンク
- 日本語対応したplatex, latexmkが入ったdocker image
https://hub.docker.com/r/paperist/alpine-texlive-ja/
algorithm.sty
を入れる