![Makefile을 사용하여 여러 파일로 출력](https://rvso.com/image/89178/Makefile%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EC%97%AC%EB%9F%AC%20%ED%8C%8C%EC%9D%BC%EB%A1%9C%20%EC%B6%9C%EB%A0%A5.png)
라텍스 템플릿을 통해 마크다운의 파일을 .pdf로 변환하는 데 사용하는 메이크파일이 있습니다. 현재로서는 한 번에 하나의 파일에서만 작동합니다. 그러나 makefile을 실행하고 싶습니다.어느markdown 파일을 활성 디렉터리에 저장하고 단일 make 명령을 사용하여 동일한 이름의 .pdf로 출력합니다. 예를 들어 다음과 같은 정보가 있을 수 있습니다.
Foo.md ---> Foo.pdf
Bar.md ---> Bar.pdf
내 현재 메이크파일은 여기에 있습니다:
TEX = pandoc
MEXT = md
src = template.tex $(wildcard *.$(MEXT))
FLAGS = --latex-engine=xelatex
letter.pdf : $(src)
$(TEX) $(filter-out $<,$^ ) -o $@ --template=$< $(FLAGS)
.PHONY: clean
clean :
rm output.pdf
어떤 조언이라도 감사드립니다...
답변1
이 시도:
TEX = pandoc
MEXT = md
SRC = $(wildcard *.$(MEXT))
PDFS = $(SRC:.md=.pdf)
TMP = template.tex
FLAGS = --latex-engine=xelatex
all: ${PDFS}
%.pdf: %.md ${TMP}
${TEX} $(filter-out $<,$^ ) -o $@ --template=${TMP} $(FLAGS) $<
.PHONY: clean
clean:
rm *.pdf
답변2
나는 이것을 완전히 테스트하지는 않았지만 약간의 수정을 통해 작동해야 한다고 생각합니다. for 루프 사용:
TEX = pandoc
MEXT = md
SRC = $(wildcard *.$(MEXT))
TMP = template.tex
FLAGS = --latex-engine=xelatex
letter.pdf :
$(foreach i, $(SRC), $(TEX) -o $(i).pdf --template=$(TMP) $(FLAGS) $(i);)
.PHONY: clean
clean :
rm -f *.pdf
또한 이 솔루션은 파일 pdf
과 정확히 동일한 이름의 파일을 생성하지 않습니다 md
.
foo.md -> foo.md.pdf
그래도 고치기가 어려워서는 안 됩니다.
답변3
# List files to be made by finding all *.md files and appending .pdf
PDFS := $(patsubst %.md,%.md.pdf,$(wildcard *.md))
# The all rule makes all the PDF files listed
all : $(PDFS)
# This generic rule accepts PDF targets with corresponding Markdown
# source, and makes them using pandoc
%.md.pdf : %.md
pandoc --latex-engine=xelatex $< -o $@
# Remove all PDF outputs
clean :
rm $(PDFS)
# Remove all PDF outputs then build them again
rebuild : clean all