修論が終わってからlatexmkの存在に気がついた
そんなわけで修論Done!!
久々にはてブたるものを書いてみる.
latexmkというlatexのコンパイルに便利なツールがあるらしい.
で,ググると微妙に情報が古いサイトが多い?っぽい雰囲気なのでメモ代わりにはてぶ.
修論はずっとTeXで書いてて,やってるときはMakefileを書いてmakeをたたいてたんだけど,びみょーにうまくいかない.
単にうちのMakefileが悪かった,という話ではあるんだけど,TeXのコンパイルって,微妙にめんどい.
.tex から latex で .aux 作って, .aux と hoge.bib から bibtex で .bbl つくって,そんでもってもいっちょlatexで .dvi を作り直して,そんで dvipdf で .pdf.ん?一回latexコマンド足りてない?気のせいか?
そんなこんなで,Makefileのデフォルトのサフィックスルールが邪魔してくれたり,同時にいろいろ生成するものだからタイムスタンプがよくわかんなくなったり……
で,どうにかこうにか動くMakefileができて,そんで修論が終わってから,どうやらlatexmkというコマンドが全部やってくれるらしい,と知った.
latexmkコマンドはうちの環境(Mac Lion)ではなんかしらんが /use/texbin/ に既に入ってた.
なにでlatexをインストールしたかもうすっかり忘れてるけど,texliveだかなんだかで入れた気がする.
だいたいのインストーラさんは入れてくれるんじゃまいかと予想.
で,早速たたいてみるわけなんだけど,とりあえずlatexmkが何を使うかを確認
$ latexmk -commands Commands used by latexmk: To run latex, I use "latex %O %S" To run pdflatex, I use "pdflatex %O %S" To run biber, I use "biber %O %B" To run bibtex, I use "bibtex %O %B" To run makeindex, I use "makeindex %O -o %D %S" To make a ps file from a dvi file, I use "dvips %O -o %D %S" To make a ps file from a dvi file with landscape format, I use "dvips -tlandscape %O -o %D %S" To make a pdf file from a dvi file, I use "dvipdf %O %S %D" To make a pdf file from a ps file, I use "ps2pdf %O %S %D" To view a pdf file, I use "start acroread %O %S" To view a ps file, I use "start gv %O %S" To view a ps file in landscape format, I use "start gv -swap %O %S" To view a dvi file, I use "start xdvi %O %S" To view a dvi file in landscape format, I use "start xdvi -paper usr %O %S" To print a ps file, I use "lpr %O %S" To print a dvi file, I use "NONE $lpr_dvi variable is not configured to allow printing of dvi files" To print a pdf file, I use "lpr %O %S" To find running processes, I use "ps -ww -u takei", and the process number is at position 1 Notes: Command starting with "start" is run detached Command that is just "start" without any other command, is used under MS-Windows to run the command the operating system has associated with the relevant file. Command starting with "NONE" is not used at all
-commands オプションをつけるとlatexmkが何を使うが分かる.
標準だとlatexとbibitexとdvipdfと……とすごくプレーン.
うちはplatexやらpbibtexを使いたいんじゃ!
とオプションを見てると -latex=HOGE でlatexの代わりにHOGEを使うよ!的なことを書かれているのだけど,じゃぁbibtexは?
で,ググってみるとlatexmkはperlスクリプトで書かれているから書き換えろ!とかいうサイトがあって,まじっすか?とか思いつつコピーして書き換えて……をやってたのだけど,どうやら ~/.latexmkrc を書くの一番スマートっぽい.
うちがググった範囲だと微妙にlatexmkrcの書き方が古いサイトが多いっぽいのだけど,すくなくともうちが使ってるLatexmk 4.24ではこんな感じ.
#!/usr/bin/perl $latex = 'platex %O %S'; $bibtex = 'pbibtex %O %B'; $dvipdf = 'dvipdfmx %O %S'; $pdf_mode = 3; # use dvipdf
別にシバン(#!)はいらないっぽいのだけど,vimのsyntaxハイライトもかかるし,どうせperlからそのままdoされてるだけっぽいので,害はないかと.
古いサイトだとコマンドだけしか書いてないことがあるんだけど,今のヴァージョンなら"%O"でオプション,"%S"でソースファイル,"%B"でbibファイルなどが指定できる模様.
特にdvipdfmxはdvipdfと微妙に引数が互換じゃないのがすこしいやらしい.
$pdf_mode はpdfを作る方法.
0(default)だとpdfを作らない,1でpdflatex,2でps経由ps2pdf,3でdvi経由dvipdfになる.
そのほかのオプションは /usr/texbin/latexmk を読めば分かるかと.
うちはどうせopenコマンドでPreview.appを起動しているので使わないけど,viewerあたりにopenとか{kde,gnome}-openやらお好みのビューワーを設定すると吉.
あとlatexmkrcはシステム,ホーム,カレントディレクトリそれぞれを読むので,論文毎に微妙に設定変えたい場合はカレントディレクトリに.latexmkrcを置いておくと吉かも.
そんなわけで .latexmkrc が読まれているか確認
$ latexmk -commands Commands used by latexmk: To run latex, I use "platex %O %S" To run pdflatex, I use "pdflatex %O %S" To run biber, I use "biber %O %B" To run bibtex, I use "pbibtex %O %B" To run makeindex, I use "makeindex %O -o %D %S" To make a ps file from a dvi file, I use "dvips %O -o %D %S" To make a ps file from a dvi file with landscape format, I use "dvips -tlandscape %O -o %D %S" To make a pdf file from a dvi file, I use "dvipdfmx %O %S" To make a pdf file from a ps file, I use "ps2pdf %O %S %D" To view a pdf file, I use "start acroread %O %S" To view a ps file, I use "start gv %O %S" To view a ps file in landscape format, I use "start gv -swap %O %S" To view a dvi file, I use "start xdvi %O %S" To view a dvi file in landscape format, I use "start xdvi -paper usr %O %S" To print a ps file, I use "lpr %O %S" To print a dvi file, I use "NONE $lpr_dvi variable is not configured to allow printing of dvi files" To print a pdf file, I use "lpr %O %S" To find running processes, I use "ps -ww -u takei", and the process number is at position 1 Notes: Command starting with "start" is run detached Command that is just "start" without any other command, is used under MS-Windows to run the command the operating system has associated with the relevant file. Command starting with "NONE" is not used at all
大丈夫っぽいのであとは latexmk hoge.tex で hoge.pdf が作れちゃいます.
latexmk -c で生成物以外のクリーン, -C で生成物を含めたクリーンができます.
便利便利♪
あとは--helpなりコードを読んでくだしあ!
まぁ,なんかomake使った方が楽とか,そんな噂もあるんですけどね…….