MacでTex環境の構築&自動化メモ
Macの環境
MacBook Pro (Retina 13-inch、Early 2015) OS X EI Capitan バージョン10.11.6
Texのダウンロード&インストール
MacTexを下記サイトからダウンロードしてインストールした。
MacTeX - TeX Users Group
Texファイルのコンパイル
TexファイルをAtomでコンパイルしようとしたところ、デフォルトが"Latex"でのコンパイルとなっていたため、 日本語ファイルがコンパイルできなかった。Atomに入れたTex関連のパッケージは下記。
この環境だと、pLatexのコンパイルができず。。。
色々調べて、Atomの上記パッケージのjsを修正すればpLatexの実行ができるというような記事を見つけて色々試したが、断念。
ターミナルからコンパイルすることにする。
ターミナルからのコンパイル方法
ターミナルからpLatexでのコンパイルを実行する方法は下記となる。大まかには、pLatexでのコンパイル→pbibtexのコンパイル→pLatexでのコンパイル(2回、citationをつけるため)、DVIからPDFへの変換、となる。
cd [target directory] platex -output-directory=[target output directory] [target file] pbibtex [target file] platex -output-directory=[target output directory] [target file] platex -output-directory=[target output directory] [target file] dvipdfmx -o [target pdf file] [target dvi file]
例)"testLatex.tex"からPDFを作成する。
cd /Users/~~/sampleLatex platex -output-directory=./out testLatex pbibtex ./out/testLatex platex -output-directory=./out testLatex platex -output-directory=./out testLatex dvipdfmx -o ./testLatex.pdf ./testLatex.dvi
コンパイルの自動化
毎回上記のようなターミナル実行を行うことが面倒だったので、Pythonで自動化するコードを作成した。コードはGitHubにあげているため、そちらを参照。
実行方法
このコードの実行方法は下記となる。
まずディレクトリ構成を下記のように作成し、対象のPythonファイル、Texファイルを配置する。
[any directory]/ ┣ compileTex/ ┃ ┗ compile_pLatex.py : **自動化用のPythonファイル** ┗ sampleLatex/ ┣ out/ ┃ ┗ testLatex.pdf : **このディレクトリに最終アウトプットのPDFが出力される** ┗ testLatex.tex : **PDFを作成したいtexファイル**
その後、下記コマンドを実行することで、PDF作成までのコマンドを全て実行するようにしている。
python compile_platex.py -d [target_directory] -f [target_file] -o [target_output_directory]
オプション引数の意味:
例えば、ディレクトリ構成を上記と同じような形にすると、コマンドは下記となる。
python compile_pLatex.py -d sampleLatex -f testLatex