FILE=theta
OUT=build
OUT2=/Users/cerf/Documents/build
DROPBOX=/Users/cerf/Library/CloudStorage/Dropbox

default:
	xelatex -output-directory=$(OUT) $(FILE).tex

all:
	rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	cp $(OUT)/theta.pdf $(DROPBOX)/thetad.pdf
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	#cp $(OUT)/theta.pdf $(DROPBOX)/thetas.pdf
	#cp $(OUT)/theta.pdf $(DROPBOX)/DropsyncFiles/thetas.pdf
	#xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	#cp theta.pdf ~/Dropbox/thetao.pdf
	#cp theta.pdf ~/Dropbox/DropsyncFiles/thetao.pdf

a:all2
all2:
	#rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	#cp $(OUT)/theta.pdf $(DROPBOX)/thetad.pdf
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	sh scalepdf.sh $(OUT)/theta.pdf
	#cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/thetas.pdf
	cp $(OUT)/theta_enlarged.pdf $(OUT2)/thetas.pdf
	#cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/DropsyncFiles/thetas.pdf
	#xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	#xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	#cp theta.pdf ~/Dropbox/thetao.pdf
	#cp theta.pdf ~/Dropbox/DropsyncFiles/thetao.pdf
	afplay /System/Library/Sounds/Tink.aiff


all3:
	rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	#cp $(OUT)/theta.pdf $(DROPBOX)/thetad.pdf
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	sh scalepdf.sh $(OUT)/theta.pdf
	#cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/thetas.pdf
	#cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/DropsyncFiles/thetas.pdf
	#xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	#xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	#cp theta.pdf ~/Dropbox/thetao.pdf
	#cp theta.pdf ~/Dropbox/DropsyncFiles/thetao.pdf


av:all2v
all2v:
	#rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	sh scalepdf.sh $(OUT)/theta.pdf
	#cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/thetasv.pdf
	cp $(OUT)/theta_enlarged.pdf $(OUT2)/thetasv.pdf
	#cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/DropsyncFiles/thetasv.pdf
	#xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	#xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	#cp theta.pdf ~/Dropbox/thetao.pdf
	#cp theta.pdf ~/Dropbox/DropsyncFiles/thetao.pdf
	afplay /System/Library/Sounds/Tink.aiff


draft:
	xelatex -output-directory=$(OUT) "\\def\\drafttrue{}\\input{$(FILE).tex}"

drafta:
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	cp $(OUT)/theta.pdf $(DROPBOX)/thetad.pdf

draftv:
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"


optifull:
	xelatex -output-directory=$(OUT) "\\def\\optifulltrue{}\\input{$(FILE).tex}"

optifulla:
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	cp $(OUT)/theta.pdf $(DROPBOX)/thetao.pdf
	cp $(OUT)/theta.pdf $(DROPBOX)/DropsyncFiles/thetao.pdf

optifulla2:
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	cp $(OUT)/theta.pdf $(DROPBOX)/thetao.pdf

smallfull:
	xelatex -output-directory=$(OUT) "\\def\\smallfulltrue{}\\input{$(FILE).tex}"

smallfulla:
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	#cp $(OUT)/theta.pdf $(DROPBOX)/thetas.pdf
	#cp $(OUT)/theta.pdf $(DROPBOX)/DropsyncFiles/thetas.pdf

smallfulla2:
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	#cp $(OUT)/theta.pdf $(DROPBOX)/thetas.pdf

d:draftall

draftall:
	#rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	sh scalepdf.sh $(OUT)/theta.pdf
	cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/thetad.pdf
	cp $(OUT)/theta_enlarged.pdf $(OUT2)/thetad.pdf
	cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/DropsyncFiles/thetad.pdf
	#afplay /System/Library/Sounds/Pop.aiff
	#afplay /System/Library/Sounds/Blow.aiff
	afplay /System/Library/Sounds/Tink.aiff

dv:draftallv

draftallv:
	#rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\ivindicated{}\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	sh scalepdf.sh $(OUT)/theta.pdf
	cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/thetadv.pdf
	cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/DropsyncFiles/thetadv.pdf
	cp $(OUT)/theta_enlarged.pdf $(OUT2)/thetadv.pdf
	afplay /System/Library/Sounds/Tink.aiff

total:
	rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	cp $(OUT)/theta.pdf $(DROPBOX)/thetad.pdf
	cp $(OUT)/theta.pdf $(DROPBOX)/DropsyncFiles/thetad.pdf
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\smallfulltrue{}\\input{$(FILE).tex}"
	#cp $(OUT)/theta.pdf $(DROPBOX)/thetas.pdf
	#cp $(OUT)/theta.pdf $(DROPBOX)/DropsyncFiles/thetas.pdf
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\optifulltrue{}\\input{$(FILE).tex}"
	cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/thetad.pdf
	cp $(OUT)/theta_enlarged.pdf $(OUT2)/thetad.pdf
	cp $(OUT)/theta_enlarged.pdf $(DROPBOX)/DropsyncFiles/thetad.pdf
	#afplay /System/Library/Sounds/Pop.aiff
	#afplay /System/Library/Sounds/Blow.aiff
	afplay /System/Library/Sounds/Tink.aiff

recorder:
	xelatex -output-directory=$(OUT) -recorder "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"

optimize:  FORCE
	rm -f $(FILE).aux $(FILE).log $(FILE).pdf 
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) -recorder "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	grep png $(OUT)/theta.fls | sed 's/INPUT \.\/pic\///g' | sed 's/INPUT pic\///g' | uniq > lists
	cp lists pic
	rm -f ~/theta/pic/optimized_figures/*png
	chmod +x pic/process2 
	cd pic;./process2 lists
	afplay /System/Library/Sounds/Glass.aiff

FORCE:

full:
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	bibtex $(OUT)/$(FILE)
	makeindex $(OUT)/$(FILE)
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\def\\drafttrue{}\\input{$(FILE).tex}"
	xelatex -output-directory=$(OUT) "\\def\\iallsections{}\\input{$(FILE).tex}"
	cp $(OUT)/theta.pdf $(DROPBOX)
	afplay /System/Library/Sounds/Glass.aiff


clean:
	rm -f $(FILE).out $(FILE).toc $(FILE).aux $(FILE).i?? $(FILE).ind $(FILE).log $(FILE).pdf *conflicted*
	cd $(OUT)
	rm -f $(FILE).out $(FILE).toc $(FILE).aux $(FILE).i?? $(FILE).ind $(FILE).log $(FILE).pdf *conflicted*


alla: FORCE clean full smallfulla optifulla

tout: draftall draftallv all2 all2v


#to clean
#latexmk -xelatex -C monfichier.tex
#latexmk -xelatex -e '$max_repeat=10' monfichier.tex
