0
1

More than 3 years have passed since last update.

Makefileで同一ディレクトリ内のLaTeXファイルを一括コンパイル

Posted at

ディレクトリ構成

以下のように、同一ディレクトリ内に複数のLaTeXソースコードがあり、それぞれ単独でコンパイルしたい場合を考えます。

$ tree

.
├── aaa.tex
├── bbb.tex
├── ccc.tex
├── ddd.tex
├── eee.tex
├── fff.tex
└── Makefile

Makefile

all: $(patsubst %.tex,%.pdf,$(wildcard *.tex))

clean:
    $(RM) *.aux *.log *.dvi

%.pdf: %.dvi
    dvipdfmx $<
%.dvi: %.tex
    platex $<

.PHONY: clean

解説

%.dvi: %.tex

platex $<により、%.texから%.dviを生成します。

使用例

$ make aaa.tex

%.pdf: %.dvi

dvipdfmx $<により、%.dviから%.pdfを生成します。

使用例

$ make aaa.dvi

all: $(patsubst %.tex,%.pdf,$(wildcard *.tex))

all: *.pdfと書きたいところですが、初回コンパイル時には*.pdfは存在しないためエラーになるのでこう書きます。

使用例

$ make

本来make allと書くべきですが、一番上のターゲットは引数を省略できます。

clean:

中間ファイル*.aux*.log*.dviを一括削除します。

.PHONY: cleanは、ディレクトリ内にcleanというファイルがあった時に無視することを意味しています。

使用例

$ make clean

注意

目次、相互参照等があり複数回コンパイルが必要な場合は、このMakefileでは正しくコンパイルできません。

複数回コンパイルが必要な場合は、%.dvi: %.texを次のように書き換えます。

%.dvi: %.tex
    for i in `seq 1 2`; do platex $<; done

2回で足りない場合はseq 1 2seq 1 3等にしてみてください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1