.PHONY: FORCE
.ONESHELL:

-include .env
export

main: pdf

# LaTeX

.PHONY: pdf
pdf:
	cd src
	latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf $(document).tex
	cp main.pdf ..

.PHONY: publish
publish: pdf
	if [ ! -d "published" ]; then mkdir published; fi
	cp $(document).pdf published/$(publish).pdf
	cp $(document).pdf published/$(publish)_$(shell date --iso-8601=seconds).pdf

.PHONY: watch
watch:
	cd src
	latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -pvc $(document).tex

.PHONY: clean
clean:
	latexmk -c

.PHONY: purge
purge:
	latexmk -C

.PHONY: init
init: env biblist config dictionary docs

# example

.PHONY: env
env: FORCE
	cp examples/.env .env

.PHONY: biblist
biblist: FORCE
	cp examples/src/biblist.bib src/biblist.bib

.PHONY: config
config: FORCE
	cp examples/src/config.tex src/config.tex

.PHONY: dictionary
dictionary: FORCE
	cp examples/src/dictionary.txt src/dictionary.txt

.PHONY: docs
docs: FORCE
	cp -rT examples/src/docs/ src/docs

# gitignore

.PHONY: ignore
ignore: acknowledge
	echo /.env >> .gitignore
	echo /src/biblist.bib >> .gitignore
	echo /src/config.tex >> .gitignore
	echo /src/dictionary.txt >> .gitignore
	echo /src/docs/ >> .gitignore

.PHONY: acknowledge
acknowledge:
	sed -i '/^\/.env/d' .gitignore
	sed -i "/^\/src\/biblist.bib/d" .gitignore
	sed -i "/^\/src\/config.tex/d" .gitignore
	sed -i '/^\/src\/dictionary.txt/d' .gitignore
	sed -i '/^\/src\/docs\//d' .gitignore

# spell check

.PHONY: textidote
textidote:
	java -jar ~/bin/textidote.jar --output html --check $(language) --dict dictionary.txt $(document).tex > textidote.html

